Files
Kyle CarberryandClaude Opus 5.5 c094099c15 ci: publish GHCR images through coder/ghcr-publisher (#8154)
GitHub grants package write per repository, so any workflow on any
branch here could overwrite ghcr.io/coder/code-server, including
latest and version tags. The docker job now pushes the GHCR copy to
code-server-staging (Docker Hub is unchanged), signs one release
attestation stating the version, the tag's commit and each image's
public GHCR tags (from the same bake file), and dispatches
coder/ghcr-publisher with a coder-ghcr-dispatch token. The publisher
verifies the release and the attestation, then copies each image.
Version tags never move; rolling tags move only for the highest stable
version.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:06:08 -05:00

441 lines
19 KiB
YAML

name: Publish code-server
on:
# Shows the manual trigger in GitHub UI
# helpful as a back-up in case the GitHub Actions Workflow fails
workflow_dispatch:
inputs:
version:
type: string
required: true
release:
types: [released]
permissions: {}
# Cancel in-progress runs for pull requests when developers push
# additional changes, and serialize builds in branches.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-concurrency-to-cancel-any-in-progress-job-or-run
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# Nothing is published unless the release came from release.yaml: coder-release-publisher made
# it (only release.yaml's approve job can sign as that App, after a second person approved), it
# is published and immutable, and every file was built and attested by release.yaml from main.
verify:
runs-on: ubuntu-latest
permissions:
contents: read
attestations: read
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ inputs.version || github.ref_name }}
steps:
- name: Check the release
run: |
set -euo pipefail
fail() { echo "::error::$*"; exit 1; }
# TAG comes from the dispatch input, so only a version may reach the shell.
[[ "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]] || fail "The version must look like v1.2.3 or v1.2.3-rc.1."
tag="v${TAG#v}"
release="$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$tag")"
author="$(jq -r .author.login <<<"$release")"
[[ "$author" == "coder-release-publisher[bot]" ]] || fail "$tag was published by $author, not by release.yaml (coder-release-publisher)."
[[ "$(jq -r .draft <<<"$release")" == "false" ]] || fail "$tag is a draft."
[[ "$(jq -r .immutable <<<"$release")" == "true" ]] || fail "$tag is not an immutable release."
- name: Verify the files
run: |
set -euo pipefail
tag="v${TAG#v}"
gh release download "$tag" --repo "$GITHUB_REPOSITORY" --dir release-files
for f in release-files/*; do
gh attestation verify "$f" \
--repo "$GITHUB_REPOSITORY" \
--signer-workflow "$GITHUB_REPOSITORY/.github/workflows/release.yaml" \
--source-ref refs/heads/main \
--deny-self-hosted-runners
done
npm:
runs-on: ubuntu-latest
needs: verify
environment: release
permissions:
# Required so GitHub can issue an OIDC token for trusted publishing.
id-token: write
env:
TAG: ${{ inputs.version || github.ref_name }}
NPM_ENVIRONMENT: "production"
steps:
- name: Set version to tag without leading v
run: |
# TAG comes from the dispatch input, so only a version may reach GITHUB_ENV and the shell.
if [[ ! "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
echo "::error::The version must look like v1.2.3 or v1.2.3-rc.1."
exit 1
fi
echo "VERSION=${TAG#v}" >> "$GITHUB_ENV"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6
with:
node-version-file: .node-version
registry-url: "https://registry.npmjs.org"
# No dependency cache in a job that publishes: a cache saved by another run could
# change what gets published.
package-manager-cache: false
- uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f # v1.13
with:
repository: "coder/code-server"
tag: ${{ env.TAG }}
fileName: "package.tar.gz"
out-file-path: "release-npm-package"
- run: tar -xzf release-npm-package/package.tar.gz
- run: |
pushd release
npm publish --tag latest --access public
aur:
runs-on: ubuntu-latest
needs: verify
environment: release
permissions:
contents: read
id-token: write # Cloud KMS signs the coder-automations App's JWT
timeout-minutes: 10
env:
TAG: ${{ inputs.version || github.ref_name }}
steps:
- name: Set version to tag without leading v
run: |
# TAG comes from the dispatch input, so only a version may reach GITHUB_ENV and the shell.
if [[ ! "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
echo "::error::The version must look like v1.2.3 or v1.2.3-rc.1."
exit 1
fi
echo "VERSION=${TAG#v}" >> "$GITHUB_ENV"
- name: Generate coder-automations app token
id: app_token
# The App's key is a non-exportable Cloud KMS key; only this workflow, in this environment,
# may sign with it.
uses: coder/github-app-token-action@00eaec58ee1bfea9c8b48655b7ab7470b07739e5 # main 2026-11-17
with:
client-id: ${{ secrets.CODER_AUTOMATION_APP_ID }}
kms-key: ${{ secrets.CODER_AUTOMATION_APP_KMS_KEY }}
workload-identity-provider: ${{ secrets.APP_KEYS_WORKLOAD_ID_PROVIDER }}
owner: coder
repositories: code-server-aur
permissions: |
contents: write
pull_requests: write
# The coder-automations token can write to coder/code-server-aur only, so the update branch
# is pushed there and the PR opened from it.
- name: Checkout code-server-aur repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
repository: "coder/code-server-aur"
token: ${{ steps.app_token.outputs.token }}
ref: "master"
- name: Configure git
run: |
git config --global user.name cdrci
git config --global user.email opensource@coder.com
- name: Validate package
uses: heyhusen/archlinux-package-action@3f7aaada28c782497bfe02d6d6ea365b25fdea12 # v3.0.1
with:
pkgver: ${{ env.VERSION }}
updpkgsums: true
srcinfo: true
- name: Open PR
env:
GH_TOKEN: ${{ steps.app_token.outputs.token }}
run: |
git checkout -b "update-version-$VERSION"
git add .
git commit -m "Update to $VERSION"
git push -u origin "$(git branch --show)"
gh pr create \
--repo coder/code-server-aur \
--title "Update to $VERSION" \
--body "PR opened by @$GITHUB_ACTOR" \
--assignee "$GITHUB_ACTOR"
docker:
runs-on: ubuntu-latest
needs: verify
# Scopes the Docker Hub OIDC subject claim to
# repo:coder/code-server:environment:release.
environment: release
permissions:
# Required so GitHub can issue an OIDC token for the Docker Hub login,
# the release attestation and the coder-ghcr-dispatch token.
id-token: write
# Pushes to ghcr.io/coder/code-server-staging only; coder/ghcr-publisher
# alone can write ghcr.io/coder/code-server.
packages: write
# The release attestation coder/ghcr-publisher checks.
attestations: write
env:
GITHUB_TOKEN: ${{ github.token }}
TAG: ${{ inputs.version || github.ref_name }}
steps:
- name: Set version to tag without leading v
run: |
# TAG comes from the dispatch input, so only a version may reach GITHUB_ENV and the shell.
if [[ ! "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
echo "::error::The version must look like v1.2.3 or v1.2.3-rc.1."
exit 1
fi
echo "VERSION=${TAG#v}" >> "$GITHUB_ENV"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
# Authenticates to Docker Hub via OIDC (workload identity federation)
# instead of a stored username/password. Requires an OIDC connection
# configured for the org in Docker Home (Identity & auth > OIDC
# connections) and the `id-token: write` permission above.
- name: Login to Docker Hub with OIDC
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
username: codercom
env:
DOCKERHUB_OIDC_CONNECTIONID: ${{ vars.DOCKERHUB_OIDC_CONNECTIONID }}
# The Docker Hub token defaults to 5 minutes, and the multi-arch build pushes at the end,
# after about 10.
DOCKERHUB_OIDC_EXPIREIN: "3600"
- uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f # v1.13
with:
repository: "coder/code-server"
tag: v${{ env.VERSION }}
fileName: "*.deb"
out-file-path: "release-packages"
- uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f # v1.13
with:
repository: "coder/code-server"
tag: v${{ env.VERSION }}
fileName: "*.rpm"
out-file-path: "release-packages"
# Docker Hub gets the images directly. Only coder/ghcr-publisher can write
# ghcr.io/coder/code-server, so the GHCR copy goes to code-server-staging,
# and the publisher copies each image after verifying the release
# attestation below. The digests come from bake's record of its own
# push, never from a staging tag.
- name: Build and push images
env:
GITHUB_REGISTRY: ghcr.io/coder/code-server-staging
run: ./ci/steps/docker-buildx-push.sh --metadata-file "$RUNNER_TEMP/bake-metadata.json"
# One attestation for every image: this workflow, at this tag's commit,
# states the version and each image's public GHCR tags. The tags come
# from the same bake file with the public registry name, so they are
# exactly the tags this workflow pushed to GHCR before.
- name: Release attestation predicate
id: predicate
run: |
set -euo pipefail
commit="$(git rev-parse HEAD)"
if [[ "$commit" != "$GITHUB_SHA" ]]; then
echo "::error::checked out ${commit}, but this run is for ${GITHUB_SHA}"
exit 1
fi
GITHUB_REGISTRY=ghcr.io/coder/code-server \
docker buildx bake -f ci/release-image/docker-bake.hcl --print > "$RUNNER_TEMP/bake-print.json"
jq -n \
--slurpfile meta "$RUNNER_TEMP/bake-metadata.json" \
--slurpfile print "$RUNNER_TEMP/bake-print.json" \
--arg v "$VERSION" \
--arg c "$commit" '
$print[0].target as $targets
| {
version: $v,
commit: $c,
target: "ghcr.io/coder/code-server",
images: (
[ $meta[0] | to_entries[]
| select((.value | type) == "object" and (.value["containerimage.digest"] | type) == "string")
| { key: .value["containerimage.digest"],
value: [ $targets[.key].tags[]
| select(startswith("ghcr.io/coder/code-server:"))
| ltrimstr("ghcr.io/coder/code-server:") ] } ]
| from_entries)
}' > "$RUNNER_TEMP/predicate.json"
expected="$(jq '.group.default.targets | length' "$RUNNER_TEMP/bake-print.json")"
got="$(jq '[.images[] | select(length > 0)] | length' "$RUNNER_TEMP/predicate.json")"
if [[ "$got" != "$expected" ]]; then
echo "::error::expected ${expected} images with GHCR tags, got ${got}"
exit 1
fi
jq -r '.images | keys[] | ltrimstr("sha256:") + " ghcr.io/coder/code-server-staging"' \
"$RUNNER_TEMP/predicate.json" > "$RUNNER_TEMP/subjects.txt"
{
echo "predicate-path=$RUNNER_TEMP/predicate.json"
echo "subjects-path=$RUNNER_TEMP/subjects.txt"
echo "digests=$(jq -r '.images | keys | join(" ")' "$RUNNER_TEMP/predicate.json")"
} >> "$GITHUB_OUTPUT"
cat "$RUNNER_TEMP/predicate.json"
- name: Release attestation
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-checksums: ${{ steps.predicate.outputs.subjects-path }}
predicate-type: https://coder.com/attestations/code-server-release/v1
predicate-path: ${{ steps.predicate.outputs.predicate-path }}
# coder-ghcr-dispatch has only contents: write, on coder/ghcr-publisher
# only: enough for a repository_dispatch and nothing else. Its key is in
# Cloud KMS, signable only by this workflow in this environment.
- name: Generate coder-ghcr-dispatch token
id: dispatch_token
uses: coder/github-app-token-action@00eaec58ee1bfea9c8b48655b7ab7470b07739e5 # main 2026-11-17
with:
client-id: ${{ secrets.CODER_GHCR_DISPATCH_APP_ID }}
kms-key: ${{ secrets.CODER_GHCR_DISPATCH_APP_KMS_KEY }}
workload-identity-provider: ${{ secrets.APP_KEYS_WORKLOAD_ID_PROVIDER }}
owner: coder
repositories: ghcr-publisher
permissions: |
contents: write
skip-token-revoke: true
- name: Promote to ghcr.io/coder/code-server
env:
GH_TOKEN: ${{ steps.dispatch_token.outputs.token }}
DIGESTS: ${{ steps.predicate.outputs.digests }}
PREDICATE: ${{ steps.predicate.outputs.predicate-path }}
run: |
set -euo pipefail
# Anonymous reads: the package is public.
remote_digest() {
local repo="coder/code-server" token
token="$(curl -fsS "https://ghcr.io/token?scope=repository:${repo}:pull" | jq -r .token)"
curl -fsS -o /dev/null -D - -I \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.docker.distribution.manifest.v2+json" \
"https://ghcr.io/v2/${repo}/manifests/$1" |
tr -d '\r' | awk -F': ' 'tolower($1) == "docker-content-digest" {print $2}'
}
# The version tags, which never move. If one already exists (a
# re-run), the publisher keeps the earlier build of this release.
declare -A expected=() before=()
while read -r digest tag; do
expected["$tag"]="$digest"
if got="$(remote_digest "$tag" 2>/dev/null)" && [[ -n "$got" ]]; then
before["$tag"]="$got"
fi
done < <(jq -r --arg v "$VERSION" '.images | to_entries[] | .key as $d | .value[] | select(. == $v or startswith($v + "-")) | "\($d) \(.)"' "$PREDICATE")
gh api repos/coder/ghcr-publisher/dispatches \
-f event_type=promote-code-server \
-f "client_payload[version]=${VERSION}" \
-f "client_payload[digests]=${DIGESTS}"
gh api -X DELETE installation/token || echo "::warning::could not revoke the dispatch token; it expires within an hour"
unset GH_TOKEN
deadline=$((SECONDS + 1800))
while true; do
pending=()
for tag in "${!expected[@]}"; do
if ! got="$(remote_digest "$tag" 2>/dev/null)" || [[ -z "$got" ]]; then
pending+=("$tag")
continue
fi
if [[ "$got" != "${expected[$tag]}" && "$got" != "${before[$tag]:-}" ]]; then
echo "::error::ghcr.io/coder/code-server:${tag} is ${got}, expected ${expected[$tag]}"
exit 1
fi
done
if [[ ${#pending[@]} -eq 0 ]]; then
echo "All images are promoted."
break
fi
if ((SECONDS > deadline)); then
echo "::error::Promotion did not finish in 30 minutes; still waiting for: ${pending[*]}. Check https://github.com/coder/ghcr-publisher/actions/workflows/promote-code-server.yaml"
exit 1
fi
sleep 20
done
# The org doesn't let GITHUB_TOKEN open pull requests, so the branch is pushed and the PR opened
# as the coder-automations App (installed on coder/code-server; its key signs only for
# publish.yaml in the release environment).
repo:
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write # Cloud KMS signs the coder-automations App's JWT
env:
TAG: ${{ inputs.version || github.ref_name }}
needs: docker
steps:
- name: Set version to tag without leading v
run: |
# TAG comes from the dispatch input, so only a version may reach GITHUB_ENV and the shell.
if [[ ! "$TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
echo "::error::The version must look like v1.2.3 or v1.2.3-rc.1."
exit 1
fi
echo "VERSION=${TAG#v}" >> "$GITHUB_ENV"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- run: ./ci/build/update-repo.sh
# Minted after the update script so the token only exists for the push and the PR.
- name: Generate coder-automations app token
id: app_token
uses: coder/github-app-token-action@00eaec58ee1bfea9c8b48655b7ab7470b07739e5 # main 2026-11-17
with:
client-id: ${{ secrets.CODER_AUTOMATION_APP_ID }}
kms-key: ${{ secrets.CODER_AUTOMATION_APP_KMS_KEY }}
workload-identity-provider: ${{ secrets.APP_KEYS_WORKLOAD_ID_PROVIDER }}
owner: coder
repositories: code-server
permissions: |
contents: write
pull_requests: write
- name: Open PR
env:
GH_TOKEN: ${{ steps.app_token.outputs.token }}
run: |
gh auth setup-git
git config --global user.name cdrci
git config --global user.email opensource@coder.com
git checkout -b "helm/$VERSION"
git add .
git commit -m "Update Helm chart and changelog with $VERSION"
git push -u origin "$(git branch --show)"
gh pr create \
--repo coder/code-server \
--body-file .cache/checklist \
--title "Update Helm chart and changelog with $VERSION"