Skip to content

Commit

Permalink
optimize(e2e): cache docker layers
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone committed Dec 28, 2022
1 parent f927ed3 commit acbc614
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
pr_num: ${{ steps.parser.outputs.pr_num }}
image_tag: "pr-${{ steps.parser.outputs.pr_num }}-${{ steps.parser.outputs.commit_sha }}"
commit_sha: ${{ steps.parser.outputs.commit_sha }}
version_buildflags: ${{ steps.parser.outputs.version_buildflags }}
go_code_hash: ${{ steps.parser.outputs.go_code_hash }}

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -51,6 +53,13 @@ jobs:
gh pr checkout $PR_NUM
SHA=$(git log -n 1 --pretty=format:"%H")
echo "::set-output name=commit_sha::$SHA"
GIT_COMMIT=$(git describe --match=NeVeRmAtCh --tags --always --dirty | cut -c 1-7)
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
VERSION=$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/v\(\)/\1/')
PKG=github.com/bentoml/yatai-deployment
VERSION_BUILDFLAGS="-X '$(PKG)/version.GitCommit=$(GIT_COMMIT)' -X '$(PKG)/version.Version=$(VERSION)' -X '$(PKG)/version.BuildDate=$(BUILD_DATE)'"
echo "::set-output name=version_buildflags::$VERSION_BUILDFLAGS"
echo "::set-output name=go_code_hash::${{ hashFiles('main.go', './apis/**', './controllers/**', './utils/**', './version/**', './yatai-client/**', '**/go.sum', '**go.mod') }}"
build-test-images:
needs: triage
Expand Down Expand Up @@ -78,6 +87,23 @@ jobs:
run: |
gh pr checkout ${{ needs.triage.outputs.pr_num }}
- name: Set up Docker Buildx
id: buildx
# Use the action from the master, as we've seen some inconsistencies with @v1
# Issue: https://github.com/docker/build-push-action/issues/286
uses: docker/setup-buildx-action@master
with:
install: true

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
# Key is named differently to avoid collision
key: ${{ runner.os }}-multi-buildx-${{ needs.triage.outputs.go_code_hash }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Login to Quay.io
uses: docker/login-action@v1
with:
Expand All @@ -86,9 +112,22 @@ jobs:
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: Build test image
env:
IMG: quay.io/bentoml/test-yatai-deployment:${{ needs.triage.outputs.image_tag }}
run: make docker-build docker-push
uses: docker/build-push-action@v2
with:
build-args: 'VERSION_BUILDFLAGS="$${{ needs.triage.outputs.version_buildflags }}"'
context: .
push: true
tags: quay.io/bentoml/test-yatai-deployment:${{ needs.triage.outputs.image_tag }}
cache-from: type=local,src=/tmp/.buildx-cache
# Note the mode=max here
# More: https://github.com/moby/buildkit#--export-cache-options
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
run-test:
needs: [triage, build-test-images]
Expand Down

0 comments on commit acbc614

Please sign in to comment.