All jobs

Add hadolint to CI for Your Dockerfiles

Yes. An agent lints every Dockerfile with hadolint, fixes the findings worth fixing, writes down why the rest stay, and adds a path-filtered CI job.

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 starts by finding every Dockerfile and reading how the repository already runs CI. In a repository shaped like GoogleCloudPlatform/microservices-demo there are twelve of them, one per service under src/, with the C# one at src/cartservice/src/Dockerfile. skaffold.yaml lists the build contexts, so the agent knows which directory each Dockerfile builds from. .github/workflows/ci-pr.yaml runs Go and C# unit tests on ubuntu-24.04 with actions/checkout@v7, and the repository keeps one small path-filtered workflow per concern: kustomize-build-ci.yaml runs only when kustomize/** changes, terraform-validate-ci.yaml only for terraform/**, helm-chart-ci.yaml only for helm-chart/**. Nothing lints the Dockerfiles, and there is no .hadolint.yaml.

Next it runs hadolint on all twelve files in the sandbox and sorts the output by rule, because the fixes differ. On these files the warnings fall into a few groups. The four Python services (emailservice, loadgenerator, recommendationservice, shoppingassistantservice) copy requirements.txt to a relative destination before any WORKDIR is set (DL3045) and run pip install without --no-cache-dir (DL3042); both are safe mechanical fixes in the builder stage. The four Go services (checkoutservice, frontend, productcatalogservice, shippingservice) end with FROM gcr.io/distroless/static and no tag (DL3006), while every other base image in the repository is pinned to a digest, so the agent proposes a tag plus digest in the same style rather than silencing the rule. The Node and Python services on Alpine run apk add without versions (DL3018), and shoppingassistantservice runs apt-get install without versions (DL3008); pinning those breaks the next time the distribution drops an old package, so the agent writes them into .hadolint.yaml under ignored with a one-line reason. loadgenerator uses the shell form of ENTRYPOINT on purpose, because the command expands ${FRONTEND_ADDR}, ${USERS:-10} and ${RATE:-1} at start, so that one gets an inline # hadolint ignore=DL3025 comment above the line instead of a global ignore. adservice runs chmod +x gradlew and ./gradlew as separate RUN steps twice (DL3059, info level), which the agent either merges or leaves, since the config sets failure-threshold: warning. cartservice is clean.

Then it adds .github/workflows/hadolint-ci.yaml in the shape of the other filtered workflows: pull_request and push to main, paths limited to src/**/Dockerfile and the workflow file itself, permissions: contents: read, and one job that checks out the code and runs hadolint over the same twelve paths with the repository config. It also adds the new workflow to the paths-ignore list in ci-pr.yaml only if the maintainers want the test job to skip Dockerfile-only changes, and says so in the pull request rather than deciding alone.

Before opening the pull request it re-runs hadolint with the new config to confirm the exit code is zero, installs Docker, which the sandbox starts without (sudo apt-get install -y docker.io, then dockerd), and runs docker build for the Dockerfiles it edited, with the build context skaffold.yaml names, so a changed WORKDIR or a --no-cache-dir flag is shown not to break the image. The pull request description pastes the before and after hadolint output and lists each ignored rule with its reason.

Start it with one API call

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

