forked from LayerZero-Labs/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
193 lines (162 loc) · 6.64 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
193
# We will alow consumers to specify the node version in case we want
# to test under different versions (since we cannot control users environment)
#
# There is nothing wrong with 18.16.0 except for a tiny issue
# in docker compose - a segmentation fault that happens
# when we try to use a dynamic import in our tests (affecting both mocha & jest)
#
# The issue has been described here https://github.com/jestjs/jest/issues/12286
# And relates to this node issue here https://github.com/nodejs/node/issues/43205
#
# This issue does not affect users, it's only related to the test runner
# so the code will still work on node 18.16.0
ARG NODE_VERSION=20.10.0
# We will allow consumers to override the default base image
#
# This will allow CI environments to supply the prebuilt base image
# while not breaking the flow for local development
#
# Local development does not by default have access to GHCR and would require
# an additonal step (docker login). While this step is easy, it is still nicer
# to provide a transiton period during which the local flow remains unchanged
# and the base image is built locally
#
# The CI environment will use base images from https://github.com/LayerZero-Labs/devtools/pkgs/container/devtools-dev-base
# e.g. ghcr.io/layerzero-labs/devtools-dev-base:main
ARG BASE_IMAGE=base
# We will provide a way for consumers to override the default EVM node image
#
# This will allow CI environments to supply the prebuilt EVM node image
# while not breaking the flow for local development
ARG EVM_NODE_IMAGE=node-evm-hardhat
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
#
# Base node image with just the build tools
#
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM node:$NODE_VERSION as base
WORKDIR /app
# We'll add an empty NPM_TOKEN to suppress any warnings
ENV NPM_TOKEN=
ENV PATH "/root/.foundry/bin:$PATH"
ENV NPM_CONFIG_STORE_DIR=/pnpm
# Update the system packages
RUN apt-get update
# Add required packages
RUN apt-get install --yes \
# expect is a utility that can be used to test CLI scripts
#
# See a tutorial here https://www.baeldung.com/linux/bash-interactive-prompts
expect
# Install foundry
RUN curl -L https://foundry.paradigm.xyz | bash
RUN foundryup
# Install docker
RUN curl -sSL https://get.docker.com/ | sh
# Enable corepack, new node package manager manager
#
# See more here https://nodejs.org/api/corepack.html
RUN corepack enable
# Output versions
RUN node -v
RUN pnpm -v
RUN git --version
RUN forge --version
RUN anvil --version
RUN chisel --version
RUN cast --version
RUN docker compose version
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
#
# Image that prepares the project for development
#
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM $BASE_IMAGE as development
ENV NPM_CONFIG_STORE_DIR=/pnpm
ENV NPM_CONFIG_PACKAGE_IMPORT_METHOD=copy
WORKDIR /app
COPY pnpm-*.yaml .npmrc ./
# Get the node_modules patches since we need them for installation
COPY patches/ patches/
RUN \
# Mount pnpm store
--mount=type=cache,id=pnpm-store,target=/pnpm \
# Fetch dependencies to the pnpm store based on the lockfile
pnpm fetch --prefer-offline --frozen-lockfile
COPY . .
RUN \
# Mount pnpm store
--mount=type=cache,id=pnpm-store,target=/pnpm \
# Install dependencies (fail if we forgot to update the lockfile)
pnpm install --recursive --offline --frozen-lockfile
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
#
# Image that builds a hardhat EVM node
#
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM development AS node-evm-hardhat-builder
# Build the node
RUN pnpm build --filter @layerzerolabs/test-evm-node
# Isolate the project
RUN --mount=type=cache,id=pnpm-store,target=/pnpm \
pnpm --filter @layerzerolabs/test-evm-node deploy --prod /build
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
#
# Image that runs a hardhat EVM node
#
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM node:$NODE_VERSION-alpine AS node-evm-hardhat
WORKDIR /app
# Update system packages
RUN apk update
# Install curl for healthcheck
RUN apk add curl --no-cache
# Get the built code
#
# By default we'll get it from the dist folder
# but for e.g. next we want to grab it from dist/.next/standalone
COPY --from=node-evm-hardhat-builder /build /app
# Enable corepack, new node package manager manager
#
# See more here https://nodejs.org/api/corepack.html
RUN corepack enable
# We want to keep the internals of the EVM node images encapsulated so we supply the healthcheckk as a part of the definition
HEALTHCHECK --interval=2s --retries=20 CMD curl -f http://0.0.0.0:8545 || exit 1
# Run the shit
ENTRYPOINT pnpm start
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
#
# Image that runs a hardhat EVM node
#
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM $EVM_NODE_IMAGE AS node-evm
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
#
# Image that represents a user machine
#
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM $BASE_IMAGE AS user