|
| 1 | +name: 'Build docker image' |
| 2 | +description: 'Build docker image' |
| 3 | + |
| 4 | +inputs: |
| 5 | + context: |
| 6 | + description: 'Context argument' |
| 7 | + required: true |
| 8 | + file: |
| 9 | + description: 'Docker file' |
| 10 | + required: true |
| 11 | + cache_key_prefix: |
| 12 | + description: 'Cache key prefix' |
| 13 | + required: true |
| 14 | + |
| 15 | +runs: |
| 16 | + using: composite |
| 17 | + steps: |
| 18 | + # Attempt to speed up building of docker images for Linux-based binaries by |
| 19 | + # using docker's recommended way of building/caching with github actions. |
| 20 | + # Notably this caches layers to github actions which enables subsequent |
| 21 | + # reuse in future runs. The goal here is to make this step faster while |
| 22 | + # additionally reducing network flakiness since the github actions cache |
| 23 | + # generally works better than upstream package servers, or at least in |
| 24 | + # theory. |
| 25 | + # |
| 26 | + # The way that this is designed is to build the image with docker-related |
| 27 | + # github actions here primarily. This populates the github actions cache |
| 28 | + # but also the local docker daemon cache too. Subsequently when the actual |
| 29 | + # build script runs it'll attempt to rebuild the image and it should get a |
| 30 | + # bunch of cache hits from here. This way we can configure the caching here |
| 31 | + # within github actions without impacting the functionality of the script |
| 32 | + # itself and continue enabling it to run locally. |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@v4 |
| 35 | + |
| 36 | + - name: Disable some docker things that are on-by-default |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + echo DOCKER_BUILD_CHECKS_ANNOTATIONS=false >> $GITHUB_ENV |
| 40 | + echo DOCKER_BUILD_SUMMARY=false >> $GITHUB_ENV |
| 41 | + echo DOCKER_BUILD_RECORD_UPLOAD=false >> $GITHUB_ENV |
| 42 | +
|
| 43 | + - name: Setup Github Actions cache |
| 44 | + uses: actions/cache@v5 |
| 45 | + with: |
| 46 | + path: ${{ runner.tool_cache }}/docker-buildx-cache |
| 47 | + key: ${{ inputs.cache_key_prefix }}-${{ hashFiles(inputs.file) }} |
| 48 | + |
| 49 | + - name: Build docker image |
| 50 | + uses: docker/build-push-action@v7 |
| 51 | + with: |
| 52 | + context: ${{ inputs.context }} |
| 53 | + file: ${{ inputs.file }} |
| 54 | + tags: build-image |
| 55 | + cache-from: type=local,src=${{ runner.tool_cache }}/docker-buildx-cache |
| 56 | + cache-to: type=local,dest=${{ runner.tool_cache }}/docker-buildx-cache |
| 57 | + outputs: type=docker |
0 commit comments