Skip to content
Merged
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
38 changes: 35 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ name: Build and Publish Docker Image

on:
push:
branches:
- main
- master
tags:
- 'v*.*.*' # Trigger on version tags like v1.0.0
pull_request:
branches:
- main
- master
workflow_dispatch: # Allow manual triggers
inputs:
tag:
Expand Down Expand Up @@ -37,7 +44,8 @@ jobs:
REGISTRY="${{ env.REGISTRY }}"
echo "username=$DOCKER_USERNAME" >> $GITHUB_OUTPUT
echo "image_name=$DOCKER_USERNAME/sous-chef" >> $GITHUB_OUTPUT
echo "cache_ref=$REGISTRY/$DOCKER_USERNAME/sous-chef:buildcache" >> $GITHUB_OUTPUT
# Cache reference should not include docker.io prefix for registry cache
echo "cache_ref=$DOCKER_USERNAME/sous-chef:buildcache" >> $GITHUB_OUTPUT

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -48,6 +56,7 @@ jobs:
with:
username: ${{ steps.docker_meta.outputs.username }}
password: ${{ secrets.DOCKER_PASSWORD }}
logout: false

# Alternative: Log in to GitHub Container Registry
# Uncomment the following if using GitHub Container Registry instead:
Expand All @@ -73,6 +82,29 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}

- name: Set cache configuration
id: cache
run: |
# Temporarily disable registry cache to avoid auth issues
# Re-enable after ensuring repository exists on Docker Hub
# For now, use inline cache which doesn't require registry write permissions
if [ "${{ github.event_name }}" != "pull_request" ]; then
# Option 1: Disable cache entirely (fastest fix)
echo "cache_from=" >> $GITHUB_OUTPUT
echo "cache_to=" >> $GITHUB_OUTPUT
# Option 2: Use inline cache (uncomment to enable)
# echo "cache_from=" >> $GITHUB_OUTPUT
# echo "cache_to=type=inline" >> $GITHUB_OUTPUT
# Option 3: Use registry cache (uncomment after creating repository on Docker Hub)
# CACHE_REF="${{ env.REGISTRY }}/${{ steps.docker_meta.outputs.cache_ref }}"
# echo "cache_from=type=registry,ref=$CACHE_REF" >> $GITHUB_OUTPUT
# echo "cache_to=type=registry,ref=$CACHE_REF,mode=max" >> $GITHUB_OUTPUT
else
# PRs use inline cache (no auth needed)
echo "cache_from=" >> $GITHUB_OUTPUT
echo "cache_to=type=inline" >> $GITHUB_OUTPUT
fi

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
Expand All @@ -81,6 +113,6 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.docker_meta.outputs.cache_ref }}
cache-to: type=registry,ref=${{ steps.docker_meta.outputs.cache_ref }},mode=max
cache-from: ${{ steps.cache.outputs.cache_from }}
cache-to: ${{ steps.cache.outputs.cache_to }}

Loading