Skip to content

Commit

Permalink
Use cache for Docker Image File
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed May 20, 2022
1 parent 806c84f commit d90eebe
Showing 1 changed file with 68 additions and 7 deletions.
75 changes: 68 additions & 7 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ on:
- main
- release/**

env:
TAG: ostracon/e2e-node
CACHE_DIR: /tmp/ostracon/e2etest

jobs:
e2e-test:
e2e-build:
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
CACHE_FILE: ${{ steps.prep.outputs.CACHE_FILE }}
steps:
- uses: actions/setup-go@v3
with:
Expand All @@ -29,36 +35,91 @@ jobs:
go.sum
- name: Create cache directory
run: mkdir -p /tmp/.buildx-cache
run: |
mkdir -p /tmp/.buildx-cache
mkdir -p ${{ env.CACHE_DIR }}
- name: Prepare
id: prep
run: |
HASH_GHE=${{ github.sha }}
VARIANT=$(TZ=UTC-9 date '+%Y%m')${HASH_GHE:0:7}
NAME_TAR="${VARIANT}.tar"
CACHE_FILE=${{ env.CACHE_DIR }}"/${NAME_TAR}"
echo "::set-output name=CACHE_FILE::${CACHE_FILE}"
if: "env.GIT_DIFF != ''"

- name: Get Docker Image File from cache
id: cache
uses: actions/cache@v3
with:
path: ${{ env.CACHE_DIR }}
key: ${{ steps.prep.outputs.CACHE_FILE }}
if: "env.GIT_DIFF != ''"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
if: "env.GIT_DIFF != ''"
if: "env.GIT_DIFF != '' && steps.cache.outputs.cache-hit != 'true'"

- name: Load cached Docker layers
- name: Get cached Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
if: "env.GIT_DIFF != ''"
if: "env.GIT_DIFF != '' && steps.cache.outputs.cache-hit != 'true'"

- name: Build e2e Docker
uses: docker/build-push-action@v2
with:
context: .
file: ./test/e2e/docker/Dockerfile
tags: ostracon/e2e-node
tags: ${{ env.TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
load: true
if: "env.GIT_DIFF != ''"
if: "env.GIT_DIFF != '' && steps.cache.outputs.cache-hit != 'true'"

- name: Move cached Docker layers
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
if: "env.GIT_DIFF != '' && steps.cache.outputs.cache-hit != 'true'"

- name: Save Docker Image
run: |
docker save -o ${{ steps.prep.outputs.CACHE_FILE }} ${{ env.TAG }}
if: "env.GIT_DIFF != '' && steps.cache.outputs.cache-hit != 'true'"

e2e-test:
needs: e2e-build
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.15.4'

- uses: actions/checkout@v3

- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Get Docker Image File from cache
id: cache
uses: actions/cache@v3
with:
path: ${{ env.CACHE_DIR }}
key: ${{ needs.e2e-build.outputs.CACHE_FILE }}
if: "env.GIT_DIFF != ''"

- name: Load Docker Image on Docker
run: |
docker load -i ${{ needs.e2e-build.outputs.CACHE_FILE }}
if: "env.GIT_DIFF != ''"

- name: Build e2e runner
Expand Down

0 comments on commit d90eebe

Please sign in to comment.