Skip to content

Commit a60c6b2

Browse files
authored
CI: ensure image build job is compatible with merge queue (#2941)
1 parent 39b10ad commit a60c6b2

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

scripts/build_image.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
2828
# Load the constants
2929
source "$AVALANCHE_PATH"/scripts/constants.sh
3030

31-
if [[ $current_branch == *"-race" ]]; then
31+
if [[ $image_tag == *"-race" ]]; then
3232
echo "Branch name must not end in '-race'"
3333
exit 1
3434
fi
@@ -74,16 +74,16 @@ else
7474
DOCKER_CMD="${DOCKER_CMD} --load"
7575
fi
7676

77-
echo "Building Docker Image with tags: $DOCKER_IMAGE:$commit_hash , $DOCKER_IMAGE:$current_branch"
78-
${DOCKER_CMD} -t "$DOCKER_IMAGE:$commit_hash" -t "$DOCKER_IMAGE:$current_branch" \
77+
echo "Building Docker Image with tags: $DOCKER_IMAGE:$commit_hash , $DOCKER_IMAGE:$image_tag"
78+
${DOCKER_CMD} -t "$DOCKER_IMAGE:$commit_hash" -t "$DOCKER_IMAGE:$image_tag" \
7979
"$AVALANCHE_PATH" -f "$AVALANCHE_PATH/Dockerfile"
8080

81-
echo "Building Docker Image with tags: $DOCKER_IMAGE:$commit_hash-race , $DOCKER_IMAGE:$current_branch-race"
82-
${DOCKER_CMD} --build-arg="RACE_FLAG=-r" -t "$DOCKER_IMAGE:$commit_hash-race" -t "$DOCKER_IMAGE:$current_branch-race" \
81+
echo "Building Docker Image with tags: $DOCKER_IMAGE:$commit_hash-race , $DOCKER_IMAGE:$image_tag-race"
82+
${DOCKER_CMD} --build-arg="RACE_FLAG=-r" -t "$DOCKER_IMAGE:$commit_hash-race" -t "$DOCKER_IMAGE:$image_tag-race" \
8383
"$AVALANCHE_PATH" -f "$AVALANCHE_PATH/Dockerfile"
8484

8585
# Only tag the latest image for the master branch when images are pushed to a registry
86-
if [[ "${DOCKER_IMAGE}" == *"/"* && $current_branch == "master" ]]; then
86+
if [[ "${DOCKER_IMAGE}" == *"/"* && $image_tag == "master" ]]; then
8787
echo "Tagging current avalanchego images as $DOCKER_IMAGE:latest"
8888
docker buildx imagetools create -t "$DOCKER_IMAGE:latest" "$DOCKER_IMAGE:$commit_hash"
8989
fi

scripts/constants.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Direct
1313
# Where AvalancheGo binary goes
1414
avalanchego_path="$AVALANCHE_PATH/build/avalanchego"
1515

16-
# Current branch (shared between image build and its test script)
16+
# Image tag based on current branch (shared between image build and its test script)
1717
# TODO: fix "fatal: No names found, cannot describe anything" in github CI
18-
current_branch=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match || true)
19-
# Supply a default branch when one is not discovered
20-
if [[ -z $current_branch ]]; then
21-
current_branch=ci_dummy
18+
image_tag=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match || true)
19+
if [[ -z $image_tag ]]; then
20+
# Supply a default tag when one is not discovered
21+
image_tag=ci_dummy
22+
elif [[ "$image_tag" == */* ]]; then
23+
# Slashes are not legal for docker image tags - replace with dashes
24+
image_tag=$(echo "$image_tag" | tr '/' '-')
2225
fi
2326

2427
# Current commit (shared between image build and its test script)

scripts/tests.build_image.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ build_and_test() {
3535
# Check all of the images expected to have been built
3636
local target_images=(
3737
"$image_name:$commit_hash"
38-
"$image_name:$current_branch"
38+
"$image_name:$image_tag"
3939
"$image_name:$commit_hash-race"
40-
"$image_name:$current_branch-race"
40+
"$image_name:$image_tag-race"
4141
)
4242

4343
for arch in "${arches[@]}"; do

0 commit comments

Comments
 (0)