Finalize and compose extraction outcomes (#89) #155
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Promote Immutable Image | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ['v*'] | |
| workflow_dispatch: {} | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: khamel83/argus | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| digest: ${{ steps.build.outputs.digest }} | |
| receipt_sha256: ${{ steps.receipt.outputs.sha256 }} | |
| source_revision: ${{ steps.identity.outputs.source_revision }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 | |
| - name: Resolve source commit | |
| id: identity | |
| run: echo "source_revision=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 | |
| - name: Login to GHCR | |
| uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| id: build | |
| uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 | |
| with: | |
| context: . | |
| build-args: VCS_REF=${{ steps.identity.outputs.source_revision }} | |
| push: true | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ steps.identity.outputs.source_revision }} | |
| provenance: mode=max | |
| sbom: true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Write release receipt | |
| id: receipt | |
| run: | | |
| python scripts/write_release_receipt.py \ | |
| --image "${REGISTRY}/${IMAGE_NAME}" \ | |
| --digest "${{ steps.build.outputs.digest }}" \ | |
| --source-revision "${{ steps.identity.outputs.source_revision }}" \ | |
| --repository "${GITHUB_REPOSITORY}" \ | |
| --workflow "${GITHUB_WORKFLOW}" \ | |
| --run-id "${GITHUB_RUN_ID}" \ | |
| --run-attempt "${GITHUB_RUN_ATTEMPT}" \ | |
| --output release-receipt.json | |
| echo "sha256=$(sha256sum release-receipt.json | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| - name: Retain release receipt | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: release-receipt | |
| path: release-receipt.json | |
| if-no-files-found: error | |
| retention-days: 90 | |
| promote: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| environment: production | |
| concurrency: | |
| group: argus-production | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Join deployment tailnet | |
| uses: tailscale/github-action@780049a30b6ff5c378a9e7b389d15ece7a204888 # v4.1.3 | |
| with: | |
| oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} | |
| oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} | |
| tags: tag:argus-deployer | |
| targets: homelab-ts | |
| - name: Submit forced-command promotion | |
| env: | |
| IMAGE_REF: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.build.outputs.digest }} | |
| SOURCE_REVISION: ${{ needs.build.outputs.source_revision }} | |
| RECEIPT_SHA256: ${{ needs.build.outputs.receipt_sha256 }} | |
| DEPLOY_KEY: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }} | |
| KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} | |
| run: | | |
| install -d -m 0700 "$RUNNER_TEMP/ssh" | |
| install -m 0600 /dev/null "$RUNNER_TEMP/ssh/deploy_key" | |
| printf '%s\n' "$DEPLOY_KEY" > "$RUNNER_TEMP/ssh/deploy_key" | |
| printf '%s\n' "$KNOWN_HOSTS" > "$RUNNER_TEMP/ssh/known_hosts" | |
| ssh -i "$RUNNER_TEMP/ssh/deploy_key" \ | |
| -o IdentitiesOnly=yes \ | |
| -o StrictHostKeyChecking=yes \ | |
| -o UserKnownHostsFile="$RUNNER_TEMP/ssh/known_hosts" \ | |
| "argus-deploy@homelab-ts" \ | |
| "argus-deploy promote ${IMAGE_REF} ${SOURCE_REVISION} ${RECEIPT_SHA256}" |