Skip to content

Commit

Permalink
Share Client Docker Build Image in CI jobs
Browse files Browse the repository at this point in the history
We don't want to build the same image twice, we want to share it between
the jobs. This is a solution where the image is saved in the disk
storage and passed to another job.
This solution is based on docker/build-push-action#225 (comment)
  • Loading branch information
nkuba committed May 24, 2023
1 parent 791269a commit bdcbdc7
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ jobs:
load: true # load image to local registry to use it in next steps
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
outputs: type=docker,dest=/tmp/go-build-env-image.tar
context: .

- name: Upload Docker Build Image
uses: actions/upload-artifact@v3
with:
name: go-build-env-image
path: /tmp/go-build-env-image.tar

- name: Run Go tests
run: |
docker run \
Expand Down Expand Up @@ -268,45 +275,22 @@ jobs:
needs: client-build-test-publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
- name: Download Docker Build Image
uses: actions/download-artifact@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
name: go-build-env-image
path: /tmp/go-build-env-image.tar

- name: Build Docker Build Image
uses: docker/build-push-action@v3
with:
target: build-docker
tags: go-build-env
build-args: |
VERSION=${{ env.version }}
REVISION=${{ env.revision }}
load: true # load image to local registry to use it in next steps
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
- name: Load Docker Build Image
run: |
docker load --input /tmp/go-build-env-image.tar
- name: Run Go Integration Tests
run: |
docker run \
--workdir /go/src/github.com/keep-network/keep-core \
go-build-env \
gotestsum -- -tags=integration ./...
- # Temp fix - move cache instead of copying (added below step and
# modified value of `cache-to`).
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# Without the change some jobs were failing with `no space left on device`
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 comments on commit bdcbdc7

Please sign in to comment.