From 1857fa4aeb25a55b6c8c0c3f3e5bf285cdeaa85e Mon Sep 17 00:00:00 2001 From: George Vina <7191725+gamerg21@users.noreply.github.com> Date: Tue, 23 Dec 2025 05:52:56 +0000 Subject: [PATCH 1/2] Update Docker build workflow to support multiple branches and pull requests - Modified the GitHub Actions workflow to trigger on pushes to both 'main' and 'master' branches. - Added support for pull requests targeting 'main' and 'master' branches, enhancing the CI/CD process for Docker image builds. --- .github/workflows/docker-build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 1061b19..cb5b29c 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -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: From a8fc766a3fd44fd3e69f4bda7cdad3ccbf0b44e3 Mon Sep 17 00:00:00 2001 From: George Vina <7191725+gamerg21@users.noreply.github.com> Date: Tue, 23 Dec 2025 05:57:43 +0000 Subject: [PATCH 2/2] Refactor Docker build workflow to improve cache handling - Updated the cache reference in the GitHub Actions workflow to exclude the docker.io prefix, ensuring compatibility with Docker Hub. - Added a new step to configure cache settings, temporarily disabling the registry cache to avoid authentication issues during builds. - Adjusted cache-from and cache-to parameters to utilize the new cache configuration, enhancing build efficiency and reliability. --- .github/workflows/docker-build.yml | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index cb5b29c..a85a426 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -44,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 @@ -55,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: @@ -80,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: @@ -88,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 }}