Use BuildX's cache mount for caching.

This commit is contained in:
Kavin 2022-03-04 19:31:27 +00:00
parent 779777b9b6
commit e44f1e55b7
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 4 additions and 12 deletions

View file

@ -26,15 +26,6 @@ jobs:
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get hash of latest image
run: docker pull golang:alpine && docker inspect --format='{{index .RepoDigests 0}}' golang:alpine > dockerhash.txt
- name: cache docker cache
uses: actions/cache@v2.1.2
with:
path: ${{ github.workspace }}/cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/dockerhash.txt') }}
restore-keys: |
${{ runner.os }}-docker-
- name: Build and push - name: Build and push
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
@ -43,5 +34,5 @@ jobs:
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
push: true push: true
tags: 1337kavin/ytproxy:latest tags: 1337kavin/ytproxy:latest
cache-from: type=local,src=cache cache-from: type=gha
cache-to: type=local,dest=cache cache-to: type=gha,mode=max

View file

@ -4,7 +4,8 @@ WORKDIR /app/
COPY . . COPY . .
RUN go build -ldflags "-s -w" main.go RUN --mount=type=cache,target=/root/.cache/go-build \
go build -ldflags "-s -w" main.go
FROM alpine:edge FROM alpine:edge