-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathDockerfile
63 lines (49 loc) · 2.31 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# ============= Setting up base Stage ================
# AVALANCHEGO_NODE_IMAGE needs to identify an existing node image and should include the tag
ARG AVALANCHEGO_NODE_IMAGE="invalid-image" # This value is not intended to be used but silences a warning
# ============= Compilation Stage ================
FROM --platform=$BUILDPLATFORM golang:1.23.7-bullseye AS builder
WORKDIR /build
ARG VM_NAME
# Download hypersdk deps
COPY go.mod go.sum ./
RUN go mod download
# Copy the code into the container
COPY . .
# Set the working directory to the VM directory
WORKDIR /build/examples/$VM_NAME/
# Download VM deps
COPY examples/$VM_NAME/go.mod examples/$VM_NAME/go.sum ./
RUN go mod download
# Ensure pre-existing builds are not available for inclusion in the final image
RUN [ -d ./build ] && rm -rf ./build/* || true
ARG TARGETPLATFORM
ARG BUILDPLATFORM
# Configure a cross-compiler if the target platform differs from the build platform.
#
# build_env.sh is used to capture the environmental changes required by the build step since RUN
# environment state is not otherwise persistent.
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] && [ "$BUILDPLATFORM" != "linux/arm64" ]; then \
apt-get update && apt-get install -y gcc-aarch64-linux-gnu && \
echo "export CC=aarch64-linux-gnu-gcc" > ./build_env.sh \
; elif [ "$TARGETPLATFORM" = "linux/amd64" ] && [ "$BUILDPLATFORM" != "linux/amd64" ]; then \
apt-get update && apt-get install -y gcc-x86-64-linux-gnu && \
echo "export CC=x86_64-linux-gnu-gcc" > ./build_env.sh \
; else \
echo "export CC=gcc" > ./build_env.sh \
; fi
# Build VM binary. The build environment is configured with build_env.sh from the step
# enabling cross-compilation.
ARG VM_COMMIT
RUN . ./build_env.sh && \
echo "{CC=$CC, TARGETPLATFORM=$TARGETPLATFORM, BUILDPLATFORM=$BUILDPLATFORM}" && \
export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) && \
export VM_COMMIT="${VM_COMMIT}" && \
./scripts/build.sh /build/build/vm
# ============= Cleanup Stage ================
FROM $AVALANCHEGO_NODE_IMAGE AS execution
# Place the VM binary and set the AVAGO_PLUGIN_DIR env variable, so that
# AvalancheGo reads it correctly without additional configuration.
ARG VM_ID
ENV AVAGO_PLUGIN_DIR="/avalanchego/build/plugins"
COPY --from=builder /build/build/vm /avalanchego/build/plugins/$VM_ID