-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build component using reusable workflow
Signed-off-by: Eduardo Apolinario <[email protected]>
- Loading branch information
1 parent
7e79c23
commit 35df30f
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Build Component 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: | ||
name: Build Docker Image | ||
runs-on: ubuntu-latest | ||
outputs: | ||
cache_key: ${{ steps.cache_key.outputs.cache_key }} | ||
defaults: | ||
run: | ||
working-directory: ${{ inputs.component }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- id: load-docker-cache | ||
name: Load Docker Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/tmp/docker-images | ||
key: /tmp/docker-images-${{ github.run_id }} | ||
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 }}/${{ github.event.repository.name }}:builder --target builder --cache-from=${{ github.repository_owner }}/${{ inputs.component }}:builder . | ||
docker build -t ${{ github.repository_owner }}/${{ inputs.component }}:latest --cache-from=${{ github.repository_owner }}/${{ inputs.component }}:builder . | ||
- name: Tag and cache docker image | ||
run: mkdir -p /tmp/tmp/docker-images && docker save ${{ github.repository_owner/${{ inputs.component }}:builder -o /tmp/tmp/docker-images/snapshot-builder.tar && docker save ${{ github.repository_owner/${{ inputs.component }}:latest -o /tmp/tmp/docker-images/snapshot.tar |