ci: restore the platform's orchestrator deploy workflow (#2)
All checks were successful
Integration Test / Platform Conformance (pull_request) Successful in 8s
SonarQube Analysis / Build, Test & Analyse (pull_request) Successful in 2m27s
Integration Test / Unit Tests + Container Smoke (workflow_dispatch) All checks passed
Integration Test / Unit Tests + Container Smoke (pull_request) Successful in 2m33s
All checks were successful
Integration Test / Platform Conformance (pull_request) Successful in 8s
SonarQube Analysis / Build, Test & Analyse (pull_request) Successful in 2m27s
Integration Test / Unit Tests + Container Smoke (workflow_dispatch) All checks passed
Integration Test / Unit Tests + Container Smoke (pull_request) Successful in 2m33s
This commit was merged in pull request #2.
This commit is contained in:
@@ -2,7 +2,13 @@ name: Build and Push to ACR
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "dev" ]
|
||||
branches: [ dev ]
|
||||
# A commit that only touches .platform/ is a release decision, not new code --
|
||||
# most often a rollback to an image that already exists. Rebuilding it would
|
||||
# either put different bits under an existing tag or trip the immutability check
|
||||
# below, so the build stays out of the way and deploy.yml picks the change up.
|
||||
paths-ignore:
|
||||
- '.platform/**'
|
||||
workflow_dispatch: {}
|
||||
|
||||
concurrency:
|
||||
@@ -16,6 +22,11 @@ jobs:
|
||||
build:
|
||||
name: Build and Push
|
||||
runs-on: ubuntu-latest
|
||||
if: >-
|
||||
github.ref != 'refs/heads/main' && (
|
||||
github.event_name == 'workflow_dispatch' ||
|
||||
(github.event_name == 'push' && github.event.before != '0000000000000000000000000000000000000000')
|
||||
)
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
@@ -23,52 +34,16 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
- name: Install Maven
|
||||
run: |
|
||||
if ! command -v mvn &>/dev/null; then
|
||||
apt-get update -qq && apt-get install -y maven
|
||||
fi
|
||||
mvn --version
|
||||
- name: Build with Maven
|
||||
run: mvn clean package -DskipTests -Dcheckstyle.skip=true -B
|
||||
- name: Run tests
|
||||
# Exclude PostgresIntegrationTests — it hardcodes spring.docker.compose.skip.in-tests=false
|
||||
# in its @SpringBootTest annotation, making it impossible to override via -D flags.
|
||||
# docker-compose is not available in the act runner container.
|
||||
# -Dtest=!ClassName is the correct Surefire 2.19+ CLI exclusion syntax.
|
||||
# -Dcheckstyle.skip=true — platform-scaffolded files (score.yaml, k6/) contain
|
||||
# internal http:// URLs that trip the NoHttp checkstyle plugin.
|
||||
run: mvn test -B '-Dtest=!PostgresIntegrationTests' -Dcheckstyle.skip=true
|
||||
|
||||
|
||||
- name: Security Scan - Trivy
|
||||
continue-on-error: true
|
||||
run: |
|
||||
# Download release tarball directly — avoids install.sh which calls
|
||||
# api.github.com/releases/tags/... and fails in network-restricted runners.
|
||||
TRIVY_VERSION="0.57.1"
|
||||
TRIVY_BIN="/tmp/trivy-bin/trivy"
|
||||
if ! command -v trivy &>/dev/null; then
|
||||
mkdir -p /tmp/trivy-bin
|
||||
curl -sfLo /tmp/trivy.tar.gz "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
|
||||
tar -xzf /tmp/trivy.tar.gz -C /tmp/trivy-bin trivy
|
||||
chmod +x "${TRIVY_BIN}"
|
||||
else
|
||||
TRIVY_BIN="$(command -v trivy)"
|
||||
fi
|
||||
# Filesystem scan — exit-code 0 so findings are reported but never block the build
|
||||
"${TRIVY_BIN}" fs --severity HIGH,CRITICAL --exit-code 0 --format table --skip-db-update --offline-scan . || "${TRIVY_BIN}" fs --severity HIGH,CRITICAL --exit-code 0 --format table .
|
||||
|
||||
- name: Install Azure CLI
|
||||
run: |
|
||||
if ! command -v az &>/dev/null; then
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||
fi
|
||||
command -v az &>/dev/null || curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||
|
||||
- name: Install Docker CLI
|
||||
run: |
|
||||
command -v docker &>/dev/null || (apt-get update -qq && apt-get install -y docker.io)
|
||||
docker --version
|
||||
|
||||
- name: Azure login (OIDC)
|
||||
run: |
|
||||
az login \
|
||||
@@ -76,13 +51,78 @@ jobs:
|
||||
--username "$AZURE_CLIENT_ID" \
|
||||
--tenant "$AZURE_TENANT_ID" \
|
||||
--federated-token "$(cat $AZURE_FEDERATED_TOKEN_FILE)"
|
||||
- name: Build and push via ACR Tasks
|
||||
echo "✓ Azure login successful"
|
||||
|
||||
- name: Get ACR details
|
||||
run: |
|
||||
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
||||
az acr build \
|
||||
--registry bstagecjotdevacr \
|
||||
--image place-a-1:$SHORT_SHA \
|
||||
--image place-a-1:latest \
|
||||
--file Dockerfile \
|
||||
.
|
||||
echo "✓ Pushed: bstagecjotdevacr.azurecr.io/place-a-1:$SHORT_SHA"
|
||||
ACR_NAME=$(az acr list --query "[0].name" -o tsv)
|
||||
ACR_NAME="${ACR_NAME:-bstagecjotdevacr}"
|
||||
echo "ACR_NAME=$ACR_NAME" >> $GITHUB_ENV
|
||||
echo "ACR_LOGIN_SERVER=${ACR_NAME}.azurecr.io" >> $GITHUB_ENV
|
||||
echo "✓ Using ACR: ${ACR_NAME}.azurecr.io"
|
||||
|
||||
- name: ACR Login
|
||||
run: |
|
||||
ACR_TOKEN=$(az acr login --name "$ACR_NAME" --expose-token --output tsv --query accessToken)
|
||||
docker login "$ACR_LOGIN_SERVER" \
|
||||
--username 00000000-0000-0000-0000-000000000000 \
|
||||
--password "$ACR_TOKEN"
|
||||
echo "✓ ACR login successful"
|
||||
|
||||
- name: Read and verify the release tag
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# .platform/release.yaml, not the commit, decides what this build produces.
|
||||
# deploy.yml reads the same file, so the tag that is built and the tag that
|
||||
# is deployed cannot drift apart.
|
||||
RELEASE_FILE=.platform/release.yaml
|
||||
if [ ! -f "$RELEASE_FILE" ]; then
|
||||
echo "::error::$RELEASE_FILE is missing -- there is no release to build."
|
||||
exit 1
|
||||
fi
|
||||
IMAGE_REF=$(sed -n 's/^image:[[:space:]]*//p' "$RELEASE_FILE" | head -1 | tr -d "\"' ")
|
||||
case "$IMAGE_REF" in
|
||||
*/*:*) ;;
|
||||
*) echo "::error::$RELEASE_FILE must set image to <registry>/<repository>:<tag>, found '$IMAGE_REF'."; exit 1 ;;
|
||||
esac
|
||||
RELEASE_TAG="${IMAGE_REF##*:}"
|
||||
IMAGE_REPO="${IMAGE_REF%:*}"
|
||||
EXPECTED_REPO="${ACR_LOGIN_SERVER}/place-a-1"
|
||||
if [ "$IMAGE_REPO" != "$EXPECTED_REPO" ]; then
|
||||
echo "::error::$RELEASE_FILE points at $IMAGE_REPO but this pipeline pushes to $EXPECTED_REPO."
|
||||
exit 1
|
||||
fi
|
||||
# Releases are immutable. A rollback is only worth anything if the tag it
|
||||
# names still holds the image it held on the day it was released, so a tag
|
||||
# is never rebuilt -- the build fails and asks for a bump instead.
|
||||
if az acr repository show-tags --name "$ACR_NAME" --repository "place-a-1" --output tsv 2>/dev/null | grep -qx "$RELEASE_TAG"; then
|
||||
echo "::error::Release $RELEASE_TAG already exists in $ACR_NAME. Bump the tag in $RELEASE_FILE -- releases are never overwritten."
|
||||
exit 1
|
||||
fi
|
||||
echo "IMAGE_FULL=$IMAGE_REF" >> $GITHUB_ENV
|
||||
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
|
||||
echo "✓ Building release $RELEASE_TAG"
|
||||
|
||||
- name: Build and Push Docker image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# Three tags on one image: the release, which is the only one any deploy
|
||||
# ever names; the commit sha, which is provenance and is never deployed;
|
||||
# and latest, for anyone poking at the registry by hand.
|
||||
IMAGE_SHA="${ACR_LOGIN_SERVER}/place-a-1:${{ gitea.sha }}"
|
||||
IMAGE_LATEST="${ACR_LOGIN_SERVER}/place-a-1:latest"
|
||||
docker build -t "$IMAGE_FULL" -t "$IMAGE_SHA" -t "$IMAGE_LATEST" .
|
||||
docker push "$IMAGE_FULL"
|
||||
docker push "$IMAGE_SHA"
|
||||
docker push "$IMAGE_LATEST"
|
||||
echo "✓ Pushed: $IMAGE_FULL"
|
||||
|
||||
- name: Build Summary
|
||||
run: |
|
||||
echo "### ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| | |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| **Service** | place-a-1 |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| **Release** | \`$RELEASE_TAG\` |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| **Commit** | ${{ gitea.sha }} |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| **Image** | $IMAGE_FULL |" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
name: Deploy to Humanitec v2
|
||||
name: Deploy to Orchestrator
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Build and Push to ACR"]
|
||||
types: [completed]
|
||||
# Must list the branches the build actually runs on. Without standard branching
|
||||
# the build runs on main, and a list of dev/staging/prod would silently match
|
||||
# nothing -- the deploy would never fire and the build would look successful.
|
||||
branches: [ "dev", "staging", "prod" ]
|
||||
# The rollback path. Editing .platform/release.yaml is how a release is chosen, and
|
||||
# build-push.yml deliberately ignores .platform/, so nothing else would trigger a
|
||||
# deploy for it. This is what turns an approved rollback pull request into a running
|
||||
# rollback the moment it merges.
|
||||
push:
|
||||
branches: [ "dev", "staging", "prod" ]
|
||||
paths:
|
||||
- '.platform/release.yaml'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
@@ -12,104 +23,257 @@ on:
|
||||
required: true
|
||||
default: 'dev'
|
||||
type: choice
|
||||
options: [dev, staging, production]
|
||||
options:
|
||||
- dev
|
||||
- staging
|
||||
- prod
|
||||
|
||||
env:
|
||||
HUMANITEC_ORG: skillful-wild-chicken-2617
|
||||
HUMANITEC_AUTH_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
|
||||
PO_API_URL: https://api.dev.orchestrator.crucible.kyndemo.live
|
||||
PO_ORG_ID: crucible
|
||||
PO_AUTH_TOKEN: ${{ secrets.PO_AUTH_TOKEN }}
|
||||
# ONE ORCHESTRATOR PROJECT PER APPLICATION.
|
||||
#
|
||||
# This used to be the shared `apps-cluster` project with one environment per app, which
|
||||
# made every app a peer of every other: the Orchestrator tab on any component listed the
|
||||
# entire estate, and an app had exactly one environment named after itself, so there was
|
||||
# nowhere for dev/staging/prod to live.
|
||||
#
|
||||
# That shape existed to avoid a Terraform pull request against config/projects.tf for every
|
||||
# scaffolded app. That constraint turned out not to be real -- `octl create project`,
|
||||
# `octl create runner-rule` and `octl create environment` are all runtime operations, so
|
||||
# the workflow below builds the whole thing on first deploy and needs no repository change.
|
||||
PROJECT_ID: place-a-1
|
||||
DEFAULT_ENV_ID: dev
|
||||
ACR_REGISTRY: bstagecjotdevacr.azurecr.io
|
||||
# The runner now comes from .platform/placement.yaml, through the guard job -- see "Read the placement decision".
|
||||
# The runner a project's workloads execute on. This is NOT cosmetic: the Kubernetes and
|
||||
# Helm providers are ambient, so a workload lands in whichever cluster its runner lives in,
|
||||
# and Terraform state is keyed per runner. A project bound to the wrong runner deploys to
|
||||
# the wrong cluster, and repointing it afterwards orphans the state it already owns.
|
||||
OCTL_VERSION: 1.0.0
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy to Humanitec v2
|
||||
guard:
|
||||
name: Placement guard
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
|
||||
outputs:
|
||||
ready: ${{ steps.check.outputs.ready }}
|
||||
runner: ${{ steps.placement.outputs.runner }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install dependencies
|
||||
run: apt-get update -qq && apt-get install -y jq
|
||||
- name: Install hctl CLI
|
||||
with:
|
||||
# The exact commit the deploy job ships, not a branch name. On a workflow_run the
|
||||
# default checkout is the DEFAULT branch, and a branch name can move between this job
|
||||
# and the deploy job -- the guard must judge the very commit the deploy will ship.
|
||||
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
|
||||
|
||||
- name: Check platform initialized
|
||||
id: check
|
||||
run: |
|
||||
HCTL_VERSION=$(curl -s https://api.github.com/repos/humanitec/hctl/releases/latest | jq -r '.tag_name')
|
||||
mkdir -p /tmp/hctl-install
|
||||
curl -sLo /tmp/hctl-install/hctl.tar.gz "https://github.com/humanitec/hctl/releases/download/${HCTL_VERSION}/hctl_${HCTL_VERSION#v}_linux_amd64.tar.gz"
|
||||
tar -xzf /tmp/hctl-install/hctl.tar.gz -C /tmp/hctl-install
|
||||
install -m 755 /tmp/hctl-install/hctl /usr/local/bin/hctl
|
||||
- name: Ensure Humanitec project and environment exist
|
||||
env:
|
||||
HUMANITEC_AUTH_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
|
||||
run: |
|
||||
DISPATCH_ENV="${{ github.event.inputs.environment }}"
|
||||
ENV_ID="${DISPATCH_ENV:-$DEFAULT_ENV_ID}"
|
||||
# Create project if it doesn't exist (hctl exits 0 if already exists)
|
||||
hctl create project "$PROJECT_ID" --set display_name="place-a-1" 2>&1 | grep -v "already exists" || true
|
||||
# Create environment if it doesn't exist
|
||||
hctl create environment "$PROJECT_ID" "$ENV_ID" --set env_type_id=development --set display_name="Development" 2>&1 | grep -v "already exists" || true
|
||||
echo "✓ Project $PROJECT_ID / env $ENV_ID ready"
|
||||
- name: Deploy with Score
|
||||
env:
|
||||
HUMANITEC_AUTH_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
|
||||
run: |
|
||||
DISPATCH_ENV="${{ github.event.inputs.environment }}"
|
||||
ENV_ID="${DISPATCH_ENV:-$DEFAULT_ENV_ID}"
|
||||
DEFAULT_IMAGE="$ACR_REGISTRY/place-a-1:latest"
|
||||
# Pre-flight: wait for any deployment from a prior run to finish before calling hctl.
|
||||
# hctl refuses to start a new deployment while one is still executing.
|
||||
echo "Pre-flight: checking for in-progress deployments..."
|
||||
MAX_PREFLIGHT=420
|
||||
PREFLIGHT_WAITED=0
|
||||
while [ $PREFLIGHT_WAITED -lt $MAX_PREFLIGHT ]; do
|
||||
PREFLIGHT_STATUS=$(curl -sf -H "Authorization: Bearer $HUMANITEC_AUTH_TOKEN" "https://api.humanitec.dev/orgs/$HUMANITEC_ORG/last-deployments?env_id=$ENV_ID&project_id=$PROJECT_ID&state_change_only=true" | jq -r '.items[0].status // "none"' 2>/dev/null || echo "none")
|
||||
if [ "$PREFLIGHT_STATUS" != "in progress" ] && [ "$PREFLIGHT_STATUS" != "pending" ] && [ "$PREFLIGHT_STATUS" != "executing" ]; then
|
||||
echo "Pre-flight passed (status=$PREFLIGHT_STATUS). Proceeding."
|
||||
break
|
||||
fi
|
||||
echo " Prior deployment still running ($PREFLIGHT_WAITED s elapsed, status=$PREFLIGHT_STATUS)..."
|
||||
sleep 15
|
||||
PREFLIGHT_WAITED=$((PREFLIGHT_WAITED + 15))
|
||||
done
|
||||
# First deploy — provisions all resources. On a brand-new Humanitec project the
|
||||
# dns-k8s-ingress Terraform module runs before the K8s Service exists, so the
|
||||
# ingress backend port falls back to 3000. A second deploy (below) corrects it
|
||||
# once the Service is up, which is essential for Java/Python apps on port 8080.
|
||||
HCTL_EXIT=0
|
||||
timeout 300 hctl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml --no-prompt --default-image "$DEFAULT_IMAGE" || HCTL_EXIT=$?
|
||||
if [ "$HCTL_EXIT" -eq 0 ]; then
|
||||
echo "✓ First deployment complete for place-a-1 to $ENV_ID"
|
||||
elif [ "$HCTL_EXIT" -eq 124 ]; then
|
||||
echo "✓ First deployment submitted (polling timed out — waiting for K8s to settle)"
|
||||
if [ -f ".platform/initialized.md" ]; then
|
||||
echo "ready=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "✗ hctl failed with exit code $HCTL_EXIT"
|
||||
exit $HCTL_EXIT
|
||||
echo "ready=false" >> $GITHUB_OUTPUT
|
||||
echo "Skipping: .platform/initialized.md not found"
|
||||
fi
|
||||
# Poll Humanitec API until the first deployment is no longer in-progress before
|
||||
# re-deploying. A flat sleep is unreliable — Terraform DNS modules can take 4-6 min.
|
||||
echo "Waiting for first deployment to finish (polling Humanitec API)..."
|
||||
MAX_WAIT=360
|
||||
WAITED=0
|
||||
while [ $WAITED -lt $MAX_WAIT ]; do
|
||||
DEPLOY_STATUS=$(curl -sf -H "Authorization: Bearer $HUMANITEC_AUTH_TOKEN" "https://api.humanitec.dev/orgs/$HUMANITEC_ORG/last-deployments?env_id=$ENV_ID&project_id=$PROJECT_ID&state_change_only=true" | jq -r '.items[0].status // "unknown"' 2>/dev/null || echo "unknown")
|
||||
if [ "$DEPLOY_STATUS" != "in progress" ] && [ "$DEPLOY_STATUS" != "pending" ] && [ "$DEPLOY_STATUS" != "executing" ]; then
|
||||
echo "First deployment finished with status: $DEPLOY_STATUS"
|
||||
break
|
||||
fi
|
||||
echo " Still running ($WAITED s elapsed, status=$DEPLOY_STATUS)..."
|
||||
sleep 15
|
||||
WAITED=$((WAITED + 15))
|
||||
done
|
||||
if [ $WAITED -ge $MAX_WAIT ]; then
|
||||
echo "Warning: first deployment still running after $MAX_WAIT s — proceeding anyway"
|
||||
|
||||
# The placement decision is enforced HERE, on every deploy, not only by the form that
|
||||
# wrote it. Missing, refused or unreadable: this job fails, the deploy job that needs it
|
||||
# never starts, and nothing reaches the orchestrator. REFUSED lines are plain echo as
|
||||
# well as ::error:: because Gitea's log view may not render the annotation.
|
||||
- name: Read the placement decision
|
||||
id: placement
|
||||
if: steps.check.outputs.ready == 'true'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
RECORD=.platform/placement.yaml
|
||||
# Top-level keys, one line each -- the same contract release.yaml keeps.
|
||||
field() { sed -n "s/^$1:[[:space:]]*//p" "$RECORD" | head -1 | sed -e 's/^"//' -e 's/"$//'; }
|
||||
if [ ! -f "$RECORD" ]; then
|
||||
echo "REFUSED: no placement decision. $RECORD is missing, and nothing deploys without an approved record."
|
||||
echo "::error::No placement decision: $RECORD is missing."
|
||||
exit 1
|
||||
fi
|
||||
# Second deploy — dns module now reads the real K8s Service port, fixing the ingress
|
||||
HCTL_EXIT2=0
|
||||
timeout 120 hctl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml --no-prompt --default-image "$DEFAULT_IMAGE" || HCTL_EXIT2=$?
|
||||
if [ "$HCTL_EXIT2" -eq 0 ]; then
|
||||
echo "✓ Deployment finalised for place-a-1 to $ENV_ID"
|
||||
elif [ "$HCTL_EXIT2" -eq 124 ]; then
|
||||
echo "✓ Second deployment submitted for place-a-1 to $ENV_ID (polling timed out)"
|
||||
DECISION=$(field decision)
|
||||
REASON=$(field reason)
|
||||
RUNNER=$(field runner)
|
||||
ZONE=$(field landing_zone_name)
|
||||
case "$DECISION" in
|
||||
placed) ;;
|
||||
refused)
|
||||
echo "REFUSED: $REASON"
|
||||
echo "::error::Placement refused: $REASON"
|
||||
exit 1 ;;
|
||||
*)
|
||||
echo "REFUSED: $RECORD has decision '$DECISION'; expected placed or refused."
|
||||
echo "::error::Unreadable placement decision '$DECISION'."
|
||||
exit 1 ;;
|
||||
esac
|
||||
case "$RUNNER" in
|
||||
''|none)
|
||||
echo "REFUSED: $RECORD is placed but names no runner."
|
||||
echo "::error::Placed record names no runner."
|
||||
exit 1 ;;
|
||||
esac
|
||||
echo "PLACED: $ZONE -- runner $RUNNER"
|
||||
echo "runner=$RUNNER" >> "$GITHUB_OUTPUT"
|
||||
|
||||
deploy:
|
||||
name: Deploy to Orchestrator
|
||||
needs: guard
|
||||
# Every trigger needs a runner from the placement record. workflow_dispatch used to skip
|
||||
# the guard's verdict; an empty runner now means the guard did not place this workload.
|
||||
if: >-
|
||||
needs.guard.outputs.runner != '' && (
|
||||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
|
||||
github.event_name == 'push' ||
|
||||
github.event_name == 'workflow_dispatch')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
# The built commit, not a branch name (see the guard). On a workflow_run the default
|
||||
# checkout is the DEFAULT branch, not the one that was built. That did not matter while
|
||||
# the image tag came from an event field; it matters now that the tag is read out of a file in this checkout.
|
||||
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
|
||||
|
||||
- name: Install octl
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSLo /tmp/octl.tar.gz \
|
||||
"https://github.com/stellwerk-labs/platform-orchestrator-cli/releases/download/v${OCTL_VERSION}/platform-orchestrator-cli_${OCTL_VERSION}_linux_amd64.tar.gz"
|
||||
tar xzf /tmp/octl.tar.gz -C /tmp
|
||||
install -m 755 /tmp/octl /usr/local/bin/octl
|
||||
octl --version
|
||||
|
||||
- name: Derive environment
|
||||
run: |
|
||||
# The environment is now a STAGE of this application -- dev, staging, prod -- because
|
||||
# the project is the application. It used to be the component id, which was the only
|
||||
# option while every app shared one project and had to be distinguishable inside it.
|
||||
DISPATCH_ENV="${{ github.event.inputs.environment }}"
|
||||
if [ -n "$DISPATCH_ENV" ]; then
|
||||
ENV_ID="$DISPATCH_ENV"
|
||||
else
|
||||
echo "✗ Second hctl deploy failed with exit code $HCTL_EXIT2"
|
||||
exit $HCTL_EXIT2
|
||||
# On a workflow_run the branch is the triggering run's, not this job's checkout.
|
||||
BRANCH="${{ github.event.workflow_run.head_branch }}"
|
||||
BRANCH="${BRANCH:-${GITHUB_REF_NAME}}"
|
||||
case "$BRANCH" in
|
||||
staging) ENV_ID=staging ;;
|
||||
prod|main|master) ENV_ID=prod ;;
|
||||
*) ENV_ID=dev ;;
|
||||
esac
|
||||
echo "Branch '$BRANCH' maps to environment '$ENV_ID'"
|
||||
fi
|
||||
echo "ENV_ID=$ENV_ID" >> $GITHUB_ENV
|
||||
echo "Deploying $PROJECT_ID to environment: $ENV_ID"
|
||||
|
||||
- name: Ensure the project and its runner binding exist
|
||||
env:
|
||||
# From the placement record, through the guard -- never a literal in this file.
|
||||
PO_RUNNER_ID: ${{ needs.guard.outputs.runner }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "$PO_RUNNER_ID" ]; then
|
||||
echo "::error::No runner from the placement guard; refusing to bind."
|
||||
echo "REFUSED: No runner from the placement guard."
|
||||
exit 1
|
||||
fi
|
||||
# Created on first deploy rather than by a pull request against config/projects.tf.
|
||||
# None of this needs a repository change: project, runner rule and environment are
|
||||
# all runtime objects.
|
||||
#
|
||||
# Neither create is idempotent, so both fall through to a read on the second run.
|
||||
octl create project "$PROJECT_ID" \
|
||||
--set display_name='place-a-1' || \
|
||||
octl get project "$PROJECT_ID"
|
||||
|
||||
# The runner rule routes this project's deployments. A project already bound to a
|
||||
# DIFFERENT runner is refused, never repointed: Terraform state is keyed per runner,
|
||||
# so rebinding orphans what it owns. A failing read is a failure, not "no rule" --
|
||||
# guessing "absent" is how a second rule gets created.
|
||||
RULES=$(octl get runner-rules -o json)
|
||||
# Several rules for one project, or a rule with no runner, is a binding nobody can
|
||||
# vouch for: refuse it by name rather than pick the first. unique + join stays jq 1.6-safe.
|
||||
if ! BOUND=$(printf '%s' "$RULES" | jq -r --arg p "$PROJECT_ID" '[.. | objects | select(.project_id? == $p) | (.runner_id // "<none>")] | unique | if length > 1 then error("bound to several runners: \(join(", "))") else (.[0] // empty) end' 2>&1); then
|
||||
echo "REFUSED: project '$PROJECT_ID' has an ambiguous runner binding: $BOUND"
|
||||
echo "::error::Runner binding is ambiguous; refusing to continue."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$BOUND" ]; then
|
||||
octl create runner-rule \
|
||||
--set project_id="$PROJECT_ID" \
|
||||
--set runner_id="$PO_RUNNER_ID" \
|
||||
--no-prompt
|
||||
elif [ "$BOUND" != "$PO_RUNNER_ID" ]; then
|
||||
echo "REFUSED: project '$PROJECT_ID' is bound to runner '$BOUND', but its placement record names '$PO_RUNNER_ID'."
|
||||
echo "::error::Runner binding disagrees with the placement record; refusing to repoint."
|
||||
exit 1
|
||||
else
|
||||
echo "Runner rule for '$PROJECT_ID' already binds '$BOUND', as the record says."
|
||||
fi
|
||||
|
||||
- name: Ensure the environment exists
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# Project and environment ids are POSITIONAL; only env_type_id and display_name go
|
||||
# through --set. `dev` and `stable` are the only environment TYPES that exist, so
|
||||
# staging rides on the dev type -- the type governs policy, the id governs identity.
|
||||
case "$ENV_ID" in
|
||||
prod) ENV_TYPE=stable ;;
|
||||
*) ENV_TYPE=dev ;;
|
||||
esac
|
||||
octl create environment "$PROJECT_ID" "$ENV_ID" \
|
||||
--set env_type_id="$ENV_TYPE" \
|
||||
--set display_name="$ENV_ID" || \
|
||||
octl get environment "$PROJECT_ID" "$ENV_ID"
|
||||
|
||||
- name: Deploy the Score workload
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# `octl score deploy` is ADDITIVE — it adds or updates a workload in the manifest and
|
||||
# never removes one. That is the opposite of `octl deploy`, where omission is
|
||||
# deletion. Do not substitute one for the other.
|
||||
# No --show-logs: octl 1.0.0 has no such flag and exits 1 with `unknown flag`
|
||||
# BEFORE contacting the orchestrator, so the whole deploy dies on an argument
|
||||
# typo. Its nearest relatives are --runner-logs-level (default `info`, already
|
||||
# what we want) and --skip-logs (which suppresses storage). Neither streams the
|
||||
# runner's logs into this job, so there is nothing to substitute -- the runner
|
||||
# logs are read from the orchestrator, not from here.
|
||||
# The image comes from .platform/release.yaml, the one place a deployable tag
|
||||
# is written down. It used to be derived from the triggering commit, which made
|
||||
# "what is running" a question you answered by reading event metadata -- and
|
||||
# left a rollback with no file to edit and no way to name an older image.
|
||||
RELEASE_FILE=.platform/release.yaml
|
||||
if [ ! -f "$RELEASE_FILE" ]; then
|
||||
echo "::error::$RELEASE_FILE is missing -- there is nothing to deploy."
|
||||
exit 1
|
||||
fi
|
||||
IMAGE_REF=$(sed -n 's/^image:[[:space:]]*//p' "$RELEASE_FILE" | head -1 | tr -d "\"' ")
|
||||
case "$IMAGE_REF" in
|
||||
*/*:*) ;;
|
||||
*) echo "::error::$RELEASE_FILE must set image to <registry>/<repository>:<tag>, found '$IMAGE_REF'."; exit 1 ;;
|
||||
esac
|
||||
echo "IMAGE_REF=$IMAGE_REF" >> $GITHUB_ENV
|
||||
echo "Deploying $IMAGE_REF"
|
||||
|
||||
octl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml \
|
||||
--default-image "$IMAGE_REF" \
|
||||
--no-prompt
|
||||
|
||||
- name: Deployment summary
|
||||
if: always()
|
||||
run: |
|
||||
# IMAGE_REF is unset when the deploy step failed before reading the release
|
||||
# file, and this step runs on failure too.
|
||||
DEPLOYED_IMAGE="${IMAGE_REF:-unresolved}"
|
||||
SHORT_SHA="${{ github.event.workflow_run.head_sha || github.sha }}"
|
||||
SHORT_SHA="${SHORT_SHA:0:7}"
|
||||
echo "## Deployment Result" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Project | \`$PROJECT_ID\` |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Environment | \`$ENV_ID\` |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Image | \`$DEPLOYED_IMAGE\` |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Triggering commit | \`$SHORT_SHA\` |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "[View in Orchestrator Console](https://console.dev.orchestrator.crucible.kyndemo.live/orgs/$PO_ORG_ID/projects/$PROJECT_ID/environments/$ENV_ID)" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
Reference in New Issue
Block a user