Skip to content

Commit

Permalink
Use container image cache (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal committed Sep 21, 2021
1 parent e4d563e commit 29eefe6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 36 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
go-version: "1.17"

- name: Check out paths
- name: Check out Go cache paths
id: go-cache-paths
run: |
echo "::set-output name=go-cache::$(go env GOCACHE)"
Expand All @@ -33,15 +33,15 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-cache }}
key: ${{ runner.os }}-go-cache-${{ hashFiles('go.sum') }}
key: ${{ runner.os }}-go-cache-${{ hashFiles('*.go', '**/*.go') }}
restore-keys: |
${{ runner.os }}-go-cache-
- name: Cache GOMODCACHE
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-mod-cache }}
key: ${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum') }}
key: ${{ runner.os }}-go-mod-cache-${{ hashFiles('go.sum', '**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-mod-cache-
Expand All @@ -65,12 +65,34 @@ jobs:
name: Image
timeout-minutes: 15
runs-on: "ubuntu-latest"
env:
IMAGE_CACHE_DIR: /tmp/image_cache
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Create cache directory
run: mkdir -p $IMAGE_CACHE_DIR

- name: Cache container images
uses: actions/cache@v2
with:
path: ${{ env.IMAGE_CACHE_DIR }}
key: ${{ runner.os }}-image-cache-${{ hashFiles('Dockerfile', 'go.sum', '**/go.sum', '*.go', '**/*.go') }}
restore-keys: |
${{ runner.os }}-image-cache-
- name: Load container image cache
run: |
ls -la $IMAGE_CACHE_DIR
for f in $(ls $IMAGE_CACHE_DIR/*.tar); do
docker load < $f
done
- name: Lint container image
run: make lint-image
run: |
make lint-image
docker save hadolint/hadolint > $IMAGE_CACHE_DIR/hadolint.tar
- name: Create cluster with Kind
run: kind create cluster
Expand All @@ -79,7 +101,16 @@ jobs:
run: make apply-manifests

- name: Build container image
run: make build-image
run: |
make build-image
docker save golang > $IMAGE_CACHE_DIR/golang.tar
docker save kubernetes-controller-template > $IMAGE_CACHE_DIR/kubernetes-controller-template.tar
danglings=$(docker images -q -f dangling=$TRUE_STR)
for id in $danglings; do
docker save $id > $IMAGE_CACHE_DIR/dangling_$id.tar
done
env:
TRUE_STR: "true"

- name: Start port forwarding for container registry
run: make port-forward &
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ clean:

build-image:
@docker build -t ${REPO}:${IMG_TAG} .
@docker image prune -f

lint-image:
@docker run --rm -i hadolint/hadolint < Dockerfile
Expand All @@ -74,6 +73,7 @@ push-image:

clean-image:
@docker rmi -f ${REPO}:${IMG_TAG} ${REGISTRY}/${REPO}:${IMG_TAG}
@docker image prune -f

apply-manifests:
@kubectl --context=kind-kind apply -f config/registry.yaml
Expand Down

0 comments on commit 29eefe6

Please sign in to comment.