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

[antithesis] Enable image build for multi-module repos #3342

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 9 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,14 @@ 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}"
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.
Expand Down
15 changes: 10 additions & 5 deletions tests/antithesis/Dockerfile.builder-instrumented
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
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=.

# 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
Loading