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

feat(ci): add dev image build and cache support #19

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/build-docker-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
54 changes: 54 additions & 0 deletions .github/workflows/build-test-docker-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build and Test Development Docker Image

on:
push:
branches:
- dev
pull_request:
branches:
- dev
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: SageSeekerSociety/cheese-frontend-dev

jobs:
build-and-test-dev-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

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

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
target: dev
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Comment on lines +45 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize Docker build and push step with caching.

The Docker build and push step is configured to use GitHub Actions' caching (cache-from: type=gha and cache-to: type=gha,mode=max). This is a great practice for speeding up builds. However, consider specifying more granular cache keys based on your project's structure and dependencies to further optimize caching efficiency. For example, using a combination of the base image version, Dockerfile changes, and dependency manifest files as part of the cache key can help ensure that the cache is invalidated appropriately when necessary.