ci: restore the platform's orchestrator deploy workflow
This commit is contained in:
@@ -2,7 +2,13 @@ name: Build and Push to ACR
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
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: {}
|
workflow_dispatch: {}
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
@@ -16,6 +22,11 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Build and Push
|
name: Build and Push
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: >-
|
||||||
|
github.ref != 'refs/heads/main' && (
|
||||||
|
github.event_name == 'workflow_dispatch' ||
|
||||||
|
(github.event_name == 'push' && github.event.before != '0000000000000000000000000000000000000000')
|
||||||
|
)
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
id-token: write
|
id-token: write
|
||||||
@@ -23,52 +34,16 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
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
|
- name: Install Azure CLI
|
||||||
run: |
|
run: |
|
||||||
if ! command -v az &>/dev/null; then
|
command -v az &>/dev/null || curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||||
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
|
||||||
fi
|
- 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)
|
- name: Azure login (OIDC)
|
||||||
run: |
|
run: |
|
||||||
az login \
|
az login \
|
||||||
@@ -76,13 +51,78 @@ jobs:
|
|||||||
--username "$AZURE_CLIENT_ID" \
|
--username "$AZURE_CLIENT_ID" \
|
||||||
--tenant "$AZURE_TENANT_ID" \
|
--tenant "$AZURE_TENANT_ID" \
|
||||||
--federated-token "$(cat $AZURE_FEDERATED_TOKEN_FILE)"
|
--federated-token "$(cat $AZURE_FEDERATED_TOKEN_FILE)"
|
||||||
- name: Build and push via ACR Tasks
|
echo "✓ Azure login successful"
|
||||||
|
|
||||||
|
- name: Get ACR details
|
||||||
run: |
|
run: |
|
||||||
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
ACR_NAME=$(az acr list --query "[0].name" -o tsv)
|
||||||
az acr build \
|
ACR_NAME="${ACR_NAME:-bstagecjotdevacr}"
|
||||||
--registry bstagecjotdevacr \
|
echo "ACR_NAME=$ACR_NAME" >> $GITHUB_ENV
|
||||||
--image vehicle-telematics:$SHORT_SHA \
|
echo "ACR_LOGIN_SERVER=${ACR_NAME}.azurecr.io" >> $GITHUB_ENV
|
||||||
--image vehicle-telematics:latest \
|
echo "✓ Using ACR: ${ACR_NAME}.azurecr.io"
|
||||||
--file Dockerfile \
|
|
||||||
.
|
- name: ACR Login
|
||||||
echo "✓ Pushed: bstagecjotdevacr.azurecr.io/vehicle-telematics:$SHORT_SHA"
|
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}/vehicle-telematics"
|
||||||
|
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 "vehicle-telematics" --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}/vehicle-telematics:${{ gitea.sha }}"
|
||||||
|
IMAGE_LATEST="${ACR_LOGIN_SERVER}/vehicle-telematics: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** | vehicle-telematics |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Release** | \`$RELEASE_TAG\` |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Commit** | ${{ gitea.sha }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Image** | $IMAGE_FULL |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|||||||
Reference in New Issue
Block a user