Skip to content

Commit

Permalink
imp #12: added a cache step for docker+go
Browse files Browse the repository at this point in the history
  • Loading branch information
donkeyx committed Sep 23, 2023
1 parent 3ea32d2 commit 3bf5de1
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,40 @@ on:
- "v*"

jobs:
build:
cache:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Cache Go packages and Docker layers
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
/tmp/.buildx-cache
key: go-docker-${{ runner.os }}-${{ hashFiles('**/*.go') }}
restore-keys: |
go-docker-${{ runner.os }}-
build:
needs: cache
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v2

- name: Cache Go packages
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Cache Go packages (reuse cache from 'cache' job)
uses: actions/cache@v2
with:
path: |
Expand All @@ -28,19 +49,8 @@ jobs:
restore-keys: |
go-${{ runner.os }}-
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: |
/tmp/.buildx-cache
key: docker-${{ runner.os }}-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
docker-${{ runner.os }}-
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker meta
id: meta
Expand All @@ -53,12 +63,6 @@ jobs:
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GHCR
uses: docker/login-action@v2
with:
Expand Down Expand Up @@ -90,4 +94,4 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: docker.io/donkeyx/cluster-utils-api:${{ steps.meta.outputs.tags }}
tags: docker.io/yourusername/your-image-name:{{ steps.meta.outputs.tags }}

0 comments on commit 3bf5de1

Please sign in to comment.