Skip to content

Commit

Permalink
fixup: Simplify generation of docker compose artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed May 11, 2024
1 parent 0a87ad2 commit 8dad27f
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ARG AVALANCHEGO_NODE_IMAGE

# ============= Compilation Stage ================
FROM golang:1.21.9-bullseye AS builder
FROM golang:1.21.10-bullseye AS builder

WORKDIR /build

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/ava-labs/subnet-evm

go 1.21.9
go 1.21.10

require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanchego v1.11.6-0.20240506185313-bcac3aef13ad
github.com/ava-labs/avalanchego v1.11.6-0.20240511023151-e1f819483959
github.com/cespare/cp v0.1.0
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set/v2 v2.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.6-0.20240506185313-bcac3aef13ad h1:jyoQE9jlda2CkJrTWZEsGpwlTZLIy2OvVFg7KqWXU5M=
github.com/ava-labs/avalanchego v1.11.6-0.20240506185313-bcac3aef13ad/go.mod h1:kIad6DhZYRRpzssQXdgF9gNuiwLiATVcTiY3cg42XtQ=
github.com/ava-labs/avalanchego v1.11.6-0.20240511023151-e1f819483959 h1:lzfbav8Ceeq6nkpYSkqI7qVnR2FZEjBtgsRxfrZyY7o=
github.com/ava-labs/avalanchego v1.11.6-0.20240511023151-e1f819483959/go.mod h1:O1e2KiYK0IBE5ypTHmmQ2aDXP5r5hnfoKetTL3Lq6yw=
github.com/ava-labs/coreth v0.13.4-0.20240506124912-82b6c4e91557 h1:92JWd4u2pqpO551gXUIZ/qDZu3l7vn8jIxX2qRyyFwM=
github.com/ava-labs/coreth v0.13.4-0.20240506124912-82b6c4e91557/go.mod h1:yMIxezDyB/5moKt8LlATlfwR/Z5cmipY3gUQ1SqHvQ0=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
25 changes: 23 additions & 2 deletions scripts/build_antithesis_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,31 @@ function build_images {
# Define default build command
local docker_cmd="docker buildx build --build-arg GO_VERSION=${GO_VERSION} --build-arg NODE_IMAGE=${node_image_name}"

# Build node image first to allow the config and workload image builds to use it.
# Build node image first to allow the workload image to be based on it.
${docker_cmd} --build-arg AVALANCHEGO_NODE_IMAGE="${avalanche_node_image}" -t "${node_image_name}" \
-f "${node_dockerfile}" "${SUBNET_EVM_PATH}"
${docker_cmd} --build-arg IMAGE_TAG="${TAG}" -t "${config_image_name}" -f "${base_dockerfile}.config" "${SUBNET_EVM_PATH}"
TARGET_PATH="${SUBNET_EVM_PATH}/build/antithesis"
if [[ -d "${TARGET_PATH}" ]]; then
# Ensure the target path is empty before generating the compose config
rm -r "${TARGET_PATH}"
fi

# Ensure avalanchego and subnet-evm binaries are available to create an initial db state that includes subnets.
"${AVALANCHEGO_CLONE_PATH}"/scripts/build.sh
PLUGIN_PATH="${TARGET_PATH}"/plugins
"${SUBNET_EVM_PATH}"/scripts/build.sh "${PLUGIN_PATH}"/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy

# Generate compose config and db state for the config image
TARGET_PATH="${TARGET_PATH}"\
IMAGE_TAG="${TAG}"\
AVALANCHEGO_PATH="${AVALANCHEGO_CLONE_PATH}/build/avalanchego"\
AVALANCHEGO_PLUGIN_DIR="${PLUGIN_PATH}"\
go run "${SUBNET_EVM_PATH}/tests/antithesis/gencomposeconfig"

# Build config image
${docker_cmd} -t "${config_image_name}" -f "${base_dockerfile}.config" "${SUBNET_EVM_PATH}"

# Build workload image
${docker_cmd} -t "${workload_image_name}" -f "${base_dockerfile}.workload" "${SUBNET_EVM_PATH}"
}

Expand Down
8 changes: 3 additions & 5 deletions scripts/tests.build_antithesis_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ docker cp "${CONTAINER_NAME}":/docker-compose.yml "${COMPOSE_FILE}"
# Copy the volume paths out of the container
docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/"

