Use caching in docker build
This commit is contained in:
parent
5a722d2bc1
commit
6698841a7d
|
@ -23,28 +23,29 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
|
||||
# Setup gcloud CLI
|
||||
- uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7
|
||||
# Login to GCR
|
||||
- name: Login to GCR
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
service_account_key: ${{ secrets.GCR_SA_KEY }}
|
||||
project_id: ${{ secrets.GCR_PROJECT }}
|
||||
registry: gcr.io
|
||||
username: _json_key
|
||||
password: ${{ secrets.GCR_SA_KEY }}
|
||||
|
||||
# Configure docker to use the gcloud command-line tool as a credential helper
|
||||
- run: |-
|
||||
gcloud --quiet auth configure-docker
|
||||
# Use docker buildx
|
||||
- name: Use docker buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
id: buildx
|
||||
with:
|
||||
install: true
|
||||
|
||||
# Build the Docker image
|
||||
- name: Build
|
||||
run: |-
|
||||
DOCKER_BUILDKIT=1 docker build \
|
||||
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
|
||||
--build-arg GITHUB_SHA="$GITHUB_SHA" \
|
||||
--build-arg GITHUB_REF="$GITHUB_REF" \
|
||||
.
|
||||
docker tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" "gcr.io/$PROJECT_ID/$IMAGE:latest"
|
||||
|
||||
# Push the Docker image to Google Container Registry
|
||||
- name: Publish
|
||||
run: |-
|
||||
docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
|
||||
docker push "gcr.io/$PROJECT_ID/$IMAGE:latest"
|
||||
# Build and push the image, leveraging layer caching
|
||||
- name: Build and Push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
|
||||
gcr.io/$PROJECT_ID/$IMAGE:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
|
Loading…
Reference in New Issue