-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.Containerfile
249 lines (180 loc) · 6.5 KB
/
build.Containerfile
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
################################################################################
## START : EDIT HERE : START ##
################################################################################
ARG rust_ver="1.82-slim"
ARG platform_contracts_count="3"
ARG protocol_contracts_count="7"
ARG test_network_build_profile="test_nets_release"
ARG test_network_max_binary_size="5M"
ARG production_network_build_profile="production_nets_release"
ARG production_network_max_binary_size="5M"
ARG cosmwasm_capabilities="cosmwasm_1_1,cosmwasm_1_2,iterator,neutron,staking,\
stargate"
################################################################################
## END : EDIT HERE : END ##
################################################################################
ARG cargo_target_dir="/target/"
FROM docker.io/library/rust:${rust_ver:?} AS builder-base
ARG rust_ver
LABEL rust_ver="${rust_ver:?}"
VOLUME ["/artifacts/"]
ARG cargo_target_dir
ENV CARGO_TARGET_DIR="${cargo_target_dir:?}"
WORKDIR "/"
RUN "$("rustup" "which" "rustc")" \
--version \
>"/rust-version.txt"
RUN ["mkdir", "-m", "0555", "/build/"]
RUN ["mkdir", "-m", "0555", "/build-profiles/"]
RUN ["mkdir", "-m", "0555", "/configuration/"]
RUN ["mkdir", "-m", "0755", "/target/"]
RUN ["mkdir", "-m", "0755", "/temp-artifacts/"]
ENTRYPOINT ["sh", "-e", "/build/build.sh"]
RUN ["rustup", "target", "add", "wasm32-unknown-unknown"]
ARG platform_contracts_count
ARG protocol_contracts_count
ARG test_network_build_profile
ARG test_network_max_binary_size
ARG production_network_build_profile
ARG production_network_max_binary_size
ARG cosmwasm_capabilities
RUN "printf" \
"%d" \
"${platform_contracts_count:?}" \
>"/configuration/platform-contracts-count"
RUN "printf" \
"%d" \
"${protocol_contracts_count:?}" \
>"/configuration/protocol-contracts-count"
RUN "printf" \
"%s" \
"${test_network_build_profile:?}" \
>"/build-profiles/test-net"
RUN "printf" \
"%s" \
"${test_network_max_binary_size:?}" \
>"/configuration/test-net-max-binary-size"
RUN "printf" \
"%s" \
"${production_network_build_profile:?}" \
>"/build-profiles/production-net"
RUN "printf" \
"%s" \
"${production_network_max_binary_size:?}" \
>"/configuration/production-net-max-binary-size"
RUN "printf" \
"%s" \
"${cosmwasm_capabilities:?}" \
>"/configuration/cosmwasm_capabilities"
RUN --mount=type=cache,target="/var/cache/apt",sharing="locked" \
--mount=type=cache,target="/var/lib/apt",sharing="locked" \
["apt", "update"]
RUN --mount=type=cache,target="/var/cache/apt",sharing="locked" \
--mount=type=cache,target="/var/lib/apt",sharing="locked" \
["apt", "install", "--yes", "coreutils", "git", "jq", "sed", "tar", "wget"]
ARG binaryen_ver="version_117"
LABEL binaryen_ver="${binaryen_ver:?}"
RUN "echo" \
"${binaryen_ver}" \
>"/binaryen-version.txt"
RUN --mount=type=cache,id="${binaryen_ver:?}",target="/binaryen/",sharing="locked" \
"[" "-f" "/binaryen/binaryen.tar.gz" "]" || \
"wget" "-O" "/binaryen/binaryen.tar.gz" "https://github.com/WebAssembly/\
binaryen/releases/download/${binaryen_ver:?}/binaryen-${binaryen_ver:?}-x86_64-\
linux.tar.gz"
RUN --mount=type=cache,id="${binaryen_ver:?}",target="/binaryen/",sharing="locked" \
"[" "-d" "/binaryen/binaryen" "]" || \
( \
cd "/binaryen/" && \
"tar" "-xf" "./binaryen.tar.gz" && \
"mv" "./binaryen-${binaryen_ver:?}" "./binaryen" \
)
RUN --mount=type=cache,id="${binaryen_ver:?}",target="/binaryen/",sharing="locked",readonly \
["cp", "/binaryen/binaryen/bin/wasm-opt", "/usr/bin/"]
RUN ["cargo", "install", "--jobs", "1", "--force", "cosmwasm-check"]
FROM builder-base AS builder
RUN --mount=type=bind,source="./",target="/code/",readonly \
cd "/code/" && \
described="$("git" "describe" --tags)" && \
readonly described && \
latest_tag="$("git" "describe" --tags --abbrev="0")" && \
readonly latest_tag && \
tag_commit="$(\
"git" \
"show-ref" \
"${latest_tag:?}" \
--abbrev \
--hash \
--tags\
)" && \
readonly tag_commit && \
"printf" \
"tag=%s / %s" \
"${tag_commit:?}" \
"${described:?}" \
>"/release-version.txt"
ARG check_dependencies_updated="true"
ENV CHECK_DEPENDENCIES_UPDATED="${check_dependencies_updated:?}"
LABEL check_container_dependencies="${check_dependencies_updated:?}"
RUN --mount=type=bind,source="./tools/",target="/tools/",readonly \
case "${check_dependencies_updated:?}" in \
("false") ;; \
("true") \
"cd" "/tools/" && \
"cargo" "update" --locked && \
"cargo" "fetch" --locked \
;; \
(*) \
"echo" "Build argument \"check_dependencies_updated\" must be a boolean value!" && \
exit 1 \
;; \
esac
RUN --mount=type=bind,source="./platform/",target="/platform/",readonly \
--mount=type=bind,source="./tools/",target="/tools/",readonly \
case "${check_dependencies_updated:?}" in \
("false") ;; \
("true") \
"cd" "/platform/" && \
"cargo" "update" --locked && \
"cargo" "fetch" --locked \
;; \
(*) \
"echo" "Build argument \"check_dependencies_updated\" must be a boolean value!" && \
exit 1 \
;; \
esac
RUN --mount=type=bind,source="./platform/",target="/platform/",readonly \
--mount=type=bind,source="./protocol/",target="/protocol/",readonly \
--mount=type=bind,source="./tools/",target="/tools/",readonly \
case "${check_dependencies_updated:?}" in \
("false") ;; \
("true") \
"cd" "/protocol/" && \
"cargo" "update" --locked && \
"cargo" "fetch" --locked \
;; \
(*) \
"echo" "Build argument \"check_dependencies_updated\" must be a boolean value!" && \
exit 1 \
;; \
esac
COPY --chmod="0555" "./tools/" "/tools/"
ARG cargo_target_dir
RUN --mount=type=tmpfs,target="${cargo_target_dir:?}" \
[ \
"cargo", \
"install", \
"--jobs", "1", \
"--locked", \
"--path", "/tools/cargo-each/" \
]
COPY --chmod="0555" "./scripts/build-and-optimize.sh" "/build/build.sh"
COPY --chmod="0555" "./.cargo/" "/.cargo/"
FROM builder AS platform-builder-base
COPY --chmod="0555" "./platform/" "/platform/"
FROM platform-builder-base AS platform-builder
WORKDIR "/platform/"
FROM platform-builder-base AS protocol-builder
VOLUME ["/build-configuration/"]
WORKDIR "/protocol/"
COPY --chmod="0555" "./protocol/" "/protocol/"