# Run the docker compose project for 2 minutes without error. 2
# minutes is suggested because the way docker-compose brings all
# containers up simultaneously and the lack of coordination results in
# exponential back-off on the nodes trying to bootstrap.
# Run the docker compose project for 30 seconds without error. Local
# network bootstrap is ~6s, but github workers can be much slower.
${COMPOSE_CMD} up -d
sleep 120
sleep 30
if ${COMPOSE_CMD} ps -q | xargs docker inspect -f '{{ .State.Status }}' | grep -v 'running'; then
echo "An error occurred."
exit 255
Expand Down
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# shellcheck disable=SC2034

# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'bcac3aef1'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'e1f819483'}
GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'}

# This won't be used, but it's here to make code syncs easier
Expand Down
55 changes: 4 additions & 51 deletions tests/antithesis/Dockerfile.config
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
# The version is supplied as a build argument rather than hard-coded
# to minimize the cost of version changes.
ARG GO_VERSION

# NODE_IMAGE needs to identify an existing subnet-evm node image and should include the tag
ARG NODE_IMAGE

# ============= Node Image State ================
FROM $NODE_IMAGE AS node

# If this is not an instrumented node image, fake the antithesis dependencies expected by the builder.
RUN [ ! -d /symbols ] && mkdir /symbols || true
RUN [ ! -f /usr/lib/libvoidstar.so ] && touch /usr/lib/libvoidstar.so || true

# ============= Compilation Stage ================
FROM golang:$GO_VERSION-bullseye AS builder

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

# Copy the code into the container
COPY . .

# IMAGE_TAG should be set to the tag for the images in the generated docker compose file.
ARG IMAGE_TAG=latest

# Copy the avalanchego binary and plugin from the node image
RUN mkdir -p ./build/plugins
COPY --from=node /avalanchego/build/avalanchego ./build
COPY --from=node /avalanchego/build/plugins/* ./build/plugins/

# Copy antithesis dependencies required by instrumented binaries
COPY --from=node /symbols /symbols
COPY --from=node /usr/lib/libvoidstar.so /usr/lib/libvoidstar.so

# Generate docker compose configuration. If the command fails, it will likely be due to a
# node configuration problem. Attempt to start a node with the same configuration so that
# its logging output will be available to aid in troubleshooting.
RUN export AVALANCHEGO_PATH=./build/avalanchego\
export AVALANCHEGO_PLUGIN_DIR=./build/plugins;\
TARGET_PATH=./build IMAGE_TAG="$IMAGE_TAG" go run ./tests/antithesis/gencomposeconfig\
|| ${AVALANCHEGO_PATH} --log-display-level=debug\
--config-file=$(find /root/.tmpnet/networks -name "flags.json" | head -n 1)

# ============= Cleanup Stage ================
FROM scratch AS execution

# Copy the docker compose file and volumes into the container
COPY --from=builder /build/build/docker-compose.yml /docker-compose.yml
COPY --from=builder /build/build/volumes /volumes
# Copy config artifacts from the build path. For simplicity, artifacts
# are built outside of the docker image.
COPY ./build/antithesis/docker-compose.yml /
COPY ./build/antithesis/volumes /volumes
11 changes: 8 additions & 3 deletions tests/antithesis/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ func main() {
genesisPath := filepath.Join(cwd, "tests/load/genesis/genesis.json")

// Create a network with an xsvm subnet
network := tmpnet.LocalNetworkOrDie()
network := tmpnet.LocalNetworkOrPanic()
network.Subnets = []*tmpnet.Subnet{
utils.NewTmpnetSubnet("subnet-evm", genesisPath, utils.DefaultChainConfig, network.Nodes...),
}

if err := antithesis.InitDBVolumes(network, avalancheGoPath, pluginDir, targetPath); err != nil {
log.Fatalf("failed to initialize db volumes: %s", err)
bootstrapVolumePath, err := antithesis.GetBootstrapVolumePath(targetPath)
if err != nil {
log.Fatalf("failed to get bootstrap volume path: %v", err)
}

if err := antithesis.InitBootstrapDB(network, avalancheGoPath, pluginDir, bootstrapVolumePath); err != nil {
log.Fatalf("failed to initialize db volumes: %v", err)
}

if err := antithesis.GenerateComposeConfig(network, nodeImageName, workloadImageName, targetPath); err != nil {
Expand Down

0 comments on commit 8dad27f

Please sign in to comment.