-
Notifications
You must be signed in to change notification settings - Fork 386
/
Earthfile
574 lines (493 loc) · 23.5 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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
ARG DOCKERHUB_AUTH=true
FROM ../..+earthly-integration-test-base --DOCKERHUB_AUTH=$DOCKERHUB_AUTH
RUN apk add --update --no-cache \
perl findutils
WORKDIR /test
all:
BUILD +ga
BUILD +experimental
ga:
BUILD ./autocompletion+test-all
BUILD ./with-docker+all
BUILD ./with-docker-compose+all
BUILD ./dockerfile+test
BUILD ./dockerfile2/subdir+test
BUILD ./version+test-all
BUILD +privileged-test
BUILD +copy-test
BUILD +cache-test
BUILD +git-clone-test
BUILD +builtin-args-test
BUILD +config-test
BUILD +excludes-test
BUILD +secrets-test
BUILD +build-arg-test
BUILD +lc-test
BUILD +from-expose-test
BUILD +scratch-test
BUILD +build-earthly-test
BUILD +host-bind-test
BUILD +remote-test
BUILD +transitive-args-test
BUILD +transitive-args-test2
BUILD +non-transitive-args-test
BUILD +star-test
BUILD +dockerfile-test
BUILD +fail-test
BUILD +fail-push-test
BUILD +allow-privileged-test
BUILD +allow-privileged-import-test
BUILD +reject-privileged-import-test
BUILD +push-test
BUILD +gen-dockerfile-test
BUILD +chown-test
BUILD +dotenv-test
BUILD +env-test
BUILD +no-cache-local-artifact-test
BUILD +empty-git-test
BUILD +escape-test
BUILD +escape-dir-test
BUILD +fail-invalid-artifact-test
BUILD +target-first-line
BUILD +end-comment
BUILD +if-exists
BUILD +file-copying
BUILD +run-no-cache
BUILD +save-artifact-after-push
BUILD +push-build
BUILD +build-arg-repeat
BUILD +if
BUILD +first-command
BUILD +platform-output
BUILD +command
BUILD +duplicate
BUILD +reserved
BUILD +quotes-test
BUILD +new-args
BUILD +import
BUILD +infinite-recursion
BUILD +from-dockerfile-arg
BUILD +cache-mount-arg
experimental:
BUILD ./dind-auto-install+all
ast-test-input:
FROM alpine:3.13
COPY ./*.earth ./
COPY ./with-docker/Earthfile ./with-docker.earth
COPY ./with-docker-compose/Earthfile ./with-docker-compose.earth
SAVE ARTIFACT ./*.earth
privileged-test:
DO +RUN_EARTHLY --earthfile=privileged.earth --extra_args="--allow-privileged" --target=+test
copy-test:
RUN mkdir -p in/sub/1 in/sub/2 && \
echo "root" > in/root && \
echo "1" > in/sub/1/file && \
echo "2" > in/sub/2/file && \
echo "sub" > in/sub/file
DO +RUN_EARTHLY --earthfile=copy.earth
RUN echo "output.txt" > .earthignore
DO +RUN_EARTHLY --earthfile=copy.earth --extra_args="--verbose" --post_command="2>output.txt"
RUN cat output.txt
RUN cat output.txt | grep 'sent data for in/root (5 bytes)'
RUN cat output.txt | grep 'transfered 4 file(s) for context . (261 bytes, 8 file/dir stats)'
cache-test:
# Test that a file can be passed between runs through the mounted cache.
DO +RUN_EARTHLY --earthfile=cache1.earth --target=+test-pass-file --use_tmpfs=false
DO +RUN_EARTHLY --earthfile=cache2.earth --target=+test-pass-file --use_tmpfs=false
# Test that a change to the contents of the mount does not cause a cache bust if everything else
# is the same.
DO +RUN_EARTHLY --earthfile=cache1.earth --target=+test-no-bust-on-change --use_tmpfs=false
DO +RUN_EARTHLY --earthfile=cache2.earth --target=+test-no-bust-on-change --use_tmpfs=false # make a change
DO +RUN_EARTHLY --earthfile=cache1.earth --target=+test-no-bust-on-change --use_tmpfs=false \
--post_command=">output.txt 2>&1" # check that all is still cached if re-running the prev version
RUN cat output.txt
RUN cat output.txt | grep '\*cached\* --> RUN echo hey'
git-clone-test:
DO +RUN_EARTHLY --earthfile=git-clone.earth --target=+test
builtin-args-test:
DO +RUN_EARTHLY --earthfile=builtin-args.earth --target=+builtin-args-test
config-test:
DO +RUN_EARTHLY --earthfile=config.earth --target=+test
excludes-test:
RUN touch exclude-me.txt
RUN touch do-not-exclude-me.txt
RUN echo 'exclude-me.txt' > .earthignore
DO +RUN_EARTHLY --earthfile=excludes.earth --target=+test
secrets-test:
ENV SECRET1=foo
ENV SECRET2=wrong
RUN echo -n "secretfilecontents" > /root/my-secret-file
DO +RUN_EARTHLY \
--earthfile=secrets.earth \
--extra_args="--secret SECRET1 --secret SECRET2=bar --secret-file SECRET3=~/my-secret-file" \
--target=+test
DO +RUN_EARTHLY \
--earthfile=secrets.earth \
--extra_args="--secret SECRET1 --secret SECRET2=bar" \
--target=+test \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /unable to lookup secret SECRET3: not found/;'"
build-arg-test:
DO +RUN_EARTHLY --earthfile=build-arg.earth
lc-test:
DO +RUN_EARTHLY --earthfile=lc.earth --target=+test
from-expose-test:
DO +RUN_EARTHLY --earthfile=from-expose.earth --extra_args="--no-output" --target=+test
scratch-test:
DO +RUN_EARTHLY --earthfile=scratch-test.earth --extra_args="--no-output" --target=+test
build-earthly-test:
# Test that build.earth is supported.
COPY config.earth ./build.earth
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- +test
host-bind-test:
RUN mkdir /bind-test
RUN echo "a" > /bind-test/a.txt
DO +RUN_EARTHLY --earthfile=host-bind.earth --target=+test
RUN test -f /bind-test/b.txt
RUN cat /bind-test/b.txt
remote-test:
ENV GIT_URL_INSTEAD_OF="https://github.com/=git@github.com:"
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- --no-output github.com/earthly/hello-world:main+hello
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- --no-output github.com/earthly/test-remote/privileged:main+locally && \
ls /tmp/hostname.3d4b1831-c07e-4b2d-805e-2b8ce578bb50
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- --no-output github.com/earthly/test-remote/builtin-args:main+test
transitive-args-test:
DO +RUN_EARTHLY --earthfile=transitive-args.earth --extra_args="--build-arg SOMEARG=xyz" --target=+test
RUN ls
RUN test -f ./abc
RUN test -f ./xyz
RUN test ! -f ./default
RUN cat ./abc | grep abc
RUN cat ./xyz | grep xyz
transitive-args-test2:
DO +RUN_EARTHLY --earthfile=transitive-args.earth --target=+test
RUN ls
RUN test -f ./abc && test -f ./default
RUN cat ./abc | grep abc
RUN cat ./default | grep default
non-transitive-args-test:
COPY non-transitive-args1.earth ./Earthfile
COPY non-transitive-args2.earth ./subdir/Earthfile
# Should not override if transitive and corssing project boundaries.
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- --build-arg SOMEARG=def +test
RUN ls ./subdir
RUN test -f ./subdir/default && test ! -f ./subdir/def && test ! -f ./subdir/abc
RUN rm ./subdir/default
# Should override, if override is direct.
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- --build-arg SOMEARG=xyz ./subdir+arg-target
RUN ls ./subdir
RUN test -f ./subdir/xyz && test ! -f ./subdir/default
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- +direct
RUN ls ./subdir
RUN test -f ./subdir/direct && test ! -f ./subdir/default
star-test:
RUN touch a.txt b.txt c.nottxt
DO +RUN_EARTHLY --earthfile=star.earth --target=+test
# TODO: This does not pass.
star-test-todo:
RUN touch a.txt b.txt c.nottxt
DO +RUN_EARTHLY --earthfile=star.earth --target=+test --use_tmpfs=false
RUN echo "a change" > c.nottxt
DO +RUN_EARTHLY --earthfile=star.earth --target=+test --use_tmpfs=false \
--post_command=">output.txt"
RUN cat output.txt
RUN cached_lines=$(cat output.txt | grep cached | wc -l); \
echo "cached_lines=$cached_lines"; \
test "$cached_lines" == "6"
dockerfile-test:
COPY dockerfile/* ./
RUN --privileged \
--entrypoint \
--mount=type=tmpfs,target=/tmp/earthly \
-- --no-output +test
fail-test:
# test that an error code is correctly returned
DO +RUN_EARTHLY --earthfile=fail.earth --should_fail=true --target=+test
# test that the 'failed with exit code' text is printed out
DO +RUN_EARTHLY --earthfile=fail.earth --target=+test \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /this-will-fail/;'"
allow-privileged-test:
# test that privileged-tasks in remote repos dont run
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-privileged-in-remote-repo-triggered-by-from-locally
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-privileged-in-remote-repo-triggered-by-from-privileged
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-privileged-in-remote-repo-triggered-by-copy-locally
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-privileged-in-remote-repo-triggered-by-copy-privileged
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-privileged-in-remote-repo-triggered-by-build-locally
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-privileged-in-remote-repo-triggered-by-build-privileged
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --should_fail=true --extra_args="--allow-privileged" -target=+reject-dedup
# test allowed-privileged tasks in remote repos work
DO +RUN_EARTHLY --earthfile=allow-privileged.earth --extra_args="--allow-privileged" --target=+allow-all
allow-privileged-import-test:
RUN mkdir -p a/really/deep/subdir && echo "subdirprivileged:
FROM alpine:latest
RUN --privileged cat /proc/self/status | grep CapEff > output
SAVE ARTIFACT output proc-status
" > a/really/deep/subdir/Earthfile
DO +RUN_EARTHLY --earthfile=allow-privileged-import.earth --extra_args="--allow-privileged" --target=+test
reject-privileged-import-test:
DO +RUN_EARTHLY --earthfile=reject-privileged-import.earth --should_fail=true --extra_args="--allow-privileged" --target=+test-reject-copy
DO +RUN_EARTHLY --earthfile=reject-privileged-import.earth --should_fail=true --extra_args="--allow-privileged" --target=+test-reject-cmd
fail-push-test:
# test that an error code is correctly returned
DO +RUN_EARTHLY --earthfile=fail.earth --should_fail=true --extra_args="--push" --target=+test-push
# test that the 'failed with exit code' text is printed out
DO +RUN_EARTHLY --earthfile=fail.earth --extra_args="--push" --target=+test-push \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /this-too-will-fail/;'"
fail-invalid-artifact-test:
# test that the artifact fails to be copied
DO +RUN_EARTHLY --earthfile=fail-invalid-artifact.earth --should_fail=true --target="--artifact +test/foo /tmp/stuff"
# test that we echo a message containing the invalid artifact name
DO +RUN_EARTHLY --earthfile=fail-invalid-artifact.earth --target="--artifact +test/foo /tmp/stuff" \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /\\\+test\\\/foo/;'"
push-test:
DO +RUN_EARTHLY --earthfile=push.earth --target=+push-test \
--post_command="2>&1 | grep 'Use earthly --push to enable pushing'"
DO +RUN_EARTHLY --earthfile=push.earth --extra_args="--push" --target=+push-test \
--post_command="2>&1 | grep 'hello world'"
private-image-test:
FROM earthly/private-test:latest
RUN --entrypoint echo hello world
gen-dockerfile-test:
DO +RUN_EARTHLY --earthfile=gen-dockerfile.earth --extra_args="--no-output" --target=+all
comments-test:
DO +RUN_EARTHLY --earthfile=comments.earth --extra_args="--no-output" --target=+test
chown-test:
RUN echo "test" > ./a.txt
DO +RUN_EARTHLY --earthfile=chown.earth --target=+test
dotenv-test:
RUN echo "TEST_ENV_1=abracadabra" >.env
RUN echo "TEST_ENV_2=foo" >>.env
RUN echo "TEST_ENV_3=bar" >>.env
DO +RUN_EARTHLY --earthfile=dotenv.earth --extra_args="--no-output" --target=+test
# Smoke test that no .env file does not result in an error.
RUN rm .env
DO +RUN_EARTHLY --earthfile=dotenv.earth --extra_args="--no-output" --target=+test-no-dotenv
env-test:
DO +RUN_EARTHLY --earthfile=env.earth --extra_args="--no-output" --target=+test
no-cache-local-artifact-test:
DO +RUN_EARTHLY --earthfile=no-cache-local-artifact.earth --use_tmpfs=false --extra_args="--no-cache" --target=+test
RUN mv file.txt old.txt
DO +RUN_EARTHLY --earthfile=no-cache-local-artifact.earth --use_tmpfs=false --extra_args="--no-cache" --target=+test
RUN ! diff file.txt old.txt
empty-git-test:
RUN git init
DO +RUN_EARTHLY --earthfile=empty-git.earth --extra_args="--no-output" --target=+test-empty
RUN git remote add origin https://github.com/earthly/earthly.git
DO +RUN_EARTHLY --earthfile=empty-git.earth --extra_args="--no-output" --target=+test-origin-no-hash
escape-test:
RUN printf "content" >file-with-+.txt
RUN printf "content" >regular-file.txt
DO +RUN_EARTHLY --earthfile=escape.earth
RUN test "test" == "$(cat ./still-+.txt)"
escape-dir-test:
RUN mkdir ./dir-with-+-in-it
COPY escape-dir2.earth ./dir-with-+-in-it/Earthfile
DO +RUN_EARTHLY --earthfile=escape-dir1.earth --extra_args="--no-output" --target=+test
eine-test-base:
FROM docker:19.03.12-dind
RUN apk --update --no-cache add git
COPY ../..+earthly/earthly /usr/local/bin/
ENV EARTHLY_BUILDKIT_IMAGE=earthly/buildkitd:dind-test
WORKDIR /test
eine-config-test:
FROM +eine-test-base
COPY config.earth ./Earthfile
WITH DOCKER --load earthly/buildkitd:dind-test=../../buildkitd+buildkitd
RUN earthly +test
END
eine-privileged-test:
FROM +eine-test-base
COPY privileged.earth ./Earthfile
WITH DOCKER --load earthly/buildkitd:dind-test=../../buildkitd+buildkitd
RUN earthly --allow-privileged +test
END
target-first-line:
DO +RUN_EARTHLY --earthfile=target-first-line.earth --extra_args="--no-output" --target=+test
end-comment:
DO +RUN_EARTHLY --earthfile=end-comment.earth --target=+test
if-exists:
DO +RUN_EARTHLY --earthfile=if-exists.earth --target=+save-exist-local
DO +RUN_EARTHLY --earthfile=if-exists.earth --target=+save-not-exist \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /save-not-exist/;'"
DO +RUN_EARTHLY --earthfile=if-exists.earth --target=+copy-not-exist \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /copy-not-exist/;'"
DO +RUN_EARTHLY --earthfile=if-exists.earth --target=+bad-wildcard-copy \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /bad-wildcard-copy/;'"
DO +RUN_EARTHLY --earthfile=if-exists.earth --target=+bad-wildcard-save \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /bad-wildcard-save/;'"
file-copying:
DO +RUN_EARTHLY --earthfile=file-copying.earth
RUN find out-glob -printf '%P\n' | sort > result-glob
RUN ls -la out-glob
RUN diff -ws expected-glob result-glob
RUN find out-dot -printf '%P\n' | sort > result-dot
RUN ls -la out-dot
RUN diff -ws expected-dot result-dot
RUN find out-dot-slash -printf '%P\n' | sort > result-dot-slash
RUN ls -la out-dot-slash
RUN diff -ws expected-dot-slash result-dot-slash
RUN find out-sub -printf '%P\n' | sort > result-sub
RUN ls -la out-sub
RUN diff -ws expected-sub result-sub
RUN find out-sub-glob -printf '%P\n' | sort > result-sub-glob
RUN ls -la out-sub-glob
RUN diff -ws expected-sub-glob result-sub-glob
RUN find out-dot-single -printf '%P\n' | sort > result-dot-single
RUN ls -la out-dot-single
RUN diff -ws expected-dot-single result-dot-single
RUN find out-rel-single -printf '%P\n' | sort > result-rel-single
RUN ls -la out-rel-single
RUN diff -ws expected-rel-single result-rel-single
RUN find out-src-dest-file-rename -printf '%P\n' | sort > result-src-dest-file-rename
RUN ls -la out-src-dest-file-rename
RUN diff -ws expected-src-dest-file-rename result-src-dest-file-rename
RUN find out-src-dest-dir-rename -printf '%P\n' | sort > result-src-dest-dir-rename
RUN ls -la out-src-dest-dir-rename
RUN diff -ws expected-src-dest-dir-rename result-src-dest-dir-rename
# Saving the root dir is not allowed. This should fail.
DO +RUN_EARTHLY --earthfile=file-copying.earth --should_fail=true --target=+test-dot-scratch
run-no-cache:
# Run twice to allow the second one to attempt to cache things
DO +RUN_EARTHLY --earthfile=run-no-cache.earth --use_tmpfs=false --target=+test
# Fail if we cached any of the motd2 lines, which are after the --no-cache
DO +RUN_EARTHLY --earthfile=run-no-cache.earth --use_tmpfs=false --target=+test \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=0} END {exit \\\$status} \\\$status=1 if /\\\*cached\\\* --> .* motd2/;'"
# Run twice to allow the second one to attempt to cache things
DO +RUN_EARTHLY --earthfile=run-no-cache.earth --use_tmpfs=false --target=+test-from
# Fail if we cached any of the COPY motd2 lines, which are after the --no-cache
DO +RUN_EARTHLY --earthfile=run-no-cache.earth --use_tmpfs=false --target=+test-from \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=0} END {exit \\\$status} \\\$status=1 if /\\\*cached\\\* --> .*motd2 \\\.\\\//;'"
save-artifact-after-push:
# test that save after push is a thing
DO +RUN_EARTHLY --earthfile=save-artifact-after-push.earth --target=+test
# test that cant copy saved after push
DO +RUN_EARTHLY --earthfile=save-artifact-after-push.earth --target=+copy-test \
--post_command="2>&1 | perl -pe 'BEGIN {\\\$status=1} END {exit \\\$status} \\\$status=0 if /not found/;'"
push-build:
DO +RUN_EARTHLY --earthfile=push-build.earth --target=+test --extra_args="--push" --post_command="> output 2>&1"
RUN cat output
RUN cat output | perl -pe 'BEGIN {$status=1} END {exit $status} $status=0 if /\+test \| 0\n/;'
RUN cat output | perl -pe 'BEGIN {$status=1} END {exit $status} $status=0 if /\+run1 \| 1\n/;'
RUN cat output | perl -pe 'BEGIN {$status=1} END {exit $status} $status=0 if /\+run2 \| 2\n/;'
build-arg-repeat:
DO +RUN_EARTHLY --earthfile=build-arg-repeat.earth --target=+build-all-1
RUN test -f ./output/out-other-1
RUN test -f ./output/out-default-1
RUN cat ./output/out-other-1 | grep "A=other"
RUN cat ./output/out-other-1 | grep "B=1"
RUN cat ./output/out-default-1 | grep "A=default"
RUN cat ./output/out-default-1 | grep "B=1"
DO +RUN_EARTHLY --earthfile=build-arg-repeat.earth --target=+build-all-2
RUN test -f ./output/out-other-1
RUN test -f ./output/out-default-1
RUN cat ./output/out-other-1 | grep "A=other"
RUN cat ./output/out-other-1 | grep "B=1"
RUN cat ./output/out-default-1 | grep "A=default"
RUN cat ./output/out-default-1 | grep "B=1"
if:
RUN touch exists-locally
DO +RUN_EARTHLY --earthfile=if.earth
first-command:
DO +RUN_EARTHLY --earthfile=first-command.earth --target=+all-positive
DO +RUN_EARTHLY --earthfile=first-command.earth --should_fail=true --target=+start-with-run
DO +RUN_EARTHLY --earthfile=first-command.earth --should_fail=true --target=+start-with-if
DO +RUN_EARTHLY --earthfile=first-command.earth --should_fail=true --target=+start-with-non-from-target
platform-output:
DO +RUN_EARTHLY --earthfile=platform-output.earth
RUN test -f ./out-arm
RUN test -f ./out-arm64
RUN ! test -f ./out-amd64
command:
RUN echo "hello command" >./message.txt
DO +RUN_EARTHLY --earthfile=command.earth
duplicate:
DO +RUN_EARTHLY --earthfile=duplicate-target-names.earth --should_fail=true --target=+duplicate
reserved:
DO +RUN_EARTHLY --earthfile=reserved-target-names.earth --should_fail=true --target=+reserved
quotes-test:
DO +RUN_EARTHLY --earthfile=quotes.earth
new-args:
DO +RUN_EARTHLY --earthfile=new-args.earth
import:
DO +RUN_EARTHLY --earthfile=import.earth
infinite-recursion:
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test1
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test2
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test3
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test4
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test5
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test6
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test7
DO +RUN_EARTHLY --earthfile=infinite-recursion.earth --should_fail=true --target=+test8
from-dockerfile-arg:
DO +RUN_EARTHLY --earthfile=from-dockerfile-arg.earth --target=+all
RUN test "$(cat ./arg-value-default)" = "default"
RUN test "$(cat ./arg-value-foo)" = "foo"
RUN test "$(cat ./arg-value-bar)" = "bar"
cache-mount-arg:
DO +RUN_EARTHLY --earthfile=cache-mount-arg.earth --use_tmpfs=false --target="+b-nomount --MYARG=123"
DO +RUN_EARTHLY --earthfile=cache-mount-arg.earth --use_tmpfs=false --target="+b-nomount --MYARG=1234" --post_command="2>output-nomount.txt"
RUN cat output-nomount.txt
RUN cat output-nomount.txt | grep '\*cached\* --> RUN echo Doing something 1'
RUN cat output-nomount.txt | grep '\*cached\* --> RUN echo Doing something 2'; test "$?" != 0
DO +RUN_EARTHLY --earthfile=cache-mount-arg.earth --use_tmpfs=false --target="+b --MYARG=abc"
DO +RUN_EARTHLY --earthfile=cache-mount-arg.earth --use_tmpfs=false --target="+b --MYARG=abcd" --post_command="2>output.txt"
RUN cat output.txt
RUN cat output.txt | grep '\*cached\* --> RUN echo Doing something 1'
RUN cat output.txt | grep '\*cached\* --> RUN echo Doing something 2'; test "$?" != 0
DO +RUN_EARTHLY --earthfile=cache-mount-arg.earth --use_tmpfs=false --target="+b-with-arg --MYARG=def"
DO +RUN_EARTHLY --earthfile=cache-mount-arg.earth --use_tmpfs=false --target="+b-with-arg --MYARG=defg" --post_command="2>output.txt"
RUN cat output.txt
RUN cat output.txt | grep '\*cached\* --> RUN echo Doing something 1'; test "$?" != 0
RUN cat output.txt | grep '\*cached\* --> RUN echo Doing something 2'; test "$?" != 0
RUN_EARTHLY:
COMMAND
ARG earthfile=
ARG target=+all
ARG extra_args
ARG post_command
ARG should_fail=false
ARG use_tmpfs=true
COPY "$earthfile" ./Earthfile
RUN echo "
set -x
if $use_tmpfs; then
export EARTHLY_TMP_DIR=/tmp/earthly-tmpfs
fi
echo running earthly with $target
eval \"/usr/bin/earthly-entrypoint.sh $extra_args $target $post_command\"
exit_code=\$?
if $should_fail; then
if [ \$exit_code -eq 0 ]; then
echo ERROR: earthly should have failed but didn\'t.
exit 1
else
exit 0
fi
else
exit \$exit_code
fi
" >/tmp/earthly-script
RUN --privileged \
--mount=type=tmpfs,target=/tmp/earthly-tmpfs \
/bin/sh /tmp/earthly-script