Skip to content

Commit

Permalink
Build component using reusable workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
eapolinario committed Sep 12, 2023
1 parent 7e79c23 commit 35df30f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/component_docker_build.yml
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

0 comments on commit 35df30f

Please sign in to comment.