-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
Earthfile
412 lines (341 loc) · 12.4 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
VERSION 0.6
FROM mcr.microsoft.com/vscode/devcontainers/base:0-bionic
ARG DEVCONTAINER_IMAGE_NAME_DEFAULT=ghcr.io/haxefoundation/haxe_devcontainer
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG WORKDIR=/workspace
RUN mkdir -m 777 "$WORKDIR"
WORKDIR "$WORKDIR"
ARG --required TARGETARCH
devcontainer-library-scripts:
RUN curl -fsSLO https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-debian.sh
RUN curl -fsSLO https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/docker-debian.sh
SAVE ARTIFACT --keep-ts *.sh AS LOCAL .devcontainer/library-scripts/
devcontainer:
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
ARG INSTALL_ZSH="false"
ARG UPGRADE_PACKAGES="true"
ARG ENABLE_NONROOT_DOCKER="true"
ARG USE_MOBY="false"
COPY .devcontainer/library-scripts/common-debian.sh .devcontainer/library-scripts/docker-debian.sh /tmp/library-scripts/
RUN apt-get update \
&& /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
&& /bin/bash /tmp/library-scripts/docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "/var/run/docker-host.sock" "/var/run/docker.sock" "${USERNAME}" "${USE_MOBY}" \
# Clean up
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/
# Setting the ENTRYPOINT to docker-init.sh will configure non-root access
# to the Docker socket. The script will also execute CMD as needed.
ENTRYPOINT [ "/usr/local/share/docker-init.sh" ]
CMD [ "sleep", "infinity" ]
# Configure apt and install packages
RUN apt-get update \
&& apt-get install -qqy --no-install-recommends apt-utils dialog 2>&1 \
&& apt-get install -qqy --no-install-recommends \
iproute2 \
procps \
sudo \
bash-completion \
build-essential \
curl \
wget \
software-properties-common \
direnv \
tzdata \
# install docker engine for using `WITH DOCKER`
docker-ce \
# install node
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -qqy --no-install-recommends nodejs=16.* \
# install ocaml and other haxe compiler deps
&& add-apt-repository ppa:avsm/ppa \
&& add-apt-repository ppa:haxe/ocaml \
&& apt-get install -qqy --no-install-recommends \
ocaml-nox \
camlp5 \
opam \
libpcre2-dev \
zlib1g-dev \
libgtk2.0-dev \
libmbedtls-dev \
ninja-build \
libstring-shellquote-perl \
libipc-system-simple-perl \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
DO +INSTALL_NEKO
COPY +earthly/earthly /usr/local/bin/
RUN earthly bootstrap --no-buildkit --with-autocomplete
USER $USERNAME
# Do not show git branch in bash prompt because it's slow
# https://github.com/microsoft/vscode-dev-containers/issues/1196#issuecomment-988388658
RUN git config --global codespaces-theme.hide-status 1
# Install OCaml libraries
COPY haxe.opam .
RUN opam init --disable-sandboxing
RUN opam switch create 4.08.1
RUN eval $(opam env)
RUN opam env
RUN opam install . --yes --deps-only --no-depexts
RUN opam list
RUN ocamlopt -v
USER root
ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
ARG IMAGE_TAG="development"
ARG IMAGE_CACHE="$IMAGE_NAME:$IMAGE_TAG"
SAVE IMAGE --cache-from="$IMAGE_CACHE" --push "$IMAGE_NAME:$IMAGE_TAG"
devcontainer-multiarch-amd64:
ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
ARG IMAGE_TAG="development"
FROM --platform=linux/amd64 +devcontainer --IMAGE_NAME="$IMAGE_NAME" --IMAGE_TAG="$IMAGE_TAG-amd64"
SAVE IMAGE --push "$IMAGE_NAME:$IMAGE_TAG"
devcontainer-multiarch-arm64:
ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
ARG IMAGE_TAG="development"
FROM --platform=linux/arm64 +devcontainer --IMAGE_NAME="$IMAGE_NAME" --IMAGE_TAG="$IMAGE_TAG-arm64"
SAVE IMAGE --push "$IMAGE_NAME:$IMAGE_TAG"
devcontainer-multiarch:
BUILD +devcontainer-multiarch-amd64
BUILD +devcontainer-multiarch-arm64
# Usage:
# COPY +earthly/earthly /usr/local/bin/
# RUN earthly bootstrap --no-buildkit --with-autocomplete
earthly:
ARG --required TARGETARCH
RUN curl -fsSL https://github.com/earthly/earthly/releases/download/v0.6.13/earthly-linux-${TARGETARCH} -o /usr/local/bin/earthly \
&& chmod +x /usr/local/bin/earthly
SAVE ARTIFACT /usr/local/bin/earthly
INSTALL_PACKAGES:
COMMAND
ARG PACKAGES
RUN apt-get update -qqy && \
apt-get install -qqy --no-install-recommends $PACKAGES && \
apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
INSTALL_NEKO:
COMMAND
ARG NEKOPATH=/neko
COPY +neko/* "$NEKOPATH/"
ARG PREFIX=/usr/local
RUN bash -c "ln -s \"$NEKOPATH\"/{neko,nekoc,nekoml,nekotools} \"$PREFIX/bin/\""
RUN bash -c "ln -s \"$NEKOPATH\"/libneko.* \"$PREFIX/lib/\""
RUN bash -c "ln -s \"$NEKOPATH\"/*.h \"$PREFIX/include/\""
RUN mkdir -p "$PREFIX/lib/neko/"
RUN bash -c "ln -s \"$NEKOPATH\"/*.ndll \"$PREFIX/lib/neko/\""
RUN ldconfig
INSTALL_HAXE:
COMMAND
ARG PREFIX=/usr/local
COPY +build/haxe +build/haxelib "$PREFIX/bin/"
COPY std "$PREFIX/share/haxe/std"
try-neko:
DO +INSTALL_NEKO
RUN neko -version
RUN nekotools
try-haxe:
DO +INSTALL_NEKO
DO +INSTALL_HAXE
RUN haxe --version
RUN haxelib version
neko:
RUN set -ex && \
case "$TARGETARCH" in \
amd64) PLATFORM=linux64;; \
arm64) PLATFORM=linux-arm64;; \
*) exit 1;; \
esac && \
curl -fsSL https://build.haxe.org/builds/neko/$PLATFORM/neko_latest.tar.gz -o neko_latest.tar.gz && \
tar -xf neko_latest.tar.gz && \
mv `echo neko-*-*` /tmp/neko-unpacked
SAVE ARTIFACT /tmp/neko-unpacked/*
SAVE IMAGE --cache-hint
build:
FROM +devcontainer
USER $USERNAME
# Build Haxe
COPY --dir extra libs plugins src* std dune* Makefile* .
# the Makefile calls git to get commit sha
COPY .git .git
ARG SET_SAFE_DIRECTORY="false"
IF [ "$SET_SAFE_DIRECTORY" = "true" ]
RUN git config --global --add safe.directory "$WORKDIR"
END
ARG ADD_REVISION
ENV ADD_REVISION=$ADD_REVISION
RUN opam config exec -- make -s -j`nproc` STATICLINK=1 haxe && ldd -v ./haxe
RUN opam config exec -- make -s haxelib && ldd -v ./haxelib
RUN make -s package_unix && ls -l out
ARG TARGETPLATFORM
SAVE ARTIFACT --keep-ts ./out/* AS LOCAL out/$TARGETPLATFORM/
SAVE ARTIFACT --keep-ts ./haxe AS LOCAL out/$TARGETPLATFORM/
SAVE ARTIFACT --keep-ts ./haxelib AS LOCAL out/$TARGETPLATFORM/
SAVE IMAGE --cache-hint
build-multiarch:
ARG ADD_REVISION
BUILD --platform=linux/amd64 --platform=linux/arm64 +build --ADD_REVISION=$ADD_REVISION
xmldoc:
DO +INSTALL_NEKO
DO +INSTALL_HAXE
COPY --dir extra .
WORKDIR extra
RUN haxelib newrepo
RUN haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp
RUN haxelib git hxjava https://github.com/HaxeFoundation/hxjava
RUN haxe doc.hxml
ARG COMMIT
ARG BRANCH
RUN echo "{\"commit\":\"$COMMIT\",\"branch\":\"$BRANCH\"}" > doc/info.json
SAVE ARTIFACT --keep-ts ./doc AS LOCAL extra/doc
test-environment:
# we use a sightly newer ubuntu for easier installation of the target runtimes (e.g. php)
FROM ubuntu:focal
DO +INSTALL_NEKO
DO +INSTALL_HAXE
ENV DEBIAN_FRONTEND=noninteractive
DO +INSTALL_PACKAGES --PACKAGES="ca-certificates curl wget git build-essential locales sqlite3"
# Node.js is required as there are tests that use it (search "-cmd node")
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -qqy nodejs && \
apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
# set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
SAVE IMAGE --cache-hint
test-environment-java:
FROM +test-environment
DO +INSTALL_PACKAGES --PACKAGES="default-jdk"
SAVE IMAGE --cache-hint
test-environment-js:
# somehow js tests require hxjava which in turns require javac
FROM +test-environment-java
test-environment-python:
FROM +test-environment
DO +INSTALL_PACKAGES --PACKAGES="python3"
SAVE IMAGE --cache-hint
test-environment-php:
FROM +test-environment
DO +INSTALL_PACKAGES --PACKAGES="php-cli php-mbstring php-sqlite3"
SAVE IMAGE --cache-hint
test-environment-hl:
FROM +test-environment
DO +INSTALL_PACKAGES --PACKAGES="cmake ninja-build libturbojpeg-dev libpng-dev zlib1g-dev libvorbis-dev libsqlite3-dev"
SAVE IMAGE --cache-hint
test-environment-lua:
# hererocks uses pip
FROM +test-environment-python
DO +INSTALL_PACKAGES --PACKAGES="libssl-dev libreadline-dev python3-pip unzip libpcre2-dev cmake"
RUN ln -s /root/.local/bin/hererocks /bin/
SAVE IMAGE --cache-hint
test-environment-cpp:
FROM +test-environment
ARG TARGETPLATFORM
IF [ "$TARGETPLATFORM" = "linux/amd64" ]
DO +INSTALL_PACKAGES --PACKAGES="g++-multilib"
ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
DO +INSTALL_PACKAGES --PACKAGES="g++-multilib-arm-linux-gnueabi"
ELSE
RUN echo "Unsupported platform $TARGETPLATFORM" && exit 1
END
SAVE IMAGE --cache-hint
test-environment-flash:
# apache flex requires java
FROM +test-environment-java
# requirements for running flash player
DO +INSTALL_PACKAGES --PACKAGES="libglib2.0-0 libfreetype6 xvfb libxcursor1 libnss3 libgtk2.0-0"
SAVE IMAGE --cache-hint
RUN_CI:
COMMAND
COPY tests tests
RUN mkdir /haxelib && haxelib setup /haxelib
WORKDIR tests
ARG --required TEST
ENV TEST="$TEST"
RUN haxe RunCi.hxml
test-macro:
FROM +test-environment
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=macro
test-neko:
FROM +test-environment
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=neko
test-js:
FROM +test-environment-js
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=js
test-hl:
FROM +test-environment-hl
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=hl
test-cpp:
FROM +test-environment-cpp
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=cpp
test-java:
FROM +test-environment-java
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=java
test-jvm:
FROM +test-environment-java
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=jvm
test-php:
FROM +test-environment-php
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=php
test-python:
FROM +test-environment-python
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=python
test-lua:
FROM +test-environment-lua
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=lua
test-flash:
FROM +test-environment-flash
ARG GITHUB_ACTIONS
ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
DO +RUN_CI --TEST=flash
test-all:
ARG TARGETPLATFORM
BUILD +test-macro
BUILD +test-neko
BUILD +test-php
BUILD +test-python
BUILD +test-java
BUILD +test-jvm
BUILD +test-cpp
BUILD +test-lua
BUILD +test-js
BUILD +test-flash
IF [ "$TARGETPLATFORM" = "linux/amd64" ]
BUILD +test-hl # FIXME: hl can't compile on arm64 (JIT issue?)
END
github-actions:
DO +INSTALL_NEKO
DO +INSTALL_HAXE
RUN mkdir -p "$WORKDIR"/.github/workflows
COPY extra/github-actions extra/github-actions
WORKDIR extra/github-actions
RUN haxe build.hxml
SAVE ARTIFACT --keep-ts "$WORKDIR"/.github/workflows AS LOCAL .github/workflows
ghcr-login:
LOCALLY
RUN echo "$GITHUB_CR_PAT" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin