Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 166 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name: Build
# (v1.2.3 -> latest, 1.2.3, 1.2, 1, sha-*); prereleases do not update latest
# - a weekly run rebuilds `latest` against the newest Codex release
# - pull requests run the checks and BUILD the image (nothing is pushed)
# Both architectures use the same resolved Codex release and are built and
# smoke-tested on native runners before publishing multi-platform tags.
# Images go to GitHub's own registry (GHCR) with the built-in GITHUB_TOKEN.

on:
Expand All @@ -27,8 +29,10 @@ on:

jobs:
quality:
name: Check scripts
name: Check scripts and resolve release
runs-on: ubuntu-latest
outputs:
codex-version: ${{ steps.codex.outputs.version }}
permissions:
contents: read

Expand All @@ -41,20 +45,9 @@ jobs:
for f in *.sh; do bash -n "$f"; done
python3 -m py_compile codex-rc-status.py

docker:
name: Build and push image
needs: quality
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v7

# Same resolution as build.sh: with CODEX_VERSION=latest the install
# layer's cache key never moves, so pass the real release.
# layer's cache key never moves, so pass the real release. Resolve once
# so both architectures contain the same version even during a release.
- name: Resolve the Codex release
id: codex
run: |
Expand All @@ -65,36 +58,139 @@ jobs:
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Codex $version"

- name: Set up QEMU
uses: docker/setup-qemu-action@v4
docker:
name: Build and test (${{ matrix.arch }})
needs: quality
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,enable=${{ github.event_name != 'schedule' }}

- name: Build smoke-test image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
platforms: linux/${{ matrix.arch }}
load: true
tags: codex-remote:smoke
build-args: CODEX_VERSION=${{ steps.codex.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.meta.outputs.labels }}
build-args: CODEX_VERSION=${{ needs.quality.outputs.codex-version }}
cache-from: type=gha,scope=image-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=image-${{ matrix.arch }}

# The entrypoint needs a signed-in ChatGPT account, so check the
# toolbox the image promises instead of starting the supervisor.
- name: Smoke-test image
env:
EXPECTED_CODEX_VERSION: ${{ needs.quality.outputs.codex-version }}
run: |
docker run --rm --entrypoint bash codex-remote:smoke -ec '
codex --version
docker run --rm --platform linux/${{ matrix.arch }} \
--env EXPECTED_ARCH=${{ matrix.arch }} \
--env EXPECTED_CODEX_VERSION \
--entrypoint bash codex-remote:smoke -ec '
test "$(dpkg --print-architecture)" = "$EXPECTED_ARCH"
version=$(codex --version)
printf "%s\n" "$version"
test "$version" = "codex-cli $EXPECTED_CODEX_VERSION"
docker --version
docker compose version
docker buildx version
git --version
node --version
npm --version
python3 --version
sqlite3 --version
for f in entrypoint.sh healthcheck.sh codex-login codex-pair codex-rc-status; do
test -x "/usr/local/bin/$f"
done
'

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Reuse the tested build's release, cached layers and labels. Push by
# digest so a single architecture cannot replace a shared image tag.
- name: Push tested image by digest
id: push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/${{ matrix.arch }}
labels: ${{ steps.meta.outputs.labels }}
build-args: CODEX_VERSION=${{ needs.quality.outputs.codex-version }}
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
if: github.event_name != 'pull_request'
env:
IMAGE_DIGEST: ${{ steps.push.outputs.digest }}
run: |
mkdir -p "$RUNNER_TEMP/digests"
printf '%s\n' "$IMAGE_DIGEST" > "$RUNNER_TEMP/digests/${{ matrix.arch }}"

