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