{
  "agent": "claude",
  "input": "Add hadolint to CI for this repository and open a pull request. First find every Dockerfile (there is one per service under src/, including src/cartservice/src/Dockerfile) and read skaffold.yaml for their build contexts and .github/workflows/*.yaml for how CI is organised. Install hadolint in the sandbox and run it on every Dockerfile; paste the full output in your notes. Fix the mechanical findings in place: pip install without --no-cache-dir, COPY to a relative path before WORKDIR, and consecutive RUN steps that are trivially merged. For rules that pin apk or apt package versions, do not pin; add them to a new .hadolint.yaml under ignored with a one-line reason each, and set failure-threshold to warning. Where a shell-form ENTRYPOINT is needed for variable expansion, add an inline hadolint ignore comment above that line instead of a global ignore. For untagged base images, propose a tag plus digest in the same style as the other FROM lines and explain the choice. Add a path-filtered workflow .github/workflows/hadolint-ci.yaml that runs on pull_request and push to main only when a Dockerfile or the workflow changes, with contents: read permissions, and runs hadolint with the repository config over all Dockerfiles. Re-run hadolint to show a clean result, install Docker (sudo apt-get install -y docker.io, then start dockerd) and run docker build for every Dockerfile you edited using its skaffold context, and put the before and after output and the list of ignored rules with reasons in the pull request description. Change nothing else.",
  "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 with a new .hadolint.yaml, a new .github/workflows/hadolint-ci.yaml, and edits to the Dockerfiles that had mechanical findings: --no-cache-dir on the pip install lines and a WORKDIR before the first relative COPY in the Python builder stages, an inline ignore above the loadgenerator entrypoint, and tagged distroless images in the Go services if the maintainers accept that change. The description shows the hadolint output before and after, grouped by rule, and a table of every ignored rule with the reason the agent wrote into the config.

The new workflow runs on the pull request itself, since the pull request touches Dockerfiles, so the check appears beside the existing test job before anyone merges. Later pull requests that touch no Dockerfile do not run it, which matches how the kustomize, terraform and helm workflows already behave in this repository.

A reviewer checks three things: that every docker build the agent ran is in the trajectory and succeeded, that no apk or apt version was pinned, and that each reason in .hadolint.yaml is one they agree with. If they would rather fail only on errors, they change failure-threshold in one place.

Run it on every repository in your organization

This is the kind of change platform teams want in every repository and never get around to: a POST /o/{org}/sessions with this prompt and one repository in resources, sent from the terminal for each repository, one run per repository. Each run reads that repository's own Dockerfiles and CI layout, writes a config that matches its findings rather than a copied one, and opens its own pull request. The sandbox parks with its disk when the turn ends, so a follow-up such as also pin the distroless images by digest wakes it with hadolint installed and the images already built.

With a webhook_url on the API key, Rush posts run.completed or run.failed with the session_url for each run as it finishes, so the pull request links for twenty repositories collect in one handler instead of twenty tabs.

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

Why run it on Rush?

A linter is cheap to add and expensive to add well. The first run reports warnings that fall into very different buckets: a missing flag that is safe to fix, a version pin that would break the next build, and a shell-form entrypoint that is shell-form on purpose. Sorting those needs someone to read each Dockerfile, build the ones they change, and write down the decisions. The agent does that in its own sandbox, with hadolint's output, the build contexts from skaffold.yaml and the existing workflows in front of it, and every docker build it ran stays in the run's record for the reviewer.

Running it on Rush also means the proof is attached to the pull request rather than to a laptop. The trajectory shows the hadolint invocation, the config it converged on and the builds that passed, so the review is about whether the reasons are right, not whether the commands were run.

Frequently asked questions

Will it pin every apk and apt package version?

No. Pinning apk add nodejs or apt-get install g++ to a version breaks the build when the distribution repository drops that version, which Alpine does often. The agent ignores DL3018 and DL3008 in .hadolint.yaml with that reason, and notes that the base images in this repository are already pinned to a digest, which is what makes the build reproducible.

Why does it not convert the loadgenerator ENTRYPOINT to JSON form?

Because that line reads ${FRONTEND_ADDR}, ${USERS:-10} and ${RATE:-1} from the environment at container start, and the JSON form does not run a shell, so the variables would never expand. The agent adds # hadolint ignore=DL3025 above that one line instead of disabling the rule everywhere.

Does it change the existing CI workflow?

It adds a separate, path-filtered workflow in the same style as the kustomize, terraform and helm ones, and leaves ci-pr.yaml alone unless the maintainers want Dockerfile-only changes added to its paths-ignore list. That keeps the test job's behaviour unchanged and makes the new check easy to make required on its own.

What does it do with the untagged distroless images?

Hadolint flags FROM gcr.io/distroless/static with no tag as DL3006. The agent proposes a tag and a digest in the same image:tag@sha256:... style the other FROM lines use, and explains the choice in the pull request, so the maintainers can take the pin or ask for the rule to be ignored for those four files.

Does it need a Docker daemon?

Hadolint itself does not; it reads the files. A Rush sandbox starts without Docker, so the agent installs it with sudo apt-get install -y docker.io, starts dockerd and runs docker build on the Dockerfiles it edited, with the context skaffold.yaml gives for each service, so a changed WORKDIR or a new flag is shown to build. Those builds appear in the trajectory.

More Docker jobs

The same job on other stacks

More jobs like this: Hand off a long task

Keep reading