From 27bea09b16e86050acd9ca02da689522844311b9 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 22 Mar 2024 18:01:50 -0400 Subject: [PATCH] Push antithesis images (#2864) --- .../workflows/publish_antithesis_images.yml | 54 ++++++++++++++++ Dockerfile | 2 + go.mod | 2 + scripts/build_antithesis_workload.sh | 11 ++++ scripts/build_avalanche.sh | 2 + tests/antithesis/Dockerfile.config | 3 + tests/antithesis/Dockerfile.node | 64 +++++++++++++++++++ tests/antithesis/Dockerfile.workload | 29 +++++++++ tests/antithesis/docker-compose.yml | 3 +- 9 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish_antithesis_images.yml create mode 100755 scripts/build_antithesis_workload.sh create mode 100644 tests/antithesis/Dockerfile.config create mode 100644 tests/antithesis/Dockerfile.node create mode 100644 tests/antithesis/Dockerfile.workload diff --git a/.github/workflows/publish_antithesis_images.yml b/.github/workflows/publish_antithesis_images.yml new file mode 100644 index 000000000000..851260858990 --- /dev/null +++ b/.github/workflows/publish_antithesis_images.yml @@ -0,0 +1,54 @@ +name: Publish Antithesis Images + +on: + workflow_dispatch: + push: + branches: + - master + +env: + REGISTRY: us-central1-docker.pkg.dev + REPOSITORY: molten-verve-216720/avalanche-repository + NODE_NAME: avalanche-node + WORKLOAD_NAME: workload + CONFIG_NAME: config + TAG: latest + +jobs: + antithesis: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Login to GAR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: _json_key + password: ${{ secrets.ANTITHESIS_GAR_JSON_KEY }} + + - name: Build node + id: build-node-image + run: | + docker build -t $REGISTRY/$REPOSITORY/$NODE_NAME:$TAG -f ./tests/antithesis/Dockerfile.node . + echo "name=image::$REGISTRY/$REPOSITORY/$NODE_NAME:$TAG" >> $GITHUB_OUTPUT + + - name: Build workload + id: build-workload-image + run: | + docker build -t $REGISTRY/$REPOSITORY/$WORKLOAD_NAME:$TAG -f ./tests/antithesis/Dockerfile.workload . + echo "name=image::$REGISTRY/$REPOSITORY/$WORKLOAD_NAME:$TAG" >> $GITHUB_OUTPUT + + - name: Build config + id: build-config-image + run: | + docker build -t $REGISTRY/$REPOSITORY/$CONFIG_NAME:$TAG -f ./tests/antithesis/Dockerfile.config . + echo "name=image::$REGISTRY/$REPOSITORY/$CONFIG_NAME:$TAG" >> $GITHUB_OUTPUT + + - name: Publish images + run: | + docker push ${REGISTRY}/${REPOSITORY}/${NODE_NAME}:${TAG} + docker push ${REGISTRY}/${REPOSITORY}/${WORKLOAD_NAME}:${TAG} + docker push ${REGISTRY}/${REPOSITORY}/${CONFIG_NAME}:${TAG} diff --git a/Dockerfile b/Dockerfile index 035b203d8ca2..e0c1c941b9fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ # Changes to the minimum golang version must also be replicated in # scripts/build_avalanche.sh +# tests/antithesis/Dockerfile.node +# tests/antithesis/Dockerfile.workload # Dockerfile (here) # README.md # go.mod diff --git a/go.mod b/go.mod index b68f4d03a89b..154b2b63763d 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/ava-labs/avalanchego // Changes to the minimum golang version must also be replicated in // scripts/build_avalanche.sh +// tests/antithesis/Dockerfile.node +// tests/antithesis/Dockerfile.workload // Dockerfile // README.md // go.mod (here, only major.minor can be specified) diff --git a/scripts/build_antithesis_workload.sh b/scripts/build_antithesis_workload.sh new file mode 100755 index 000000000000..e0d99d1fed11 --- /dev/null +++ b/scripts/build_antithesis_workload.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Directory above this script +AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) +# Load the constants +source "$AVALANCHE_PATH"/scripts/constants.sh + +echo "Building Workload..." +go build -o "$AVALANCHE_PATH/build/workload" "$AVALANCHE_PATH/tests/antithesis/"*.go diff --git a/scripts/build_avalanche.sh b/scripts/build_avalanche.sh index a2b06508668e..094fa5467a2b 100755 --- a/scripts/build_avalanche.sh +++ b/scripts/build_avalanche.sh @@ -24,6 +24,8 @@ done # Changes to the minimum golang version must also be replicated in # scripts/build_avalanche.sh (here) +# tests/antithesis/Dockerfile.node +# tests/antithesis/Dockerfile.workload # Dockerfile # README.md # go.mod diff --git a/tests/antithesis/Dockerfile.config b/tests/antithesis/Dockerfile.config new file mode 100644 index 000000000000..f00caae693be --- /dev/null +++ b/tests/antithesis/Dockerfile.config @@ -0,0 +1,3 @@ +FROM scratch + +COPY ./tests/antithesis/docker-compose.yml /docker-compose.yml diff --git a/tests/antithesis/Dockerfile.node b/tests/antithesis/Dockerfile.node new file mode 100644 index 000000000000..3b32041dd3cb --- /dev/null +++ b/tests/antithesis/Dockerfile.node @@ -0,0 +1,64 @@ +# Antithesis: Getting the Antithesis golang instrumentation library +FROM docker.io/antithesishq/go-instrumentor AS instrumentor + +# Changes to the minimum golang version must also be replicated in +# scripts/build_avalanche.sh +# tests/antithesis/Dockerfile.node (here) +# Dockerfile +# README.md +# go.mod +# ============= Compilation Stage ================ +FROM golang:1.21.8-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 . . + +# Keep the commit hash to easily verify the exact version that is running +RUN git rev-parse HEAD > ./commit_hash.txt + +# Copy the instrumentor and supporting files to their correct locations +COPY --from=instrumentor /opt/antithesis /opt/antithesis +COPY --from=instrumentor /opt/antithesis/lib /lib + +# Create the destination output directory for the instrumented code +RUN mkdir -p /avalanchego_instrumented + +# Park the .git file in a safe location +RUN mkdir -p /opt/tmp/ +RUN cp -r .git /opt/tmp/ + +# Instrument avalanchego +RUN /opt/antithesis/bin/goinstrumentor \ + -stderrthreshold=INFO \ + -antithesis /opt/antithesis/instrumentation \ + . \ + /avalanchego_instrumented + +WORKDIR /avalanchego_instrumented/customer +RUN go mod download +RUN ln -s /opt/tmp/.git .git + +# Build avalanchego with race detection (-r) enabled. +RUN ./scripts/build.sh -r + +# ============= Cleanup Stage ================ +FROM debian:11-slim AS execution + +# Copy identifying information into the container +COPY --from=builder /build/commit_hash.txt ./commit_hash.txt + +# Copy the antithesis dependencies into the container +RUN mkdir -p /symbols +COPY --from=builder /avalanchego_instrumented/symbols /symbols +COPY --from=builder /opt/antithesis/lib/libvoidstar.so /usr/lib/libvoidstar.so + +# Copy the executable into the container +COPY --from=builder /avalanchego_instrumented/customer/build/avalanchego ./avalanchego + +CMD [ "./avalanchego" ] diff --git a/tests/antithesis/Dockerfile.workload b/tests/antithesis/Dockerfile.workload new file mode 100644 index 000000000000..755c931c1a07 --- /dev/null +++ b/tests/antithesis/Dockerfile.workload @@ -0,0 +1,29 @@ +# Changes to the minimum golang version must also be replicated in +# scripts/build_avalanche.sh +# tests/antithesis/Dockerfile.node +# tests/antithesis/Dockerfile.workload (here) +# Dockerfile +# README.md +# go.mod +# ============= Compilation Stage ================ +FROM golang:1.21.8-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 . . + +# Build the workload +RUN ./scripts/build_antithesis_workload.sh + +# ============= Cleanup Stage ================ +FROM debian:11-slim AS execution + +# Copy the executable into the container +COPY --from=builder /build/build/workload ./workload + +CMD [ "./workload" ] diff --git a/tests/antithesis/docker-compose.yml b/tests/antithesis/docker-compose.yml index 5a23f8b71d2f..6a13eca55761 100644 --- a/tests/antithesis/docker-compose.yml +++ b/tests/antithesis/docker-compose.yml @@ -8,7 +8,6 @@ services: # workload waits until cluster is up, issues 5 transactions, and the intializes the wallet. THEN we start fuzzing workload: container_name: workload - entrypoint: [ "./antithesis-workload" ] image: workload:latest environment: { AVAWL_URIS: "http://10.0.20.3:9650 http://10.0.20.4:9650 http://10.0.20.5:9650 http://10.0.20.6:9650 http://10.0.20.7:9650" @@ -117,4 +116,4 @@ services: AVAGO_STAKING_SIGNER_KEY_FILE_CONTENT: "QXZhbGFuY2hlTG9jYWxOZXR3b3JrVmFsaWRhdG9yMDU=" } networks: - avalanche-testnet: { ipv4_address: 10.0.20.7 } \ No newline at end of file + avalanche-testnet: { ipv4_address: 10.0.20.7 }