From a3b6bda6afb11355bc8158cb4a0e7650777d6971 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 15 Aug 2026 03:29:45 +0000 Subject: [PATCH] Authenticate to Docker Hub before pushing the image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The push step failed with 'unauthorized: access token has insufficient scopes' because the workflow never logged in — Docker Hub issued an anonymous, pull-only token. - Log in with docker/login-action using DOCKERHUB_USERNAME/DOCKERHUB_TOKEN - Build and push via docker/build-push-action with GitHub Actions layer cache - Skip login and push on pull_request events, where secrets are unavailable and unreviewed images should not be published - Also tag each build with the commit SHA alongside :latest Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01UCVZxJxkKSJwWJKDNoiAs4 --- .github/workflows/docker-image.yml | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index f412516..d20c9d2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,8 +14,27 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag tanutapi/simple-meteor-chat:latest - - name: Push to Docker Hub - run: docker push tanutapi/simple-meteor-chat:latest - + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Credentials are only available on push events, so pull requests + # build the image without logging in or pushing it. + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push the Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: | + tanutapi/simple-meteor-chat:latest + tanutapi/simple-meteor-chat:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max