Skip to content

Instantly share code, notes, and snippets.

@johnxy84
Created June 3, 2021 12:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnxy84/1238a7d1b0e3c4ab74e8ff4103063480 to your computer and use it in GitHub Desktop.
Save johnxy84/1238a7d1b0e3c4ab74e8ff4103063480 to your computer and use it in GitHub Desktop.
name: Docker Build With Cache
on:
push:
branches:
- main
env:
IMAGE_NAME: imagename:latest
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout'
uses: actions/checkout@v2
- name: Docker Login
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
# Use Github Actions' cache
- name: Setup Docker layers cache
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Build And Push
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: ./Dockerfile
push: true
tags: ${{ env.IMAGE_NAME }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp Solution
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment