Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: ensure image build job is compatible with merge queue #2941

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scripts/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
# Load the constants
source "$AVALANCHE_PATH"/scripts/constants.sh

if [[ $current_branch == *"-race" ]]; then
if [[ $image_tag == *"-race" ]]; then
echo "Branch name must not end in '-race'"
exit 1
fi
Expand Down Expand Up @@ -74,16 +74,16 @@ else
DOCKER_CMD="${DOCKER_CMD} --load"
fi

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

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

# Only tag the latest image for the master branch when images are pushed to a registry
if [[ "${DOCKER_IMAGE}" == *"/"* && $current_branch == "master" ]]; then
if [[ "${DOCKER_IMAGE}" == *"/"* && $image_tag == "master" ]]; then
echo "Tagging current avalanchego images as $DOCKER_IMAGE:latest"
docker buildx imagetools create -t "$DOCKER_IMAGE:latest" "$DOCKER_IMAGE:$commit_hash"
fi
13 changes: 8 additions & 5 deletions scripts/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Direct
# Where AvalancheGo binary goes
avalanchego_path="$AVALANCHE_PATH/build/avalanchego"

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

# Current commit (shared between image build and its test script)
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests.build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ build_and_test() {
# Check all of the images expected to have been built
local target_images=(
"$image_name:$commit_hash"
"$image_name:$current_branch"
"$image_name:$image_tag"
"$image_name:$commit_hash-race"
"$image_name:$current_branch-race"
"$image_name:$image_tag-race"
)

for arch in "${arches[@]}"; do
Expand Down
Loading