docker-build-cache-config-action icon indicating copy to clipboard operation
docker-build-cache-config-action copied to clipboard

Consider case of multiple image tags from branch

Open int128 opened this issue 1 year ago • 0 comments

Problem to solve

For some branch strategy, CI builds multiple image tags from a branch with a different build-args or arch. Here are the example cases.

Different arch

  • From main branch, it builds main-amd64 for amd64 architecture
  • From main branch, it builds main-arm64 for arm64 architecture

Different build-args

  • From main branch, it builds development with the build-args
  • From main branch, it builds staging with the build-args

How to solve

Different arch

Set an architecture to the suffix to separate the cache tags.

      - uses: int128/docker-build-cache-config-action@v1
        with:
          # e.g. main-arm64-cache
          flavor: suffix=-${{ inputs.arch }}-cache

This works as follows:

  • On push branch
    • Import and export the cache tag of main-arm64-cache
  • On pull_request
    • Import the cache tag of main-arm64-cache
  • On pull_request with pull-request-cache
    • Export the cache tag of pr-123-arm64-cache
    • Import the cache tag of pr-123-arm64-cache and main-arm64-cache
  • On other events
    • Import the cache tag of main-arm64-cache

Different build-args

      - uses: int128/docker-build-cache-config-action@v1
        with:
          flavor: |
            suffix=-${{ inputs.environment }}-cache
          always-cache-from-tags: main-development-cache

For example,

  • On push branch
    • If the environment is development,
      • Import and export the cache tag of main-development-cache
    • If the environment is staging,
      • Import and export the cache tag of main-staging-cache
  • On pull_request
    • Import the cache tag of main-development-cache
  • On pull_request with pull-request-cache
    • Export the cache tag of pr-123--cache
    • Import the cache tag of pr-123--cache and main-development-cache
  • On other events
    • Import the cache tag of main-development-cache

int128 avatar Nov 23 '23 06:11 int128