Skip to content

Commit 6eef37e

Browse files
authored
Bug 2064286 - Don't break the CircleCI build when DOCKERHUB_REPO is unset
1 parent cc52ba3 commit 6eef37e

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

.circleci/config.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ jobs:
4848
command: |
4949
mkdir /tmp/artifacts && \
5050
cp version.json /tmp/artifacts/version.json
51+
- run:
52+
name: Set image name
53+
# `DOCKERHUB_REPO` is not exposed to builds from forked pull requests,
54+
# so fall back to a local-only name to keep the build working there.
55+
command: |
56+
echo "export IMAGE_NAME=\"${DOCKERHUB_REPO:-mozilla/phabricator}\"" >> "$BASH_ENV"
5157
- run:
5258
name: Build Docker image
53-
command: docker build --pull -t $DOCKERHUB_REPO --target production .
59+
command: docker build --pull -t "$IMAGE_NAME" --target production .
5460
- run:
5561
name: Build test image
5662
command: docker compose build test_phab
@@ -59,25 +65,25 @@ jobs:
5965
command: docker compose build test_phab_local
6066
- run:
6167
name: Inspect Docker image ID
62-
command: docker inspect $(docker inspect -f '{{.Id}}' $DOCKERHUB_REPO)
68+
command: docker inspect "$(docker inspect -f '{{.Id}}' "$IMAGE_NAME")"
6369
- run:
6470
name: Copy imageid to artifacts
65-
command: docker inspect -f '{{.Id}}' $DOCKERHUB_REPO | tee /tmp/artifacts/docker-image-shasum256.txt
71+
command: docker inspect -f '{{.Id}}' "$IMAGE_NAME" | tee /tmp/artifacts/docker-image-shasum256.txt
6672
- store_artifacts:
6773
path: /tmp/artifacts
6874
- run:
6975
name: Deploy to docker hub
7076
command: |
7177
[[ -n "$DOCKERHUB_REPO" && -n "$DOCKER_USER" && -n "$DOCKER_PASS" ]] || exit 0
7278
echo "${DOCKER_PASS}" | docker login -u="${DOCKER_USER}" --password-stdin
73-
docker tag "$DOCKERHUB_REPO" "$DOCKERHUB_REPO:$CIRCLE_SHA1"
79+
docker tag "$IMAGE_NAME" "$DOCKERHUB_REPO:$CIRCLE_SHA1"
7480
docker push "$DOCKERHUB_REPO:$CIRCLE_SHA1"
7581
if [[ "$CIRCLE_BRANCH" == "master" ]]; then
7682
docker push "$DOCKERHUB_REPO:latest"
7783
else
7884
# Replace forward slashes with hyphens in branch name for Docker tag
7985
SAFE_BRANCH_NAME=$(echo "$CIRCLE_BRANCH" | tr '/' '-')
80-
docker tag "$DOCKERHUB_REPO" "$DOCKERHUB_REPO:$SAFE_BRANCH_NAME"
86+
docker tag "$IMAGE_NAME" "$DOCKERHUB_REPO:$SAFE_BRANCH_NAME"
8187
docker push "$DOCKERHUB_REPO:$SAFE_BRANCH_NAME"
8288
fi
8389

0 commit comments

Comments
 (0)