diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 1061b19..a85a426 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: @@ -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 @@ -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: @@ -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: @@ -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 }}