-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dockerfile
406 lines (313 loc) · 15 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#
# MetaCall Install Script by Parra Studios
# Cross-platform set of scripts to install MetaCall infrastructure.
#
# Copyright (C) 2016 - 2024 Vicente Eduardo Ferrer Garcia <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
ARG METACALL_INSTALL_CERTS=certificates_local
FROM scratch AS testing
# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
maintainer.name="Vicente Eduardo Ferrer Garcia" \
maintainer.address="[email protected]" \
vendor="MetaCall Inc." \
version="0.1"
# Proxy certificates
FROM metacall/install_nginx AS certificates_local
# Remote certificates
FROM debian:bookworm-slim AS certificates_remote
RUN mkdir -p /etc/ssl/certs/
FROM ${METACALL_INSTALL_CERTS} AS certificates
# Debian Base (root)
FROM debian:bookworm-slim AS debian_root
ENV METACALL_INSTALL_DEBUG=1
COPY --from=certificates /etc/ssl/certs/ /etc/ssl/certs/
COPY test/ /test/
# Install dependencies and set up a sudo user without password
RUN apt-get update \
&& apt-get install -y --no-install-recommends sudo curl wget ca-certificates \
&& apt-get clean && rm -rf /var/lib/apt/lists/ \
&& printf "\nca_directory=/etc/ssl/certs" | tee -a /etc/wgetrc \
&& update-ca-certificates \
&& adduser --disabled-password --gecos "" user \
&& usermod -aG sudo user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R user /test \
&& chmod -R 700 /test
# Debian Base (user)
FROM debian_root AS debian_user
USER user
# Test install debian with root and wget from path
FROM debian_root AS test_debian_root_wget_from_path
RUN wget https://github.com/metacall/distributable-linux/releases/download/v0.7.0/metacall-tarball-linux-amd64.tar.gz \
&& wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash -s -- --from-path /metacall-tarball-linux-amd64.tar.gz \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Debian with root and curl
FROM debian_root AS test_debian_root_curl
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test certificates in Debian with root (comparing against <!doctype html> in buffer format)
FROM test_debian_root_curl AS test_debian_root_certificates
RUN export WEB_RESULT="`printf 'load py /test/script.py\ninspect\ncall fetch_https(\"www.google.com\")\nexit' | metacall`" \
&& export WEB_BUFFER="[\n 60, 33, 100, 111, 99,\n 116, 121, 112, 101, 32,\n 104, 116, 109, 108, 62\n]" \
&& [ -z "${WEB_RESULT##*$WEB_BUFFER*}" ] || exit 1
# Test install Debian with root and wget
FROM debian_root AS test_debian_root_wget
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Debian without root and curl
FROM debian_user AS test_debian_user_curl
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test uninstall Debian without root and curl
FROM test_debian_user_curl AS test_debian_user_curl_uninstall
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh \
| bash -s -- --uninstall \
&& [ ! -f "/usr/local/bin/metacall" ]
# Test uninstall Debian without root and curl, checking if it preserves existing files
FROM debian_user AS test_debian_user_curl_uninstall_existing_files
RUN sudo mkdir -p /gnu \
&& curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)' \
&& curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh \
| bash -s -- --uninstall \
&& [ ! -f "/usr/local/bin/metacall" ] \
&& [ -d /gnu ]
# TODO:
# When implementing timestamp support:
#
# Create a test that has a /gnu folder, then install metacall, then update the mtime of a random file
# from metacall installation, then uninstall and then verify that /gnu and the random file that has been
# update are still present after the uninstall process
# Test certificates in Debian with user (comparing against <!doctype html> in buffer format)
FROM test_debian_user_curl AS test_debian_user_certificates
RUN export WEB_RESULT="`printf 'load py /test/script.py\ninspect\ncall fetch_https(\"www.google.com\")\nexit' | metacall`" \
&& export WEB_BUFFER="[\n 60, 33, 100, 111, 99,\n 116, 121, 112, 101, 32,\n 104, 116, 109, 108, 62\n]" \
&& [ -z "${WEB_RESULT##*$WEB_BUFFER*}" ] || exit 1
# Test install Debian without root and wget
FROM debian_user AS test_debian_user_wget
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test reinstall Debian without root and wget
FROM test_debian_user_wget AS test_debian_user_wget_reinstall
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash -s -- --update \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test pip installation
FROM test_debian_user_wget AS test_debian_user_pip
RUN metacall pip3 install -r /test/requirements.txt \
&& metacall /test/requirements.py | grep '123456'
# Test npm installation
FROM test_debian_user_wget AS test_debian_user_npm
WORKDIR /test
RUN metacall npm install \
&& metacall /test/package.js | grep 'eyJhbGciOiJIUzI1NiJ9.eWVldA.bS3dTiCfusUIIqeH3484ByiBZC_cH0y8G5vonpPdqXA'
# Test PYTHONPATH
FROM test_debian_user_wget AS test_debian_user_pythonpath
RUN metacall /test/async.py | grep 'Async Done'
# Fedora Base (root)
FROM fedora:latest AS fedora_root
ENV METACALL_INSTALL_DEBUG=1
COPY --from=certificates /etc/ssl/certs/ /etc/pki/ca-trust/source/anchors/
COPY test/ /test/
# Install dependencies and set up a sudo user without password
RUN dnf update -y \
&& dnf install -y sudo curl wget ca-certificates findutils util-linux \
&& dnf clean all \
&& printf "\nca_directory=/etc/ssl/certs" | tee -a /etc/wgetrc \
&& update-ca-trust extract \
&& adduser user \
&& usermod -aG wheel user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R user /test \
&& chmod -R 700 /test
# Fedora Base (user)
FROM fedora_root AS fedora_user
USER user
# Test install Fedora with root and curl
FROM fedora_root AS test_fedora_root_curl
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Fedora with root and wget
FROM fedora_root AS test_fedora_root_wget
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Fedora without root and curl
FROM fedora_user AS test_fedora_user_curl
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Fedora without root and wget
FROM fedora_user AS test_fedora_user_wget
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test uninstall Fedora
FROM test_fedora_user_wget AS test_fedora_user_wget_uninstall
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh \
| sh -s -- --uninstall \
&& [ ! -f "/usr/local/bin/metacall" ]
# Alpine Base (root)
FROM alpine:latest AS alpine_root
ENV METACALL_INSTALL_DEBUG=1
COPY --from=certificates /etc/ssl/certs/ /etc/ssl/certs/
COPY test/ /test/
# Install dependencies and set up a sudo user without password
RUN apk update \
&& apk add --no-cache sudo curl wget ca-certificates \
&& rm -rf /var/cache/apk/* \
&& printf "\nca_directory=/etc/ssl/certs" | tee -a /etc/wgetrc \
&& update-ca-certificates \
&& adduser --disabled-password --gecos "" user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R user /test \
&& chmod -R 700 /test
# Alpine Base (user)
FROM alpine_root AS alpine_user
USER user
# Test install Alpine with root and curl
FROM alpine_root AS test_alpine_root_curl
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Alpine with root and wget
FROM alpine_root AS test_alpine_root_wget
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Alpine without root and curl
FROM alpine_user AS test_alpine_user_curl
RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test install Alpine without root and wget
FROM alpine_user AS test_alpine_user_wget
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test update Alpine
FROM test_alpine_user_wget AS test_alpine_user_wget_update
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh \
| sh -s -- --update \
| grep 'MetaCall has been installed'
# Test uninstall Alpine
FROM test_alpine_user_wget AS test_alpine_user_wget_uninstall
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh \
| sh -s -- --uninstall \
&& [ ! -f "/usr/local/bin/metacall" ]
# BusyBox Base
FROM busybox:stable-uclibc AS test_busybox
ENV METACALL_INSTALL_DEBUG=1
# Busybox wget fails with self signed certificates so we avoid the tests
FROM test_busybox AS busybox_fail_certificates_local
# Test install BusyBox fail due to lack of SSL implementation in wget (if it fails, then the test passes)
FROM test_busybox AS busybox_fail_certificates_remote
RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
|| if [ $? -ne 0 ]; then exit 0; else exit 1; fi
FROM busybox_fail_${METACALL_INSTALL_CERTS} AS test_busybox_fail
# BusyBox Base (with sources)
FROM test_busybox AS test_busybox_base
COPY test/ /test/
# Busybox wget fails with self signed certificates so we avoid the tests
FROM test_busybox_base AS busybox_without_certificates_local
FROM busybox_without_certificates_local AS busybox_uninstall_without_certificates_local
# Test install BusyBox without certificates
FROM test_busybox_base AS busybox_without_certificates_remote
RUN wget --no-check-certificate -O - https://raw.githubusercontent.com/metacall/install/master/install.sh \
| sh -s -- --no-check-certificate \
&& sh /usr/local/bin/metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*' \
&& printf "load mock test.mock\ninspect\nexit" \
| metacall \
| grep -e 'function three_str(a_str, b_str, c_str)'
# Test uninstall BusyBox without certificates
FROM busybox_without_certificates_remote AS busybox_uninstall_without_certificates_remote
RUN wget --no-check-certificate -O - https://raw.githubusercontent.com/metacall/install/master/install.sh \
| sh -s -- --no-check-certificate --uninstall \
&& [ ! -f "/usr/local/bin/metacall" ]
# Test install BusyBox
FROM busybox_without_${METACALL_INSTALL_CERTS} AS test_busybox_without_certificates
# Test uninstall BusyBox
FROM busybox_uninstall_without_${METACALL_INSTALL_CERTS} AS test_busybox_uninstall_without_certificates