Skip to content

Commit 8c98cd9

Browse files
authored
Merge pull request #3 from didil/2-docker-build-caching
Add build caching
2 parents 385c843 + 11b5462 commit 8c98cd9

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

.github/workflows/ci.yaml

+25-6
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,39 @@ jobs:
66
build_app:
77
runs-on: ubuntu-22.04
88
steps:
9-
- uses: actions/checkout@v3
10-
119
- name: Set up Go
1210
uses: actions/setup-go@v3
1311
with:
1412
go-version: 1.19
1513

14+
- id: go-cache-paths
15+
run: |
16+
echo "::set-output name=go-build::$(go env GOCACHE)"
17+
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
18+
19+
- uses: actions/checkout@v3
20+
21+
- name: Go Build Cache
22+
uses: actions/cache@v3
23+
with:
24+
path: ${{ steps.go-cache-paths.outputs.go-build }}
25+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
26+
27+
- name: Go Mod Cache
28+
uses: actions/cache@v3
29+
with:
30+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
31+
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
32+
1633
- name: Build
1734
run: GOFLAGS=-v make build
1835

1936
- name: Test
2037
run: GOFLAGS=-v make test
2138

2239

23-
publish_container_image:
40+
build_container_image:
2441
needs: build_app
25-
if: github.ref == 'refs/heads/main'
2642
runs-on: ubuntu-22.04
2743
steps:
2844
- uses: actions/checkout@v3
@@ -46,9 +62,12 @@ jobs:
4662
id: set_output_vars
4763
run: echo "short_sha=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
4864

49-
- name: Build and push
65+
- name: Build / Push
5066
uses: docker/build-push-action@v4
5167
with:
52-
push: true
68+
context: .
69+
cache-from: type=gha
70+
cache-to: type=gha,mode=max
71+
push: ${{ github.ref == 'ref/heads/main' }}
5372
platforms: linux/amd64,linux/arm64
5473
tags: ${{ vars.DOCKER_IMAGE_NAME }}:${{ steps.set_output_vars.outputs.short_sha }}

0 commit comments

Comments
 (0)