Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docker Build: Adopt Google Artifact Registry and enable registry caching. #22

Merged
merged 19 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/actions/deploy-cloud-run/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ inputs:
credentials_json:
description: 'Google Cloud Service Account JSON'
required: true
gcr_hostname:
description: 'Google Cloud Run Docker Repository'
artifact_registry:
description: 'Artifact Registry'
required: false
default: gcr.io
default: us-central1-docker.pkg.dev

runs:
using: 'composite'
Expand All @@ -32,7 +32,7 @@ runs:
- name: gcloud run deploy
run: |
gcloud run deploy ${{ inputs.service_name }} \
--image ${{ inputs.gcr_hostname }}/${{ inputs.project_id }}/${{ inputs.service_name }}:${{ github.sha }} \
--image ${{ inputs.artifact_registry }}/${{ inputs.project_id }}/docker-registry/${{ inputs.service_name }}:${{ github.sha }} \
--platform managed \
--region us-central1 \
--quiet
Expand Down
16 changes: 9 additions & 7 deletions .github/actions/dockerize/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ inputs:
credentials_json:
description: 'Google Cloud Service Account JSON'
required: true
gcr_hostname:
description: 'Google Cloud Run Docker Repository'
required: false
default: gcr.io
dockerfile:
description: 'Location of Dockerfile'
required: true
default: ./Dockerfile
artifact_registry:
description: 'Artifact Registry'
required: false
default: us-central1-docker.pkg.dev

runs:
using: 'composite'
Expand All @@ -34,17 +34,19 @@ runs:
skip_install: true

- name: gcloud configure docker
run: gcloud auth configure-docker ${{ inputs.gcr_hostname }}
run: gcloud auth configure-docker ${{ inputs.artifact_registry }}
shell: bash

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

# guide to docker caching: https://blacksmith.sh/blog/cache-is-king-a-guide-for-docker-layer-caching-in-github-actions
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ inputs.dockerfile }}
push: true
tags: ${{ inputs.gcr_hostname }}/${{ inputs.project_id }}/${{ inputs.service_name }}:${{ github.sha }}
no-cache: true
tags: ${{ inputs.artifact_registry }}/${{ inputs.project_id }}/docker-registry/${{ inputs.service_name }}:${{ github.sha }}
cache-from: type=registry,ref=${{ inputs.artifact_registry }}/${{ inputs.project_id }}/docker-registry/${{ inputs.service_name }}/app:buildcache
cache-to: type=registry,ref=${{ inputs.artifact_registry }}/${{ inputs.project_id }}/docker-registry/${{ inputs.service_name }}/app:buildcache,mode=max
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ apps/react-app/public/js
apps/react-app/public/index.js
apps/react-app/public/styles.css
.nx
stats.html
stats.html
docker-build.sh