- name: Upload digest
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v7
with:
name: digest-${{ matrix.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

publish:
name: Publish multi-platform image
needs: docker
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Download digests
uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/digests
pattern: digest-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v6
Expand All @@ -108,21 +204,57 @@ jobs:
type=sha,enable=${{ github.event_name != 'schedule' }}

- name: Login 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: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: CODEX_VERSION=${{ steps.codex.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Publish manifest
working-directory: ${{ runner.temp }}/digests
env:
IMAGE: ghcr.io/${{ github.repository }}
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
sources=()
for arch in amd64 arm64; do
digest=$(cat "$arch")
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
sources+=("$IMAGE@$digest")
done
tags=()
while IFS= read -r tag; do
tags+=(--tag "$tag")
done <<< "$IMAGE_TAGS"
docker buildx imagetools create "${tags[@]}" "${sources[@]}"

- name: Inspect published image
env:
IMAGE: ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
run: |
docker buildx imagetools inspect "$IMAGE"
docker buildx imagetools inspect "$IMAGE" --raw | jq -e '
[.manifests[].platform | select(.os == "linux") | .architecture]
| sort == ["amd64", "arm64"]
'

- name: Verify public image access
env:
IMAGE_PATH: ${{ github.repository }}
IMAGE_TAG: ${{ steps.meta.outputs.version }}
run: |
# Request an anonymous pull token without Docker credentials or GITHUB_TOKEN.
if ! token=$(curl --disable --fail --silent --show-error --get \
--data-urlencode 'service=ghcr.io' \
--data-urlencode "scope=repository:$IMAGE_PATH:pull" \
https://ghcr.io/token | jq -er '.token // .access_token'); then
echo "::error::Cannot pull ghcr.io/$IMAGE_PATH anonymously. Set the package visibility to Public in GitHub Package settings."
exit 1
fi
curl --disable --fail --silent --show-error \
--header "Authorization: Bearer $token" \
--header 'Accept: application/vnd.oci.image.index.v1+json' \
"https://ghcr.io/v2/$IMAGE_PATH/manifests/$IMAGE_TAG" | jq -e '
[.manifests[].platform | select(.os == "linux") | .architecture]
| sort == ["amd64", "arm64"]
'
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ ones are pruned).

## The image

CI publishes the image to the GitHub Container Registry for linux/amd64 and
linux/arm64, built against the newest Codex release, once the script checks,
the build-time schema assertion and a smoke test of the built image pass:
CI publishes the image to the GitHub Container Registry for **linux/amd64**
(x86-64) and **linux/arm64** (AArch64). Each architecture is built and
smoke-tested on a native runner using the same resolved Codex release.
Shared tags are published only after both builds pass the remote-control
schema assertion and smoke checks for the CPU architecture, Codex version,
Docker CLI and plugins, Git, Node.js, Python, SQLite and helper scripts:

| Tag | Points at |
|---|---|
Expand All @@ -296,7 +299,22 @@ the build-time schema assertion and a smoke test of the built image pass:
| `1.2.3`, `1.2`, `1` | the release tag `v1.2.3` |

`compose.yaml` pulls `ghcr.io/markfrancisonly/codex-remote`, tagged by
`DOCKER_CODEX_IMAGE_TAG` in `.env` (default `latest`).
`DOCKER_CODEX_IMAGE_TAG` in `.env` (default `latest`). Docker automatically
selects the matching architecture, so ARM64 hosts use the same Compose file
and tags without a `platform` override. A 64-bit OS is required; 32-bit ARM
(`arm/v7`) is not supported.

The GHCR package must be **Public** so these pulls work without a GitHub
login. After the first publication, the maintainer must select **Public**
under **Package settings → Change visibility**; a public repository does
not make its container package public automatically. See
[GitHub's package visibility instructions](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#configuring-visibility-of-packages-for-your-personal-account).
CI checks anonymous access to the published manifest and fails if the image
cannot be pulled publicly. After changing visibility, rerun the failed job.

For local builds, run `./build.sh` on either supported architecture. Ubuntu
packages and the standalone Codex installer select the matching binaries;
the schema assertion runs for that architecture before the image is ready.

## Applying config changes from inside a session

Expand Down
Loading