Skip to content

uprade actions/checkout #1

uprade actions/checkout

uprade actions/checkout #1

name: Build Docker Image
on:
workflow_call:
inputs:
component:
required: true
type: string
outputs:
cache_key:
description: "Docker Cache key"
value: ${{ jobs.build_docker.outputs.cache_key }}
jobs:
build_docker:
runs-on: ubuntu-latest
outputs:
cache_key: ${{ steps.cache_key.outputs.cache_key }}
steps:
- name: Checkout
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- id: load-docker-cache
name: Load Docker Cache
uses: actions/cache@v3
with:
path: /tmp/tmp/docker-images-${{ inputs.component }}
key: /tmp/docker-images-${{ github.run_id }}-${{ inputs.component }}
restore-keys: |
/tmp/docker-images-
- name: Set cache key output
id: cache_key
run: |
echo ::set-output name=cache_key::/tmp/docker-images-${{ github.run_id }}
- name: Prime docker cache
run: (docker load -i /tmp/tmp/docker-images/snapshot-builder.tar || true) && (docker load -i /tmp/tmp/docker-images/snapshot.tar || true)
- name: Build dockerfile
env:
# We are unable to leverage docker buildx here without changing the
# caching mechanism significantly. See here for the caching options
# available for docker buildx: https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-from
# For now at least enable DOCKER_BUILDKIT for faster builds. Eventually we
# should rewrite this pipeline to use docker buildx with cache type=gha.
DOCKER_BUILDKIT: "1"
run: |
docker build -t ${{ github.repository_owner }}/${{ inputs.component }}:builder --target builder --cache-from=${{ github.repository_owner }}/${{ inputs.component }}:builder --file Dockerfile.${{ inputs.component }} .
docker build -t ${{ github.repository_owner }}/${{ inputs.component }}:latest --cache-from=${{ github.repository_owner }}/${{ inputs.component }}:builder --file Dockerfile.${{ inputs.component }} .
- name: Tag and cache docker image
run: |
mkdir -p /tmp/tmp/docker-images-${{ inputs.component }} && docker save ${{ github.repository_owner }}/${{ inputs.component }}:builder -o /tmp/tmp/docker-images-${{ inputs.component }}/snapshot-builder-${{ inputs.component }}.tar && docker save ${{ github.repository_owner }}/${{ inputs.component }}:latest -o /tmp/tmp/docker-images-${{ inputs.component }}/snapshot-${{ inputs.component }}.tar