From 51e54a5e3295b7d4d44236621b821a8f41dfea0a Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 27 Aug 2024 18:48:20 -0700 Subject: [PATCH 1/2] [antithesis] Enable image build for multi-module repos 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. --- scripts/lib_build_antithesis_images.sh | 4 +++- .../antithesis/Dockerfile.builder-uninstrumented | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/lib_build_antithesis_images.sh b/scripts/lib_build_antithesis_images.sh index 0ab36a0bcdf3..d006836be67a 100644 --- a/scripts/lib_build_antithesis_images.sh +++ b/scripts/lib_build_antithesis_images.sh @@ -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" @@ -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. diff --git a/tests/antithesis/Dockerfile.builder-uninstrumented b/tests/antithesis/Dockerfile.builder-uninstrumented index 4ff06603d96c..aedbc610f0ba 100644 --- a/tests/antithesis/Dockerfile.builder-uninstrumented +++ b/tests/antithesis/Dockerfile.builder-uninstrumented @@ -5,13 +5,20 @@ 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 . . +# Download dependencies of the main go module +RUN go mod download + +# 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 + +# Download dependencies for the specified go module if a path was provided +RUN [ -n $MODULE_PATH ] && (cd $MODULE_PATH && go mod download) || true + # Ensure pre-existing builds are not available for inclusion in the final image RUN [ -d ./build ] && rm -rf ./build/* || true From 04782bcc3b786114cefdddaddfc7ed3257cd9618 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 27 Aug 2024 20:03:27 -0700 Subject: [PATCH 2/2] fixup: Extend module path support to instrumentation --- scripts/lib_build_antithesis_images.sh | 10 ++++++++-- tests/antithesis/Dockerfile.builder-instrumented | 15 ++++++++++----- .../antithesis/Dockerfile.builder-uninstrumented | 10 ++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/lib_build_antithesis_images.sh b/scripts/lib_build_antithesis_images.sh index d006836be67a..bb7640807944 100644 --- a/scripts/lib_build_antithesis_images.sh +++ b/scripts/lib_build_antithesis_images.sh @@ -26,8 +26,14 @@ function build_antithesis_builder_image { builder_dockerfile="${base_dockerfile}.builder-uninstrumented" fi - docker buildx build --build-arg GO_VERSION="${go_version}" --build-arg=MODULE_PATH="${module_path}" \ - -t "${image_name}" -f "${builder_dockerfile}" "${target_path}" + BUILD_ARGS="--build-arg GO_VERSION=${go_version}" + if [[ -n "${module_path}" ]]; then + # Only set the module path if it is provided + BUILD_ARGS="${BUILD_ARGS} --build-arg MODULE_PATH=${module_path}" + fi + + # shellcheck disable=SC2086 + docker buildx build ${BUILD_ARGS} -t "${image_name}" -f "${builder_dockerfile}" "${target_path}" } # Build the antithesis node, workload, and config images. diff --git a/tests/antithesis/Dockerfile.builder-instrumented b/tests/antithesis/Dockerfile.builder-instrumented index f9e4b2d054e1..e49db5948219 100644 --- a/tests/antithesis/Dockerfile.builder-instrumented +++ b/tests/antithesis/Dockerfile.builder-instrumented @@ -9,14 +9,19 @@ FROM docker.io/antithesishq/go-instrumentor AS instrumentor 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=. + +# Download dependencies for the specified go module if a path was provided, +# otherwise download dependencies for the current directory. +RUN cd $MODULE_PATH && go mod download + # Ensure pre-existing builds are not available for inclusion in the final image RUN [ -d ./build ] && rm -rf ./build/* || true @@ -38,7 +43,7 @@ RUN cp -r .git /opt/tmp/ RUN /opt/antithesis/bin/goinstrumentor \ -stderrthreshold=INFO \ -antithesis /opt/antithesis/instrumentation \ - . \ + $MODULE_PATH \ /instrumented WORKDIR /instrumented/customer diff --git a/tests/antithesis/Dockerfile.builder-uninstrumented b/tests/antithesis/Dockerfile.builder-uninstrumented index aedbc610f0ba..0bf1321fe54a 100644 --- a/tests/antithesis/Dockerfile.builder-uninstrumented +++ b/tests/antithesis/Dockerfile.builder-uninstrumented @@ -9,16 +9,14 @@ WORKDIR /build # Copy the code into the container COPY . . -# Download dependencies of the main go module -RUN go mod download - # 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 +ARG MODULE_PATH=. -# Download dependencies for the specified go module if a path was provided -RUN [ -n $MODULE_PATH ] && (cd $MODULE_PATH && go mod download) || true +# Download dependencies for the specified go module if a path was provided, +# otherwise download dependencies for the current directory. +RUN cd $MODULE_PATH && go mod download # Ensure pre-existing builds are not available for inclusion in the final image RUN [ -d ./build ] && rm -rf ./build/* || true