Skip to content

Commit

Permalink
Merge pull request #3 from didil/2-docker-build-caching
Browse files Browse the repository at this point in the history
Add build caching
  • Loading branch information
didil authored Feb 24, 2023
2 parents 385c843 + 11b5462 commit 8c98cd9
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,39 @@ jobs:
build_app:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/checkout@v3

- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- name: Build
run: GOFLAGS=-v make build

- name: Test
run: GOFLAGS=-v make test


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

- name: Build and push
- name: Build / Push
uses: docker/build-push-action@v4
with:
push: true
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
push: ${{ github.ref == 'ref/heads/main' }}
platforms: linux/amd64,linux/arm64
tags: ${{ vars.DOCKER_IMAGE_NAME }}:${{ steps.set_output_vars.outputs.short_sha }}

0 comments on commit 8c98cd9

Please sign in to comment.