Login only if needed

This commit is contained in:
Felipe Knorr Kuhn 2025-11-28 20:26:46 -08:00
parent 4afe4be5e5
commit 1205d15920
No known key found for this signature in database
GPG key ID: 79619B52BB097C1A

View file

@ -83,6 +83,9 @@ jobs:
- name: Login to Docker for building
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'docker-test'))
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Checkout project
@ -139,16 +142,38 @@ jobs:
- name: Run Docker buildx for ${{ matrix.service }} against tag
id: docker-build
run: |
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache,mode=max" \
--platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKER_HUB_USER }}/${{ matrix.service }}:$TAG \
--build-context rustgbt=./rust \
--build-context backend=./backend \
--output "type=registry,push=true" \
--build-arg commitHash=$SHORT_SHA \
./${{ matrix.service }}/
# For docker-test label PRs, build locally without pushing
IS_DOCKER_TEST=false
if [ "${{ github.event_name }}" = "pull_request" ]; then
LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}"
if echo "$LABELS" | grep -q "docker-test"; then
IS_DOCKER_TEST=true
fi
fi
if [ "$IS_DOCKER_TEST" = "true" ]; then
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache,mode=max" \
--platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKER_HUB_USER }}/${{ matrix.service }}:$TAG \
--build-context rustgbt=./rust \
--build-context backend=./backend \
--output "type=image,push=false" \
--build-arg commitHash=$SHORT_SHA \
./${{ matrix.service }}/
else
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache,mode=max" \
--platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKER_HUB_USER }}/${{ matrix.service }}:$TAG \
--build-context rustgbt=./rust \
--build-context backend=./backend \
--output "type=registry,push=true" \
--build-arg commitHash=$SHORT_SHA \
./${{ matrix.service }}/
fi
tag-latest:
needs: build