action.yml raw

   1  name: 'Configure Docker'
   2  description: 'Set up Docker build driver and configure build cache args'
   3  inputs:
   4    provider:
   5      description: 'The cache provider to use'
   6      required: false
   7      default: 'gha'
   8  runs:
   9    using: 'composite'
  10    steps:
  11      - name: Set up Docker Buildx for Warp cache
  12        if: ${{ inputs.provider == 'warp' }}
  13        uses: docker/setup-buildx-action@v4
  14        with:
  15          driver-opts: |
  16            network=host
  17  
  18      - name: Set up Docker Buildx
  19        if: ${{ inputs.provider != 'warp' }}
  20        uses: docker/setup-buildx-action@v4
  21  
  22      # This is required when using the gha cache backend with a manual docker buildx invocation.
  23      # Docker will check for variables $ACTIONS_CACHE_URL, $ACTIONS_RESULTS_URL and $ACTIONS_RUNTIME_TOKEN
  24      # which are set automatically when running on GitHub infra: https://docs.docker.com/build/cache/backends/gha/#synopsis
  25      - name: Expose actions cache variables
  26        uses: actions/github-script@v8
  27        with:
  28          script: |
  29            Object.keys(process.env).forEach(function (key) {
  30              if (key.startsWith('ACTIONS_')) {
  31                core.info(`Exporting ${key}`);
  32                core.exportVariable(key, process.env[key]);
  33              }
  34            });
  35  
  36      - name: Construct docker build cache args
  37        shell: bash
  38        run: |
  39          cache_options="scope=${CONTAINER_NAME}"
  40          if [[ "${{ inputs.provider }}" == "warp" ]]; then
  41            cache_options="url=http://127.0.0.1:49160/,version=1,${cache_options}"
  42          fi
  43  
  44          # Configure docker build cache backend
  45          # Always optimistically --cache‑from in case a cache blob exists
  46          args=(--cache-from "type=gha,${cache_options}")
  47  
  48          # Only add --cache-to when pushing to the default branch.
  49          if [[ ${{ github.event_name }} == "push" && ${{ github.ref_name }} == ${{ github.event.repository.default_branch }} ]]; then
  50            args+=(--cache-to "type=gha,mode=max,ignore-error=true,${cache_options}")
  51          fi
  52  
  53          # Always `--load` into docker images (needed when using the `docker-container` build driver).
  54          args+=(--load)
  55  
  56          echo "DOCKER_BUILD_CACHE_ARG=${args[*]}" >> $GITHUB_ENV
  57