Rabi Siddique
258 words
1 minutes
ARG in Dockerfile

Today started by reading Brendon’s messages. Brendon inquired about the Liquidation testing in the CI pipeline, specifically concerned about which Docker image was used when running our tests in CI.

Brendon's Image

Recently, we created a new Docker image for the Agoric SDK and were testing with it, but it had not yet become the latest image. So there was a problem: to test against this new SDK image in CI, we had to manually update the SDK image tag in the Dockerfile by making a pull request(PR) and then continue with running the tests. This was not ideal.

I suggested to Brendon that I can explore automating this process. After some Googling and consulting ChatGPT, I discovered the ARG keyword in Dockerfiles. Using the ARG keyword, we can pass build-time arguments to the Dockerfile, which provides great flexibility and solves our problem.

I introduced an ARG in the Dockerfile to specify the image tag dynamically.

Before:

FROM ghcr.io/agoric/agoric-sdk:latest

After:

ARG BASE_IMAGE_TAG
FROM ghcr.io/agoric/agoric-sdk:${BASE_IMAGE_TAG}

I also made the following changes to the Docker Compose file:

Before:

version: '3.9'

services:
  synpress:
    profiles:
      - synpress
      - daily-tests
    container_name: synpress
    build: ../..

After:

version: '3.9'

services:
  synpress:
    profiles:
      - synpress
      - daily-tests
    container_name: synpress
    build:
      context: ../..
      args:
        BASE_IMAGE_TAG: ${BASE_IMAGE_TAG_INPUT}

The context can be used to specify the location of a Dockefile or URL to a git repo. While args define build arguments.

After making these changes, I need to update the yml files for GitHub Actions to accept user input for the tag and then pass it to the Docker Compose file. The final output was:

GitHub-Actions

You can see my PR to view the complete code.

ARG in Dockerfile
https://rabisiddique.com/posts/docker-arg/
Author
Rabi Siddique
Published at
2024-07-11