All jobs

Add a GitHub Actions Workflow That Builds a Docker Image and Pushes It to GHCR

Yes. An agent reads your Dockerfile, adds a workflow that tests, builds for amd64 and arm64 and pushes tagged images to GitHub Container Registry, then opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads how the image is built before writing a workflow around it. In an app like miguelgrinberg/microblog, Dockerfile starts FROM python:slim with no version tag, copies requirements.txt, runs pip install -r requirements.txt and a second pip install gunicorn pymysql cryptography with no pins, copies app, migrations, microblog.py, config.py and boot.sh, sets ENV FLASK_APP microblog.py in the legacy space-separated form, runs flask translate compile to build the Spanish .mo file from app/translations/es/LC_MESSAGES/messages.po, exposes port 5000 and uses boot.sh as the entrypoint. boot.sh retries flask db upgrade every five seconds until it succeeds and then runs gunicorn -b :5000 --access-logfile - --error-logfile - microblog:app. requirements.txt already pins Flask==3.0.0, gunicorn==21.2.0, Flask-SQLAlchemy==3.1.1, elasticsearch==8.11.0, redis==5.0.1 and rq==1.15.1, so the unpinned second pip install reinstalls gunicorn unpinned over the pinned one.

It also reads what surrounds the Dockerfile. There is no .github directory and no .dockerignore, so a build context includes .git, the venv directory .gitignore names, app.db and the Vagrantfile. tests.py is a unittest suite (UserModelCase with password hashing, avatar, follow and feed tests) that runs with python tests.py against an in-memory SQLite database with ELASTICSEARCH_URL = None, so it needs no services. config.py reads SECRET_KEY, DATABASE_URL, REDIS_URL, ELASTICSEARCH_URL and the mail settings from the environment, which means the image can be built without any of them.

The agent writes .github/workflows/docker-publish.yml. A test job sets up Python, installs requirements.txt and runs python tests.py. A build job that needs it runs docker/setup-qemu-action, docker/setup-buildx-action, docker/login-action against ghcr.io with github.actor and secrets.GITHUB_TOKEN, docker/metadata-action with images: ghcr.io/${{ github.repository }} and tags for the branch, the short SHA and semver patterns on v* tags, then docker/build-push-action with platforms: linux/amd64,linux/arm64, cache-from: type=gha, cache-to: type=gha,mode=max and push: ${{ github.event_name != 'pull_request' }}, so pull requests build but never publish. The workflow declares permissions: contents: read, packages: write and triggers on push to main, push of v* tags and pull_request.

It also makes the two Dockerfile changes the build exposes: ENV FLASK_APP=microblog.py in the current form, and FROM python:slim pinned to a specific 3.x-slim tag, naming in the pull request the tag the sandbox build used and why. It adds a .dockerignore with .git, venv, app.db, *.log, __pycache__, tests.py and Vagrantfile. The sandbox has no Docker, so the agent installs it (sudo apt-get install -y docker.io, then starts dockerd) and runs docker build . for the sandbox's own architecture to confirm the Dockerfile builds; the arm64 build happens only on the GitHub runner through QEMU, and the pull request says so rather than claiming it was tested.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add a GitHub Actions workflow that publishes this repository's Docker image to GitHub Container Registry. Read the Dockerfile, the entrypoint script and the test suite first. The workflow must run the tests, then build for linux/amd64 and linux/arm64 with buildx and QEMU, tag images from the branch, the commit SHA and semver git tags with docker/metadata-action, use the GitHub Actions cache, and push only on pushes to the default branch and version tags, never on pull requests, using the GITHUB_TOKEN with packages write permission. Add a .dockerignore. Fix only what the build exposes in the Dockerfile, such as an unpinned base image or deprecated syntax, and explain each change. Build the image once in your sandbox to confirm the Dockerfile works and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds .github/workflows/docker-publish.yml and .dockerignore and changes Dockerfile in two lines. The description explains the tag scheme with examples (main, sha-<short>, 1.2.3 and 1.2 from a v1.2.3 tag), says which base tag replaced python:slim and why, lists what the .dockerignore excludes, and quotes the docker build output from the sandbox for the one architecture it could build.

The run's record keeps every command with its output, including the Docker installation in the sandbox, the build log and the python tests.py run, so a reviewer can see the Dockerfile builds and the tests pass before the workflow runs on GitHub for the first time.

Before merging, a reviewer checks the package visibility they want on GHCR (a first push creates a private package tied to the repository), confirms the base image tag choice, and decides whether the test job should also run flask translate compile to catch a broken .po file before the image build does.

Run it on every new repository

Each new service repository in your organisation can get its publish workflow with one POST /o/{org}/sessions carrying this body and that repository in resources. Started from a terminal, the run continues in its sandbox after you close the window and the sandbox parks when the turn ends, so a follow-up (POST /o/{org}/sessions/{id}/messages) can add a second registry or a different tag scheme without starting over.

A webhook on the API key reports run.completed with the session_url to read the pull request link, so a script that creates repositories can start the run and move on.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A publish workflow is mostly conventions, and the mistakes are in the details the Dockerfile dictates: an unpinned base image that changes under you, a build context with the whole .git directory in it, a pull request that accidentally pushes a tag. The agent reads the Dockerfile, the entrypoint and the tests first, and the workflow it writes matches how this image is actually built and tested.

The sandbox is a real Linux computer where the agent installs Docker and builds the image, and the build log stays in the run's record. The pull request arrives with that evidence rather than a workflow that fails on its first run. Several repositories can be done at once, each in its own sandbox.

Frequently asked questions

Will pull requests push images?

No. The build step's push input is github.event_name != 'pull_request', so a pull request builds both platforms to prove the Dockerfile works but publishes nothing. Only pushes to the default branch and version tags push.

How are the images tagged?

By docker/metadata-action: the branch name on branch pushes, sha- plus the short commit SHA on every push, and semver tags from git tags, so v1.2.3 produces 1.2.3, 1.2 and latest. The pull request lists the exact patterns so you can trim them.

Why did it change my Dockerfile?

Only where the build exposed a problem: ENV key value is a deprecated form that BuildKit warns about, and an untagged python:slim means the image's Python version changes whenever the upstream tag moves. Each change is one line, explained in the pull request, and easy to revert if you disagree.

Can it push to Docker Hub or another registry instead?

Yes. Say which registry in the prompt; the login step and the images list change, and the credentials become repository secrets you add. GHCR is the default because the GITHUB_TOKEN already works there with no secret to create.

More Docker jobs

More jobs like this: Hand off a long task

Keep reading