From 9e06aa04b7a4eac5b3fc5e173d07e2bbd88788c0 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Fri, 10 Apr 2026 12:03:55 +0000 Subject: [PATCH] ci: push images to ghcr.io with new naming convention Add GHCR push support alongside existing Docker Hub push. New naming: ghcr.io/coder/$TAG:$IMAGE (e.g., ghcr.io/coder/ubuntu:base). Docker Hub images continue to be pushed for backwards compatibility. Closes #291 --- .github/workflows/build.yaml | 17 +++++++++++- README.md | 22 ++++++++++++++++ scripts/push_images.sh | 51 +++++++++++++++++++++++++----------- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 386e13f..48a8ddd 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,7 +31,7 @@ permissions: id-token: write deployments: none issues: none - packages: none + packages: write pull-requests: none repository-projects: none security-events: write @@ -87,3 +87,18 @@ jobs: run: | ${{ github.workspace }}/scripts/push_images.sh \ --tag=ubuntu + + - name: Authenticate to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push images to GHCR + if: github.event_name != 'pull_request' + run: | + ${{ github.workspace }}/scripts/push_images.sh \ + --tag=ubuntu \ + --registry=ghcr.io diff --git a/README.md b/README.md index 429d817..4ae3fc9 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,28 @@ under the `ubuntu` tag. > For backward compatibility, these images are also available with the `enterprise-` prefix > (e.g., `codercom/enterprise-base`), but the `example-` prefix is recommended for new deployments. +## Images on GHCR + +Images are also published to the GitHub Container Registry (GHCR) under a +distro-based naming convention: + +``` +ghcr.io/coder/: +``` + +For example: + +| Image | GHCR Reference | +| ------- | ------------------------------ | +| base | `ghcr.io/coder/ubuntu:base` | +| minimal | `ghcr.io/coder/ubuntu:minimal` | +| golang | `ghcr.io/coder/ubuntu:golang` | +| java | `ghcr.io/coder/ubuntu:java` | +| node | `ghcr.io/coder/ubuntu:node` | +| desktop | `ghcr.io/coder/ubuntu:desktop` | + +Date-tagged variants are also available (e.g., `ghcr.io/coder/ubuntu:base-20250410`). + ## Contributing See our [contributing guide](.github/CONTRIBUTING.md). diff --git a/scripts/push_images.sh b/scripts/push_images.sh index 5eed22a..2ba3b89 100755 --- a/scripts/push_images.sh +++ b/scripts/push_images.sh @@ -15,11 +15,12 @@ PROJECT_ROOT="$(git rev-parse --show-toplevel)" TAG="ubuntu" DRY_RUN=false QUIET=false +REGISTRY="dockerhub" function usage() { echo "Usage: $(basename "$0") [options]" echo - echo "This script pushes Coder's container images to Docker Hub." + echo "This script pushes Coder's container images to a registry." echo echo "Options:" echo " -h, --help Show this help text and exit" @@ -28,6 +29,8 @@ function usage() { echo " --tag= Select an image tag group to build," echo " e.g. ubuntu)" echo " --quiet Suppress container build output" + echo " --registry= Target registry: dockerhub (default)" + echo " or ghcr.io" exit 1 } @@ -39,7 +42,8 @@ options=$(getopt \ help, \ dry-run, \ tag:, \ - quiet" \ + quiet, \ + registry:" \ --options="h" \ -- "$@") # allow checking the exit code separately here, because we need both @@ -63,6 +67,10 @@ while true; do --quiet) QUIET=true ;; + --registry) + shift + REGISTRY="$1" + ;; -h|--help) usage ;; @@ -92,10 +100,6 @@ date_str=$(date --utc +%Y%m%d) for image in "${IMAGES[@]}"; do image_dir="$PROJECT_ROOT/images/$image" image_file="${TAG}.Dockerfile" - enterprise_image_ref="codercom/enterprise-$image:$TAG" - enterprise_image_ref_date="${enterprise_image_ref}-${date_str}" - example_image_ref="codercom/example-$image:$TAG" - example_image_ref_date="${example_image_ref}-${date_str}" image_path="$image_dir/$image_file" if [ ! -f "$image_path" ]; then @@ -106,14 +110,29 @@ for image in "${IMAGES[@]}"; do fi build_id=$(cat "build_${image}.json" | jq -r .\[\"depot.build\"\].buildID) - - # Push example images (primary) - run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$example_image_ref" "$build_id" - run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$example_image_ref_date" "$build_id" - run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "codercom/example-${image}:latest" "$build_id" - - # Push enterprise images (alias) - run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$enterprise_image_ref" "$build_id" - run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$enterprise_image_ref_date" "$build_id" - run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "codercom/enterprise-${image}:latest" "$build_id" + + if [ "$REGISTRY" = "ghcr.io" ]; then + # Push to GHCR with new naming: ghcr.io/coder/$TAG:$IMAGE + ghcr_ref="ghcr.io/coder/${TAG}:${image}" + ghcr_ref_date="ghcr.io/coder/${TAG}:${image}-${date_str}" + + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$ghcr_ref" "$build_id" + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$ghcr_ref_date" "$build_id" + else + # Push to Docker Hub (default, existing behavior) + enterprise_image_ref="codercom/enterprise-$image:$TAG" + enterprise_image_ref_date="${enterprise_image_ref}-${date_str}" + example_image_ref="codercom/example-$image:$TAG" + example_image_ref_date="${example_image_ref}-${date_str}" + + # Push example images (primary) + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$example_image_ref" "$build_id" + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$example_image_ref_date" "$build_id" + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "codercom/example-${image}:latest" "$build_id" + + # Push enterprise images (alias) + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$enterprise_image_ref" "$build_id" + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "$enterprise_image_ref_date" "$build_id" + run_trace $DRY_RUN depot push --project "gb3p8xrshk" --tag "codercom/enterprise-${image}:latest" "$build_id" + fi done