Skip to content

Commit

Permalink
[antithesis] Enable image build for multi-module repos
Browse files Browse the repository at this point in the history
The proposed subnet-evm refactor requires that construction of the
builder image support providing the path to the go module whose
dependencies will be downloaded.
  • Loading branch information
marun committed Aug 28, 2024
1 parent 0117ab9 commit d2a25dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion scripts/lib_build_antithesis_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function build_antithesis_builder_image {
local image_name=$2
local avalanchego_path=$3
local target_path=$4
local module_path=${5:-}

local base_dockerfile="${avalanchego_path}/tests/antithesis/Dockerfile"
local builder_dockerfile="${base_dockerfile}.builder-instrumented"
Expand All @@ -25,7 +26,8 @@ function build_antithesis_builder_image {
builder_dockerfile="${base_dockerfile}.builder-uninstrumented"
fi

docker buildx build --build-arg GO_VERSION="${go_version}" -t "${image_name}" -f "${builder_dockerfile}" "${target_path}"
docker buildx build --build-arg GO_VERSION="${go_version}" --build-arg=MODULE_PATH="${module_path}" \
-t "${image_name}" -f "${builder_dockerfile}" "${target_path}"
}

# Build the antithesis node, workload, and config images.
Expand Down
13 changes: 9 additions & 4 deletions tests/antithesis/Dockerfile.builder-uninstrumented
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ ARG GO_VERSION
FROM golang:$GO_VERSION-bullseye

WORKDIR /build
# Copy and download dependencies using go mod
COPY go.mod .
COPY go.sum .
RUN go mod download

# Copy the code into the container
COPY . .

# Providing a non-empty MODULE_PATH supports the case where the target module is
# not at the root of the repo but its go.mod references other modules in the repo
# (including the root).
ARG MODULE_PATH

# Copy and download dependencies using go mod. If MODULE_PATH is set, download the
# dependencies only for that module.
RUN [ -n $MODULE_PATH ]] && (cd ${MODULE_PATH} && go mod download) || go mod download

# Ensure pre-existing builds are not available for inclusion in the final image
RUN [ -d ./build ] && rm -rf ./build/* || true

0 comments on commit d2a25dd

Please sign in to comment.