name: build # Builds, signs and publishes ghcr.io/coder/coder-preview for every commit to # main and release/*. dogfood.cdr.dev pulls new main builds itself through Flux # image automation in coder/dogfood, so this workflow needs no cluster access. # # The build job signs exactly like release.yaml, through the same # ./.github/actions/build-coder action. This workflow has no pull_request or # workflow_dispatch trigger: the release-signer identity provider only accepts # this file on a push to main or release/X.Y, or the creation of a release/X.Y # branch, from the ci-signing environment. on: push: branches: - main - release/* # Same as the docs filter in ci.yaml's changes job: commits that only # touch these don't need a signed build. paths-ignore: - "docs/**" - ".claude/docs/**" - "*.md" - "examples/web-server/**" - "examples/monitoring/**" - "examples/lima/**" # GitHub Actions does not reliably trigger push-based runs when a new branch # is created at a commit that already has a run (e.g. from main). The create # event fires separately so newly cut release branches get an image. Other # branch and tag creations are filtered out by the build job condition. create: permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false jobs: build: if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-22.04' }} # Gates access to the signing secrets and identities. Both GCP signing # service accounts only trust this environment and `release`. environment: ci-signing permissions: contents: read # Necessary to push docker images to ghcr.io. packages: write # Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage) # Also necessary for keyless cosign (https://docs.sigstore.dev/cosign/signing/overview/) # And for GitHub Actions attestation id-token: write # Required for GitHub Actions attestation attestations: write env: DOCKER_CLI_EXPERIMENTAL: "enabled" steps: - name: Harden Runner uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2 with: egress-policy: audit - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - name: GHCR Login uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # The fat binaries embed every slim binary, so this builds and signs all # of them (darwin, Windows and GPG), as release.yaml does. Notarization # only applies to darwin archives, which main builds don't produce. - name: Build and sign id: build uses: ./.github/actions/build-coder with: sign: "true" extra-tools: "cosign syft" # Enable React profiling build and discoverable source maps for the # dogfood deployment (dogfood.cdr.dev). This also applies to # release/* branch builds, but those still produce coder-preview # images, not release images. Release images are built by # release.yaml (no profiling). react-profiling: "true" targets: >- build/coder_@VERSION@_linux_amd64 build/coder_@VERSION@_linux_arm64 build/coder_@VERSION@_linux_armv7 build/coder_@VERSION@_windows_amd64.zip build/coder_@VERSION@_linux_amd64.tar.gz build/coder_@VERSION@_linux_arm64.tar.gz build/coder_@VERSION@_linux_armv7.tar.gz build/coder_@VERSION@_linux_amd64.deb build/coder_@VERSION@_linux_arm64.deb build/coder_@VERSION@_linux_armv7.deb ev-workload-identity-provider: ${{ vars.GCP_CODE_SIGNING_WORKLOAD_ID_PROVIDER }} ev-service-account: ${{ vars.GCP_CODE_SIGNING_SERVICE_ACCOUNT }} ev-key: ${{ secrets.EV_KEY }} ev-keystore: ${{ secrets.EV_KEYSTORE }} ev-tsa-url: ${{ secrets.EV_TSA_URL }} ev-signing-cert: ${{ secrets.EV_SIGNING_CERT }} release-signer-workload-identity-provider: ${{ secrets.GPG_KMS_WORKLOAD_ID_PROVIDER }} release-signer-service-account: ${{ secrets.GPG_KMS_SERVICE_ACCOUNT }} gpg-release-key: ${{ secrets.GPG_RELEASE_KEY_BASE64 }} gpg-kms-key: ${{ secrets.GPG_KMS_KEY }} ac-certificate-pem: ${{ secrets.AC_CERTIFICATE_PEM }} ac-kms-key-ring: ${{ secrets.AC_KMS_KEY_RING }} ac-kms-key: ${{ secrets.AC_KMS_KEY }} # The KMS key's OpenPGP form can only be made by CI. Publish it from main # builds so its fingerprint can be checked and added to release.key. - name: Print GPG KMS public key if: github.ref == 'refs/heads/main' run: | set -euo pipefail if [[ -z "$GPG_KMS_KEY" ]]; then echo "GPG_KMS_KEY is not set, skipping." exit 0 fi ./scripts/gpgkms.sh public-key -key "$GPG_KMS_KEY" > "$RUNNER_TEMP/gpg-kms-public.key" gpg --show-keys --with-fingerprint "$RUNNER_TEMP/gpg-kms-public.key" { echo "### Cloud KMS release signing key" echo '```' gpg --show-keys --with-fingerprint "$RUNNER_TEMP/gpg-kms-public.key" cat "$RUNNER_TEMP/gpg-kms-public.key" echo '```' } >> "$GITHUB_STEP_SUMMARY" env: GPG_KMS_KEY: ${{ secrets.GPG_KMS_KEY }} GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.build.outputs.release-signer-credentials-file }} # Free up disk space before building Docker images. The preceding # Build step produces ~2 GB of binaries and packages, the Go build # cache is ~1.3 GB, and node_modules is ~500 MB. Docker image # builds, pushes, and SBOM generation need headroom that isn't # available without reclaiming some of that space. - name: Clean up build cache run: | set -euxo pipefail # Go caches are no longer needed; binaries are already compiled. go clean -cache -modcache # Remove .apk and .rpm packages that are not uploaded as # artifacts and were only built as make prerequisites. rm -f ./build/*.apk ./build/*.rpm - name: Build Linux Docker images id: build-docker env: CODER_IMAGE_BASE: ghcr.io/coder/coder-preview DOCKER_CLI_EXPERIMENTAL: "enabled" # Skip building .deb/.rpm/.apk/.tar.gz as prerequisites for # the Docker image targets; they were already built above. DOCKER_IMAGE_NO_PREREQUISITES: "true" run: | set -euxo pipefail # build Docker images for each architecture version="$(./scripts/version.sh)" tag="${version//+/-}" echo "tag=$tag" >> "$GITHUB_OUTPUT" # build images for each architecture # note: omitting the -j argument to avoid race conditions when pushing make build/coder_"$version"_linux_{amd64,arm64,armv7}.tag # only push if we are on main branch or release branch if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == refs/heads/release/* ]]; then # build and push multi-arch manifest, this depends on the other images # being pushed so will automatically push them # note: omitting the -j argument to avoid race conditions when pushing make push/build/coder_"$version"_linux_{amd64,arm64,armv7}.tag # Define specific tags tags=("$tag") if [ "${GITHUB_REF}" == "refs/heads/main" ]; then # main-- sorts by commit time, so the # dogfood Flux ImagePolicy can select the newest main build. tags+=("main" "latest" "main-$(git log -1 --format=%ct HEAD)-$(git rev-parse --short=12 HEAD)") elif [[ "${GITHUB_REF}" == refs/heads/release/* ]]; then tags+=("release-${GITHUB_REF#refs/heads/release/}") fi # Create and push a multi-arch manifest for each tag # we are adding `latest` tag and keeping `main` for backward # compatibality for t in "${tags[@]}"; do echo "Pushing multi-arch manifest for tag: $t" # shellcheck disable=SC2046 ./scripts/build_docker_multiarch.sh \ --push \ --target "ghcr.io/coder/coder-preview:$t" \ --version "$version" \ $(cat build/coder_"$version"_linux_{amd64,arm64,armv7}.tag) done fi - name: SBOM Generation and Attestation if: github.ref == 'refs/heads/main' continue-on-error: true env: COSIGN_EXPERIMENTAL: 1 BUILD_TAG: ${{ steps.build-docker.outputs.tag }} run: | set -euxo pipefail # Define image base and tags IMAGE_BASE="ghcr.io/coder/coder-preview" TAGS=("${BUILD_TAG}" "main" "latest") # Generate and attest SBOM for each tag for tag in "${TAGS[@]}"; do IMAGE="${IMAGE_BASE}:${tag}" SBOM_FILE="coder_sbom_${tag//[:\/]/_}.spdx.json" echo "Generating SBOM for image: ${IMAGE}" syft "${IMAGE}" -o spdx-json > "${SBOM_FILE}" echo "Attesting SBOM to image: ${IMAGE}" cosign clean --force=true "${IMAGE}" cosign attest --type spdxjson \ --predicate "${SBOM_FILE}" \ --yes \ "${IMAGE}" done - name: Resolve Docker image digests for attestation id: docker_digests if: github.ref == 'refs/heads/main' continue-on-error: true env: IMAGE_BASE: ghcr.io/coder/coder-preview BUILD_TAG: ${{ steps.build-docker.outputs.tag }} run: | set -euxo pipefail main_digest=$(docker buildx imagetools inspect --raw "${IMAGE_BASE}:main" | sha256sum | awk '{print "sha256:"$1}') echo "main_digest=${main_digest}" >> "$GITHUB_OUTPUT" latest_digest=$(docker buildx imagetools inspect --raw "${IMAGE_BASE}:latest" | sha256sum | awk '{print "sha256:"$1}') echo "latest_digest=${latest_digest}" >> "$GITHUB_OUTPUT" version_digest=$(docker buildx imagetools inspect --raw "${IMAGE_BASE}:${BUILD_TAG}" | sha256sum | awk '{print "sha256:"$1}') echo "version_digest=${version_digest}" >> "$GITHUB_OUTPUT" - name: GitHub Attestation for Docker image id: attest_main if: github.ref == 'refs/heads/main' && steps.docker_digests.outputs.main_digest != '' continue-on-error: true uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-name: ghcr.io/coder/coder-preview subject-digest: ${{ steps.docker_digests.outputs.main_digest }} push-to-registry: true - name: GitHub Attestation for Docker image (latest tag) id: attest_latest if: github.ref == 'refs/heads/main' && steps.docker_digests.outputs.latest_digest != '' continue-on-error: true uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-name: ghcr.io/coder/coder-preview subject-digest: ${{ steps.docker_digests.outputs.latest_digest }} push-to-registry: true - name: GitHub Attestation for version-specific Docker image id: attest_version if: github.ref == 'refs/heads/main' && steps.docker_digests.outputs.version_digest != '' continue-on-error: true uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-name: ghcr.io/coder/coder-preview subject-digest: ${{ steps.docker_digests.outputs.version_digest }} push-to-registry: true # Report attestation failures but don't fail the workflow - name: Check attestation status if: github.ref == 'refs/heads/main' run: | # zizmor: ignore[template-injection] We're just reading steps.attest_x.outcome here, no risk of injection if [[ "${{ steps.attest_main.outcome }}" == "failure" ]]; then echo "::warning::GitHub attestation for main tag failed" fi if [[ "${{ steps.attest_latest.outcome }}" == "failure" ]]; then echo "::warning::GitHub attestation for latest tag failed" fi if [[ "${{ steps.attest_version.outcome }}" == "failure" ]]; then echo "::warning::GitHub attestation for version-specific tag failed" fi - name: GitHub Attestation for binaries id: attest_binaries if: github.ref == 'refs/heads/main' continue-on-error: true uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-path: | ./build/*.tar.gz ./build/*.zip ./build/*.deb - name: Report binary attestation failure if: github.ref == 'refs/heads/main' && steps.attest_binaries.outcome == 'failure' run: echo "::warning::GitHub attestation for binaries failed" - name: Upload build artifact (coder-linux-amd64.tar.gz) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-linux-amd64.tar.gz path: ./build/*_linux_amd64.tar.gz retention-days: 7 - name: Upload build artifact (coder-linux-amd64.deb) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-linux-amd64.deb path: ./build/*_linux_amd64.deb retention-days: 7 - name: Upload build artifact (coder-linux-arm64.tar.gz) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-linux-arm64.tar.gz path: ./build/*_linux_arm64.tar.gz retention-days: 7 - name: Upload build artifact (coder-linux-arm64.deb) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-linux-arm64.deb path: ./build/*_linux_arm64.deb retention-days: 7 - name: Upload build artifact (coder-linux-armv7.tar.gz) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-linux-armv7.tar.gz path: ./build/*_linux_armv7.tar.gz retention-days: 7 - name: Upload build artifact (coder-linux-armv7.deb) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-linux-armv7.deb path: ./build/*_linux_armv7.deb retention-days: 7 - name: Upload build artifact (coder-windows-amd64.zip) if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: coder-windows-amd64.zip path: ./build/*_windows_amd64.zip retention-days: 7 # Runs separately from the signing job so this third-party action never runs # in the same job as the signing credentials. prune: needs: build if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest permissions: packages: write steps: - name: Harden Runner uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2 with: egress-policy: audit - name: Prune old images uses: vlaurin/action-ghcr-prune@0cf7d39f88546edd31965acba78cdcb0be14d641 # v0.6.0 with: token: ${{ secrets.GITHUB_TOKEN }} organization: coder container: coder-preview keep-younger-than: 30 # days keep-tags: latest keep-tags-regexes: ^pr prune-tags-regexes: | ^main- ^v prune-untagged: true notify-slack-on-failure: needs: - build - prune runs-on: ubuntu-latest environment: main if: failure() && github.ref == 'refs/heads/main' steps: - name: Send Slack notification run: | curl -X POST -H 'Content-type: application/json' \ --data '{ "blocks": [ { "type": "header", "text": { "type": "plain_text", "text": "❌ Build failure in main", "emoji": true } }, { "type": "section", "text": { "type": "mrkdwn", "text": "*View failure:* <'"${RUN_URL}"'|Click here>" } } ] }' "${SLACK_WEBHOOK}" env: SLACK_WEBHOOK: ${{ secrets.CI_FAILURE_SLACK_WEBHOOK }} RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"