My dev container image grew too big to build locally, so I moved the build to GitHub Actions

Plenty of people now get their work done leaning on coding agents, and I am one of them. Each coding agent ships with its own sandbox feature. Start the agent through it and the agent can only touch files under the directory you point it at, which keeps it from wrecking the environment of the machine it runs on. I never quite managed to trust that feature, though, so I made a rule of always running coding agents inside a Docker container, and I wrote my own Emacs extension1 for that.

In the beginning it was a lightweight Docker image with nothing but the coding agent installed. But it is simply more convenient to have everything you need for development inside the image. I kept installing whatever came up, and the image grew into a dev container of respectable size. I had told myself that an all-in-one development container like a devcontainer is heresy as far as containers go and that I should keep it as small as possible, but convenience won in the end, and after a long detour I apparently arrived at a devcontainer anyway.

The trouble is that once the image got that big, building it locally became hard. Mostly there is no free storage. Recent tooling eats storage like nothing else2. So I decided to switch to building the Docker image somewhere remote and pulling it to use it.

The move comes down to two choices: where to build the image, and which container registry to store it in. I wanted something free that did not force me to make anything public, and GitHub offers both, so that is what I went with. Free within a quota, of course, but that is plenty for me.

I created one source repository on GitHub, set up the Dockerfile and a workflow under .github, made the build start manually, and made it push the image only when the build succeeds.

First, let the build be triggered by hand.

... omitted ...

on:
  workflow_dispatch:
    inputs:
      tag:
        description: "Image tag (e.g. 202611.dev1)"
        required: true
        default: dev
  push:
    tags:
      - "*"

... omitted ...
Excerpt from .github/workflows/build.yml

GitHub provides a container registry at ghcr.io, so I use it as is. Pushing to a repository in that registry requires the packages: write permission.

... omitted ...

permissions:
  contents: read
  packages: write

... omitted ...
Excerpt from .github/workflows/build.yml

My machine is a Mac with Apple Silicon, so the image has to be built for arm. GitHub Actions offers arm64 standard runners that private repositories can use within the free quota, so I use those.

... omitted ...

jobs:
  build:
    runs-on: ubuntu-24.04-arm
    steps:

... omitted ...
Excerpt from .github/workflows/build.yml

The actions provided by Docker handle everything from build to push.

... omitted ...
      - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

      - uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # Runners are disposable, so the layer cache lives in a buildcache tag on ghcr.io
      - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
        with:
          context: .
          platforms: linux/arm64
          push: true
          provenance: false
          tags: ${{ steps.image.outputs.name }}:${{ steps.image.outputs.tag }}
          cache-from: type=registry,ref=${{ steps.image.outputs.name }}:buildcache
          cache-to: type=registry,ref=${{ steps.image.outputs.name }}:buildcache,mode=max
... omitted ...
Excerpt from .github/workflows/build.yml

After a few retries, the built image started landing in the registry. This is what I will be using from now on.


1

That is agentic.el.

2

Models, for instance. And models. And package manager caches. And models.

Created