-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
192 lines (160 loc) · 6.39 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Dependency versions (some used by builder and runtime)
ARG JAVA_VERSION=21.0.4+7
ARG NODE_VERSION=20.17.0
ARG PROTO_VERSION=28.2
ARG GO_VERSION=1.22.7
ARG GO_MIGRATE_VERSION=4.18.1
ARG GRADLE_VERSION=8.5
ARG WASMER_VERSION=4.3.7
# Additional JVM selection options
ARG JVM_TYPE=hotspot
ARG JVM_HEAP=normal
# Stage 1: Builder base for all the sub-builds
FROM ubuntu:24.04 AS base-builder
ARG TARGETOS
ARG TARGETARCH
ARG JAVA_VERSION
ARG JVM_TYPE
ARG JVM_HEAP
ARG NODE_VERSION
ARG PROTO_VERSION
ARG GO_VERSION
ARG GRADLE_VERSION
ARG WASMER_VERSION
# Set environment variables
ENV LANG=C.UTF-8
# Install build dependencies
RUN apt-get update && apt-get install -y \
curl \
unzip \
git \
build-essential \
gcc \
g++ \
libc6-dev \
pkg-config \
libgomp1 \
xz-utils \
&& apt-get clean
# Install JDK
RUN JAVA_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "aarch64"; else echo -n "x64"; fi ) && \
curl -sLo - https://api.adoptium.net/v3/binary/version/jdk-${JAVA_VERSION}/${TARGETOS}/${JAVA_ARCH}/jdk/${JVM_TYPE}/${JVM_HEAP}/eclipse | \
tar -C /usr/local -xzf - && \
ln -s /usr/local/jdk-* /usr/local/java
# Install Node.js v18 and npm
RUN NODE_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "arm64"; else echo -n "x64"; fi ) && \
curl -sLo - https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${TARGETOS}-${NODE_ARCH}.tar.xz | \
xz -cd - | tar -C /usr/local -xf - && \
ln -s /usr/local/node-* /usr/local/node
# Install Protoc
RUN PROTO_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "aarch_64"; else echo -n "x86_64"; fi ) && \
curl -sLo protoc-$PROTO_VERSION-${TARGETOS}-${PROTO_ARCH}.zip \
https://github.com/protocolbuffers/protobuf/releases/download/v$PROTO_VERSION/protoc-$PROTO_VERSION-${TARGETOS}-${PROTO_ARCH}.zip && \
unzip protoc-$PROTO_VERSION-${TARGETOS}-${PROTO_ARCH}.zip -d /usr/local/protoc && \
rm protoc-$PROTO_VERSION-${TARGETOS}-${PROTO_ARCH}.zip
# Install Go
RUN GO_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "arm64"; else echo -n "amd64"; fi ) && \
curl -sLo - https://go.dev/dl/go${GO_VERSION}.${TARGETOS}-${GO_ARCH}.tar.gz | \
tar -C /usr/local -xzf -
# Install Gradle
RUN curl -sLo gradle-${GRADLE_VERSION}-bin.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip && \
unzip gradle-${GRADLE_VERSION}-bin.zip -d /usr/local && \
rm gradle-${GRADLE_VERSION}-bin.zip && \
ln -s /usr/local/gradle-* /usr/local/gradle
# Install Wasmer (which includes libwasmer.so)
RUN WASMER_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "aarch64"; else echo -n "amd64"; fi ) && \
mkdir -p /usr/local/wasmer && \
curl -sLo - https://github.com/wasmerio/wasmer/releases/download/v${WASMER_VERSION}/wasmer-${TARGETOS}-${WASMER_ARCH}.tar.gz | \
tar -C /usr/local/wasmer -zxf -
# Add all the tools we installed to the path
ENV PATH=$PATH:/usr/local/bin
ENV PATH=$PATH:/usr/local/go/bin
ENV PATH=$PATH:/root/go/bin
ENV PATH=$PATH:/usr/local/node/bin
ENV PATH=$PATH:/usr/local/java/bin
ENV PATH=$PATH:/usr/local/gradle/bin
ENV PATH=$PATH:/usr/local/protoc/bin
ENV PATH=$PATH:/usr/local/wasmer/bin
# Set the working directory
WORKDIR /app
# Initialize gradle and build tasks
COPY build.gradle settings.gradle ./
COPY buildSrc buildSrc
RUN gradle --no-daemon --parallel :buildSrc:jar
# Copy in a set of thing before the first gradle command that are less likely to change
COPY solidity solidity
COPY config config
COPY toolkit/proto toolkit/proto
COPY toolkit toolkit
COPY go.work.sum ./
# We have to use a special minimal go.work for this
COPY go.work.base go.work
# Set Go CGO environment variables
ENV CGO_ENABLED=1
ENV CC=gcc
# This minimal set of commands primes the build with some slower things that accellerate rebuilds:
# - Installing gradle with the wrapper
# - Compiling the groovy buildSrc
# - Installing a bunch of base Go pre-reqs
RUN gradle --no-daemon --parallel :toolkit:go:assemble :solidity:compile
# Stage 2... Full build - currently core/zeto/noto/core are all cop-req'd together
# (If we untangle this we can get more parallelism and less re-build in our docker build)
FROM base-builder AS full-builder
COPY go.work go.work
COPY core/go core/go
COPY core/java core/java
COPY toolkit/java toolkit/java
COPY domains/pente domains/pente
COPY domains/zeto domains/zeto
COPY domains/noto domains/noto
COPY domains/integration-test domains/integration-test
COPY registries/static registries/static
COPY registries/evm registries/evm
COPY transports/grpc transports/grpc
COPY ui/client ui/client
# No build of these two, but we need to go.mod to make the go.work valid
COPY testinfra/go.mod testinfra/go.mod
COPY operator/go.mod operator/go.mod
RUN gradle --no-daemon --parallel assemble
# Stage 3: Pull together runtime
FROM ubuntu:24.04 AS runtime
ARG TARGETOS
ARG TARGETARCH
ARG JAVA_VERSION
ARG JVM_TYPE
ARG JVM_HEAP
ARG GO_MIGRATE_VERSION
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libgomp1 \
curl \
&& apt-get clean
# Set environment variables
ENV LANG=C.UTF-8
ENV LD_LIBRARY_PATH=/app/libs:/usr/local/wasmer/lib
# Set the working directory
WORKDIR /app
# Install JRE
RUN JAVA_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "aarch64"; else echo -n "x64"; fi ) && \
curl -sLo - https://api.adoptium.net/v3/binary/version/jdk-${JAVA_VERSION}/${TARGETOS}/${JAVA_ARCH}/jre/${JVM_TYPE}/${JVM_HEAP}/eclipse | \
tar -C /usr/local -xzf - && \
ln -s /usr/local/jdk-* /usr/local/java
# Install DB migration tool
RUN GO_MIRGATE_ARCH=$( if [ "$TARGETARCH" = "arm64" ]; then echo -n "arm64"; else echo -n "amd64"; fi ) && \
curl -sLo - https://github.com/golang-migrate/migrate/releases/download/v$GO_MIGRATE_VERSION/migrate.${TARGETOS}-${GO_MIRGATE_ARCH}.tar.gz | \
tar -C /usr/local/bin -xzf - migrate
# Copy Wasmer shared libraries to the runtime container
COPY --from=full-builder /usr/local/wasmer/lib/libwasmer.so /usr/local/wasmer/lib/libwasmer.so
# Copy the build artifacts from the builder stage
COPY --from=full-builder /app/build /app
# Copy the db migration files
COPY --from=full-builder /app/core/go/db /app/db
# Add tools we installed to the path
ENV PATH=$PATH:/usr/local/java/bin
# Define the entry point for running the application
ENTRYPOINT [ \
"java", \
"-Djna.library.path=/app/libs", \
"-jar", \
"/app/libs/paladin.jar" \
]