-
Notifications
You must be signed in to change notification settings - Fork 5
/
Earthfile
503 lines (449 loc) · 12.7 KB
/
Earthfile
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# Earthfile
VERSION 0.8
FROM alpine:3.20
ARG --global base_image=cimg/clojure:1.10
ARG --global clojure_version=1.10.1.727
# https://github.com/clj-kondo/clj-kondo/releases
ARG --global kondo_version=2024.08.29
# https://nodejs.org/en/download
ARG --global NODE_MAJOR=20
# https://www.npmjs.com/package/npm?activeTab=versions
ARG --global npm_version=10.8.0
# https://github.com/tilt-dev/tilt/releases
ARG --global tilt_version=0.33.20
# ARG repo=duck1123
# ARG project=dinsro
ARG --global version=latest
ARG --global dev_group=circleci
ARG --global dev_user=circleci
ARG --global src_home=/usr/src/app
ARG --global data_dir=/var/lib/dinsro/data
ARG --global uid=3434
ARG --global gid=3434
WORKDIR /usr/src/app
EXPOSE_DOCKER_PORTS:
FUNCTION
# Main web interface
EXPOSE 3000/tcp
# nRepl interface (cljs)
EXPOSE 3333/tcp
# Main cljs devtools
EXPOSE 3691/tcp
# Tests
EXPOSE 3692/tcp
# Workspaces
EXPOSE 3693/tcp
# nRepl interface (clj)
EXPOSE 7000/tcp
# shadow-cljs watcher
EXPOSE 9630/tcp
IMPORT_JAR_DEPS:
FUNCTION
COPY --dir --chown=circleci --chmod=755 \
+jar-deps/.clojure \
+jar-deps/.deps.clj \
+jar-deps/.gitlibs \
+jar-deps/.m2 \
${USER_HOME}
COPY --dir --chown=root --chmod=755 \
+jar-deps/.clojure \
+jar-deps/.deps.clj \
+jar-deps/.gitlibs \
+jar-deps/.m2 \
/root
COPY --dir --chown=circleci +jar-deps/.cpcache .
INSTALL_BABASHKA:
FUNCTION
# FIXME: This always downloads the latest version, enable pinning
RUN curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install \
&& chmod +x install \
&& ./install \
&& rm -f install
INSTALL_BYOBU:
FUNCTION
RUN apt update && apt install -y \
byobu \
&& rm -rf /var/lib/apt/lists/*
INSTALL_FIREFOX:
FUNCTION
RUN apt update && apt install -y \
firefox-geckodriver \
&& rm -rf /var/lib/apt/lists/*
INSTALL_KONDO:
FUNCTION
RUN curl -sLO https://raw.githubusercontent.com/clj-kondo/clj-kondo/master/script/install-clj-kondo \
&& chmod +x install-clj-kondo \
&& echo Version: $kondo_version \
&& ./install-clj-kondo --version $kondo_version \
&& rm -f install-clj-kondo
# Assumes running as root
INSTALL_NODE:
FUNCTION
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt update \
&& apt install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g npm@${npm_version}
RUN npm install -g yarn
INSTALL_NOSCL:
FUNCTION
RUN curl -LJO "https://github.com/fiatjaf/noscl/releases/download/v0.6.0/noscl"
RUN mv noscl /usr/local/bin/noscl
RUN chmod +x /usr/local/bin/noscl
RUN mkdir -p /root/.config/noscl
INSTALL_TILT:
FUNCTION
RUN echo ${tilt_version}
RUN curl -fsSL "https://github.com/tilt-dev/tilt/releases/download/v${tilt_version}/tilt.${tilt_version}.linux.x86_64.tar.gz" \
| tar -xzv tilt \
&& sudo mv tilt /usr/local/bin/tilt
INSTALL_TILT_LATEST:
FUNCTION
RUN curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
all-images:
BUILD +support-images
BUILD +image
base-builder:
FROM ${base_image}
WORKDIR ${src_home}
ENV USER_HOME=/home/${dev_user}
USER root
DO +INSTALL_NODE
DO +INSTALL_BABASHKA
DO +INSTALL_KONDO
DO +INSTALL_NOSCL
RUN chown -R ${uid}:${gid} ${src_home}
RUN apt update && apt install -y \
sudo \
nmap \
tree \
&& rm -rf /var/lib/apt/lists/*
USER ${uid}
babashka-base:
FROM ${base_image}
WORKDIR ${src_home}
USER root
DO +INSTALL_BABASHKA
builder:
FROM +deps-builder
RUN mkdir -p classes data target
COPY --dir src/main src/notebooks src/notebook-utils src
USER root
RUN mkdir -p /var/lib/dinsro/data && chown -R ${uid}:${gid} /var/lib/dinsro/data
USER ${uid}
VOLUME ${data_dir}
COPY resources/docker/config.edn config.edn
COPY shadow-cljs.edn .
check:
FROM +src
COPY indentation.edn .
RUN bb check
ci:
BUILD +validate
BUILD +all-images
cert-downloader:
FROM babashka/babashka:latest
ARG repo=duck1123
ARG project=cert-downloader
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:${tag}
COPY resources/cert-downloader .
ENTRYPOINT ["bb", "bootstrap.clj"]
CMD ["bb", "bootstrap.clj"]
SAVE IMAGE --push ${EXPECTED_REF}
compile-frontend:
FROM +src
RUN bb compile-cljs
SAVE ARTIFACT resources
compile-production:
FROM +src
COPY --dir src/prod src/prod
COPY +compile-styles/* resources/main/public/
RUN bb compile-production
SAVE ARTIFACT classes
compile-styles:
FROM +deps-builder
COPY --dir src/styles src/styles
COPY semantic/src/theme.config semantic/src/theme.config
COPY semantic/src/site/globals/site.* semantic/src/site/globals/
RUN bb install-style-dependencies
RUN bb compile-styles
SAVE ARTIFACT resources/main/public/css/ css/
SAVE ARTIFACT resources/main/public/themes/ themes/
deps-builder:
FROM +script-builder
DO +IMPORT_JAR_DEPS
dev-image:
FROM +deps-builder
COPY --dir \
src \
site-defaults.edn \
semantic \
package.json \
shadow-cljs.edn \
.
COPY --dir resources/main resources/main
DO +EXPOSE_DOCKER_PORTS
VOLUME ${data_dir}
USER root
CMD ["bb", "dev-bootstrap"]
image-dev:
FROM +dev-image
ARG repo=duck1123
ARG project=dinsro
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:dev-${version}
SAVE IMAGE ${EXPECTED_REF}
devcards-image:
FROM +dev-sources-minimal
ARG repo=duck1123
ARG project=dinsro
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:devcards-${version}
COPY --dir resources/tilt resources
COPY --dir public .
CMD ["bb", "devcards-server"]
SAVE IMAGE --push ${EXPECTED_REF}
devspace-base:
ARG repo=duck1123
ARG project=devimage
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:${tag}
FROM +base-builder
USER root
DO +INSTALL_BYOBU
DO +INSTALL_TILT
RUN apt update && apt install -y \
bash-completion \
firefox-geckodriver \
inetutils-ping \
zsh \
&& rm -rf /var/lib/apt/lists/*
DO +IMPORT_JAR_DEPS
COPY --dir +node-deps/node_modules node_modules
RUN chsh -s /bin/zsh
RUN mkdir -p /root/.byobu
RUN echo "set -g default-shell /usr/bin/zsh\nset -g default-command /usr/bin/zsh" > /root/.byobu/.tmux.conf
SAVE IMAGE --push ${EXPECTED_REF}
dev-image-sources-base:
ARG watch_sources=true
ARG use_notebooks=false
FROM +dev-sources-minimal
USER root
RUN mkdir -p resources/main/public/css \
&& mkdir -p resources/main/public/js \
&& mkdir -p resources/main/public/themes \
&& chown -R $uid resources/main
IF [ "$watch_sources" = "true" ]
USER $uid
RUN --no-cache ls -al resources
RUN bb compile-cljs
END
HEALTHCHECK --start-period=600s CMD curl -f http://localhost:3000 || exit 1
DO +EXPOSE_DOCKER_PORTS
WORKDIR ${src_home}
VOLUME ${data_dir}
USER root
CMD ["bb", "dev-bootstrap"]
dev-image-sources:
ARG use_notebooks=false
ARG watch_sources=true
ARG repo=duck1123
ARG project=dinsro
ARG tag=latest
FROM +dev-image-sources-base \
--watch_sources=$watch_sources \
--use_notebooks=$use_notebooks
ARG EXPECTED_REF=${repo}/${project}:dev-sources-${version}
COPY --dir resources/main ${src_home}/resources
SAVE IMAGE ${EXPECTED_REF}
dev-sources:
FROM +deps-builder
COPY resources/docker/config.edn /etc/dinsro/config.edn
COPY --dir . ${src_home}
COPY --dir +node-deps/node_modules node_modules
DO +IMPORT_JAR_DEPS
dev-sources-minimal:
FROM +deps-builder
COPY resources/docker/config.edn /etc/dinsro/config.edn
COPY --dir src ${src_home}
COPY shadow-cljs.edn .
COPY --dir resources/workspaces ${src_home}/resources/workspaces
docs:
FROM +dev-sources-minimal
RUN bb docs
SAVE ARTIFACT target/doc docs
docs-image:
FROM babashka/babashka:latest
ARG repo=duck1123
ARG project=dinsro
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:docs-${version}
WORKDIR /usr/src/app
COPY resources/docs-server .
COPY --dir +docs/docs .
RUN ls -al
CMD ["bb", "serve.clj"]
SAVE IMAGE --push ${EXPECTED_REF}
eastwood:
FROM +dev-sources
RUN bb eastwood
fileserver:
FROM babashka/babashka:latest
ARG repo=duck1123
ARG project=lnd-fileserver
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:${tag}
COPY resources/fileserver .
RUN mkdir -p /mnt/lnd-data
CMD ["bb", "watch.clj", "/mnt/lnd-data"]
SAVE IMAGE --push ${EXPECTED_REF}
image:
FROM amazoncorretto:17-alpine
ARG repo=duck1123
ARG project=dinsro
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:${tag}
RUN echo ${EXPECTED_REF}
WORKDIR ${src_home}
VOLUME ${data_dir}
RUN mkdir -p src
COPY +jar/dinsro.jar dinsro.jar
COPY resources/docker/config.edn /etc/dinsro/config.edn
COPY --dir src/main src/notebooks src/notebook-utils src/shared src
COPY seed.edn .
CMD ["java", "-jar", "dinsro.jar"]
SAVE IMAGE --push ${EXPECTED_REF}
image-wait:
FROM +image
jar:
FROM +src
COPY --dir +compile-production/classes .
COPY +compile-styles/* resources/main/public/
COPY --dir resources/main/public/images resources/main/public/
COPY resources/main/*.conf resources/main
RUN bb compile-production-cljs
RUN bb package-jar
SAVE ARTIFACT target/dinsro-4.0.null.jar /dinsro.jar AS LOCAL target/dinsro.jar
jar-deps:
FROM +script-builder
USER root
RUN rm -rf ${USER_HOME}/.m2
RUN --mount=type=cache,target=/root/.clojure \
--mount=type=cache,target=/root/.gitlibs \
--mount=type=cache,target=/root/.m2 \
--mount=type=cache,target=/root/.deps.clj \
(bb display-path || bb display-path) \
&& bb init-bb \
&& cp -r /root/.clojure ${USER_HOME}/ \
&& cp -r /root/.deps.clj ${USER_HOME}/ \
&& cp -r /root/.gitlibs ${USER_HOME}/ \
&& cp -r /root/.m2 ${USER_HOME}/
USER ${uid}
SAVE ARTIFACT ${USER_HOME}/.clojure
SAVE ARTIFACT ${USER_HOME}/.deps.clj
SAVE ARTIFACT ${USER_HOME}/.gitlibs
SAVE ARTIFACT ${USER_HOME}/.m2
SAVE ARTIFACT .cpcache
kibit:
FROM +dev-sources
RUN bb kibit
kondo:
FROM +dev-sources
RUN bb kondo
lint:
BUILD +kondo
BUILD +eastwood
# BUILD +kibit
node-deps:
FROM +base-builder
COPY package.json semantic.json yarn.lock .
# RUN npx yarn add fomantic-ui --ignore-scripts
RUN npx yarn install --frozen-lockfile
SAVE ARTIFACT node_modules
nostream-build:
FROM node:18-alpine3.16
ARG NOSTREAM_BASE=resources/nostream/
WORKDIR /build
COPY \
${NOSTREAM_BASE}package.json \
${NOSTREAM_BASE}package-lock.json \
${NOSTREAM_BASE}knexfile.js \
.
COPY --dir ${NOSTREAM_BASE}migrations /build
RUN npm install -g knex@2.3.0
RUN npm install knex --quiet
RUN npm install --quiet
COPY ${NOSTREAM_BASE} .
RUN npm run build
SAVE ARTIFACT dist
nostream-image:
FROM node:18
ARG NOSTREAM_BASE=resources/nostream/
ARG NOSTREAM_IMAGE_BASE=resources/nostream-image/
ARG NOSTR_CONFIG_DIR=/home/node/.nostr
ARG repo=duck1123
ARG project=nostream
ARG tag=latest
ARG EXPECTED_REF=${repo}/${project}:${tag}
LABEL org.opencontainers.image.title="Nostr Typescript Relay"
LABEL org.opencontainers.image.source=https://github.com/Cameri/nostr-ts-relay
LABEL org.opencontainers.image.description="nostr-ts-relay"
LABEL org.opencontainers.image.authors="Ricardo Arturo Cabral Mejía"
LABEL org.opencontainers.image.licenses=MIT
WORKDIR /app
RUN apt update && apt install -y \
curl \
gnupg2 \
jq \
postgresql-client \
tree \
wait-for-it \
wget \
&& rm -rf /var/lib/apt/lists/*
COPY +nostream-build/dist .
RUN npm install --omit=dev --quiet
USER 1000:1000
COPY ${NOSTREAM_IMAGE_BASE}bootstrap.sh ${NOSTREAM_IMAGE_BASE}check-connection .
COPY --dir ${NOSTREAM_BASE}resources ${NOSTREAM_BASE}migrations ${NOSTREAM_BASE}knexfile.js .
RUN mkdir -p $NOSTR_CONFIG_DIR
CMD ["./bootstrap.sh"]
ENTRYPOINT ["./bootstrap.sh"]
SAVE IMAGE --push ${EXPECTED_REF}
script-builder:
FROM +base-builder
COPY package.json semantic.json yarn.lock .
COPY --dir +node-deps/node_modules node_modules
COPY --dir bb.edn build.clj deps.edn rollup.config.js .
COPY --dir src/babashka src/shared src
src:
FROM +builder
support-images:
BUILD +cert-downloader
BUILD +fileserver
BUILD +devspace-base
BUILD +devcards-image
BUILD +docs-image
test:
BUILD +test-clj
BUILD +test-cljs
test-clj:
FROM +test-sources
RUN bb test-clj
test-cljs:
FROM +test-sources
RUN bb test-cljs
test-sources:
FROM +src
USER root
DO +INSTALL_FIREFOX
USER ${uid}:${gid}
COPY --dir tests.edn bin .
COPY --dir src/test src
DO +IMPORT_JAR_DEPS
validate:
BUILD +check
BUILD +test
BUILD +lint