fix: docker should always run, even in forks (#26801)

This commit is contained in:
Maxime Beauchemin 2024-01-25 11:33:51 -08:00 committed by GitHub
parent 424b4c2378
commit 845bcc9bea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 24 deletions

View File

@ -8,27 +8,7 @@ on:
types: [synchronize, opened, reopened, ready_for_review]
jobs:
config:
runs-on: "ubuntu-latest"
outputs:
has-secrets: ${{ steps.check.outputs.has-secrets }}
steps:
- name: "Check for secrets"
id: check
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
if [[ -n "$DOCKERHUB_USER" && -n "$DOCKERHUB_TOKEN" ]]; then
echo "has-secrets=true" >> "$GITHUB_ENV"
echo "has secrets!"
else
echo "has-secrets=false" >> "$GITHUB_ENV"
echo "no secrets!"
fi
docker-build:
needs: config
if: needs.config.outputs.has-secrets == 'true'
name: docker-build
runs-on: ubuntu-latest
strategy:
@ -63,9 +43,8 @@ jobs:
run: |
./scripts/docker_build_push.sh "" ${{ matrix.target }} ${{ matrix.platform }}
ephemeral-docker-build:
needs: config
if: needs.config.outputs.has-secrets
name: docker-build
runs-on: ubuntu-latest
steps:

View File

@ -130,15 +130,22 @@ if [[ -n "${BUILD_TARGET}" ]]; then
TARGET_ARGUMENT="--target ${BUILD_TARGET}"
fi
# Building the cache settings
CACHE_REF="${REPO_NAME}-cache:${TARGET}-${BUILD_ARG}"
CACHE_REF=$(echo "${CACHE_REF}" | tr -d '.')
CACHE_FROM_ARG="--cache-from=type=registry,ref=${CACHE_REF}"
CACHE_TO_ARG=""
if [ -n "${DOCKERHUB_TOKEN}" ]; then
# need to be logged in to push to the cache
CACHE_TO_ARG="--cache-to=type=registry,mode=max,ref=${CACHE_REF}"
fi
docker buildx build \
${TARGET_ARGUMENT} \
${DOCKER_ARGS} \
--cache-from=type=registry,ref=${CACHE_REF} \
--cache-to=type=registry,mode=max,ref=${CACHE_REF} \
${DOCKER_TAGS} \
${CACHE_FROM_ARG} \
${CACHE_TO_ARG} \
--platform ${BUILD_PLATFORM} \
--label "sha=${SHA}" \
--label "built_at=$(date)" \