Earthfile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. VERSION 0.6
  2. FROM mcr.microsoft.com/vscode/devcontainers/base:0-bionic
  3. ARG DEVCONTAINER_IMAGE_NAME_DEFAULT=ghcr.io/haxefoundation/haxe_devcontainer
  4. ARG USERNAME=vscode
  5. ARG USER_UID=1000
  6. ARG USER_GID=$USER_UID
  7. ARG WORKDIR=/workspace
  8. RUN mkdir -m 777 "$WORKDIR"
  9. WORKDIR "$WORKDIR"
  10. ARG --required TARGETARCH
  11. devcontainer-library-scripts:
  12. RUN curl -fsSLO https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-debian.sh
  13. RUN curl -fsSLO https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/docker-debian.sh
  14. SAVE ARTIFACT --keep-ts *.sh AS LOCAL .devcontainer/library-scripts/
  15. devcontainer:
  16. # Avoid warnings by switching to noninteractive
  17. ENV DEBIAN_FRONTEND=noninteractive
  18. ARG INSTALL_ZSH="false"
  19. ARG UPGRADE_PACKAGES="true"
  20. ARG ENABLE_NONROOT_DOCKER="true"
  21. ARG USE_MOBY="false"
  22. COPY .devcontainer/library-scripts/common-debian.sh .devcontainer/library-scripts/docker-debian.sh /tmp/library-scripts/
  23. RUN apt-get update \
  24. && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
  25. && /bin/bash /tmp/library-scripts/docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "/var/run/docker-host.sock" "/var/run/docker.sock" "${USERNAME}" "${USE_MOBY}" \
  26. # Clean up
  27. && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/
  28. # Setting the ENTRYPOINT to docker-init.sh will configure non-root access
  29. # to the Docker socket. The script will also execute CMD as needed.
  30. ENTRYPOINT [ "/usr/local/share/docker-init.sh" ]
  31. CMD [ "sleep", "infinity" ]
  32. # Configure apt and install packages
  33. RUN apt-get update \
  34. && apt-get install -qqy --no-install-recommends apt-utils dialog 2>&1 \
  35. && apt-get install -qqy --no-install-recommends \
  36. iproute2 \
  37. procps \
  38. sudo \
  39. bash-completion \
  40. build-essential \
  41. curl \
  42. wget \
  43. software-properties-common \
  44. direnv \
  45. tzdata \
  46. # install docker engine for using `WITH DOCKER`
  47. docker-ce \
  48. # install node
  49. && curl -sL https://deb.nodesource.com/setup_16.x | bash - \
  50. && apt-get install -qqy --no-install-recommends nodejs=16.* \
  51. # install ocaml and other haxe compiler deps
  52. && add-apt-repository ppa:avsm/ppa \
  53. && add-apt-repository ppa:haxe/ocaml \
  54. && apt-get install -qqy --no-install-recommends \
  55. ocaml-nox \
  56. camlp5 \
  57. opam \
  58. libpcre3-dev \
  59. zlib1g-dev \
  60. libgtk2.0-dev \
  61. libmbedtls-dev \
  62. ninja-build \
  63. libstring-shellquote-perl \
  64. libipc-system-simple-perl \
  65. #
  66. # Clean up
  67. && apt-get autoremove -y \
  68. && apt-get clean -y \
  69. && rm -rf /var/lib/apt/lists/*
  70. # Switch back to dialog for any ad-hoc use of apt-get
  71. ENV DEBIAN_FRONTEND=
  72. DO +INSTALL_NEKO
  73. COPY +earthly/earthly /usr/local/bin/
  74. RUN earthly bootstrap --no-buildkit --with-autocomplete
  75. USER $USERNAME
  76. # Do not show git branch in bash prompt because it's slow
  77. # https://github.com/microsoft/vscode-dev-containers/issues/1196#issuecomment-988388658
  78. RUN git config --global codespaces-theme.hide-status 1
  79. # Install OCaml libraries
  80. COPY opam .
  81. RUN opam init --disable-sandboxing
  82. RUN opam install . --yes --deps-only --no-depexts
  83. RUN opam list
  84. RUN ocamlopt -v
  85. USER root
  86. ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
  87. ARG IMAGE_TAG="development"
  88. ARG IMAGE_CACHE="$IMAGE_NAME:$IMAGE_TAG"
  89. SAVE IMAGE --cache-from="$IMAGE_CACHE" --push "$IMAGE_NAME:$IMAGE_TAG"
  90. devcontainer-multiarch-amd64:
  91. ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
  92. ARG IMAGE_TAG="development"
  93. FROM --platform=linux/amd64 +devcontainer --IMAGE_NAME="$IMAGE_NAME" --IMAGE_TAG="$IMAGE_TAG-amd64"
  94. SAVE IMAGE --push "$IMAGE_NAME:$IMAGE_TAG"
  95. devcontainer-multiarch-arm64:
  96. ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
  97. ARG IMAGE_TAG="development"
  98. FROM --platform=linux/arm64 +devcontainer --IMAGE_NAME="$IMAGE_NAME" --IMAGE_TAG="$IMAGE_TAG-arm64"
  99. SAVE IMAGE --push "$IMAGE_NAME:$IMAGE_TAG"
  100. devcontainer-multiarch:
  101. BUILD +devcontainer-multiarch-amd64
  102. BUILD +devcontainer-multiarch-arm64
  103. # Usage:
  104. # COPY +earthly/earthly /usr/local/bin/
  105. # RUN earthly bootstrap --no-buildkit --with-autocomplete
  106. earthly:
  107. ARG --required TARGETARCH
  108. RUN curl -fsSL https://github.com/earthly/earthly/releases/download/v0.6.13/earthly-linux-${TARGETARCH} -o /usr/local/bin/earthly \
  109. && chmod +x /usr/local/bin/earthly
  110. SAVE ARTIFACT /usr/local/bin/earthly
  111. INSTALL_PACKAGES:
  112. COMMAND
  113. ARG PACKAGES
  114. RUN apt-get update -qqy && \
  115. apt-get install -qqy --no-install-recommends $PACKAGES && \
  116. apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
  117. INSTALL_NEKO:
  118. COMMAND
  119. ARG NEKOPATH=/neko
  120. COPY +neko/* "$NEKOPATH/"
  121. ARG PREFIX=/usr/local
  122. RUN bash -c "ln -s \"$NEKOPATH\"/{neko,nekoc,nekoml,nekotools} \"$PREFIX/bin/\""
  123. RUN bash -c "ln -s \"$NEKOPATH\"/libneko.* \"$PREFIX/lib/\""
  124. RUN mkdir -p "$PREFIX/lib/neko/"
  125. RUN bash -c "ln -s \"$NEKOPATH\"/*.ndll \"$PREFIX/lib/neko/\""
  126. RUN ldconfig
  127. INSTALL_HAXE:
  128. COMMAND
  129. ARG PREFIX=/usr/local
  130. COPY +build/haxe +build/haxelib "$PREFIX/bin/"
  131. COPY std "$PREFIX/share/haxe/std"
  132. try-neko:
  133. DO +INSTALL_NEKO
  134. RUN neko -version
  135. RUN nekotools
  136. try-haxe:
  137. DO +INSTALL_NEKO
  138. DO +INSTALL_HAXE
  139. RUN haxe --version
  140. RUN haxelib version
  141. neko:
  142. RUN set -ex && \
  143. case "$TARGETARCH" in \
  144. amd64) PLATFORM=linux64;; \
  145. arm64) PLATFORM=linux-arm64;; \
  146. *) exit 1;; \
  147. esac && \
  148. curl -fsSL https://build.haxe.org/builds/neko/$PLATFORM/neko_latest.tar.gz -o neko_latest.tar.gz && \
  149. tar -xf neko_latest.tar.gz && \
  150. mv `echo neko-*-*` /tmp/neko-unpacked
  151. SAVE ARTIFACT /tmp/neko-unpacked/*
  152. SAVE IMAGE --cache-hint
  153. build:
  154. FROM +devcontainer
  155. USER $USERNAME
  156. # Build Haxe
  157. COPY --dir extra libs plugins src* std dune* Makefile* .
  158. COPY .git .git # the Makefile calls git to get commit sha
  159. ARG ADD_REVISION
  160. ENV ADD_REVISION=$ADD_REVISION
  161. RUN opam config exec -- make -s -j`nproc` STATICLINK=1 haxe && ldd -v ./haxe
  162. RUN opam config exec -- make -s haxelib && ldd -v ./haxelib
  163. RUN make -s package_unix && ls -l out
  164. ARG TARGETPLATFORM
  165. SAVE ARTIFACT --keep-ts ./out/* AS LOCAL out/$TARGETPLATFORM/
  166. SAVE ARTIFACT --keep-ts ./haxe AS LOCAL out/$TARGETPLATFORM/
  167. SAVE ARTIFACT --keep-ts ./haxelib AS LOCAL out/$TARGETPLATFORM/
  168. SAVE IMAGE --cache-hint
  169. build-multiarch:
  170. ARG ADD_REVISION
  171. BUILD --platform=linux/amd64 --platform=linux/arm64 +build --ADD_REVISION=$ADD_REVISION
  172. xmldoc:
  173. DO +INSTALL_NEKO
  174. DO +INSTALL_HAXE
  175. COPY --dir extra .
  176. WORKDIR extra
  177. RUN haxelib newrepo
  178. RUN haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp
  179. RUN haxelib git hxjava https://github.com/HaxeFoundation/hxjava
  180. RUN haxelib git hxcs https://github.com/HaxeFoundation/hxcs
  181. RUN haxe doc.hxml
  182. ARG COMMIT
  183. ARG BRANCH
  184. RUN echo "{\"commit\":\"$COMMIT\",\"branch\":\"$BRANCH\"}" > doc/info.json
  185. SAVE ARTIFACT --keep-ts ./doc AS LOCAL extra/doc
  186. test-environment:
  187. # we use a sightly newer ubuntu for easier installation of the target runtimes (e.g. php)
  188. FROM ubuntu:focal
  189. DO +INSTALL_NEKO
  190. DO +INSTALL_HAXE
  191. ENV DEBIAN_FRONTEND=noninteractive
  192. DO +INSTALL_PACKAGES --PACKAGES="ca-certificates curl wget git build-essential locales sqlite3"
  193. # Node.js is required as there are tests that use it (search "-cmd node")
  194. RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
  195. apt-get install -qqy nodejs && \
  196. apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
  197. # set locale
  198. RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
  199. ENV LANG=en_US.UTF-8
  200. ENV LANGUAGE=en_US:en
  201. ENV LC_ALL=en_US.UTF-8
  202. SAVE IMAGE --cache-hint
  203. test-environment-java:
  204. FROM +test-environment
  205. DO +INSTALL_PACKAGES --PACKAGES="default-jdk"
  206. SAVE IMAGE --cache-hint
  207. test-environment-js:
  208. # somehow js tests require hxjava which in turns require javac
  209. FROM +test-environment-java
  210. test-environment-python:
  211. FROM +test-environment
  212. DO +INSTALL_PACKAGES --PACKAGES="python3"
  213. SAVE IMAGE --cache-hint
  214. test-environment-php:
  215. FROM +test-environment
  216. DO +INSTALL_PACKAGES --PACKAGES="php-cli php-mbstring php-sqlite3"
  217. SAVE IMAGE --cache-hint
  218. test-environment-cs:
  219. FROM +test-environment
  220. DO +INSTALL_PACKAGES --PACKAGES="mono-devel mono-mcs"
  221. SAVE IMAGE --cache-hint
  222. test-environment-hl:
  223. FROM +test-environment
  224. DO +INSTALL_PACKAGES --PACKAGES="cmake ninja-build libturbojpeg-dev libpng-dev zlib1g-dev libvorbis-dev libsqlite3-dev"
  225. SAVE IMAGE --cache-hint
  226. test-environment-lua:
  227. # hererocks uses pip
  228. FROM +test-environment-python
  229. DO +INSTALL_PACKAGES --PACKAGES="libssl-dev libreadline-dev python3-pip unzip libpcre3-dev cmake"
  230. RUN ln -s /root/.local/bin/hererocks /bin/
  231. SAVE IMAGE --cache-hint
  232. test-environment-cpp:
  233. FROM +test-environment
  234. ARG TARGETPLATFORM
  235. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  236. DO +INSTALL_PACKAGES --PACKAGES="g++-multilib"
  237. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  238. DO +INSTALL_PACKAGES --PACKAGES="g++-multilib-arm-linux-gnueabi"
  239. ELSE
  240. RUN echo "Unsupported platform $TARGETPLATFORM" && exit 1
  241. END
  242. SAVE IMAGE --cache-hint
  243. test-environment-flash:
  244. # apache flex requires java
  245. FROM +test-environment-java
  246. # requirements for running flash player
  247. DO +INSTALL_PACKAGES --PACKAGES="libglib2.0-0 libfreetype6 xvfb libxcursor1 libnss3 libgtk2.0-0"
  248. SAVE IMAGE --cache-hint
  249. RUN_CI:
  250. COMMAND
  251. COPY tests tests
  252. RUN mkdir /haxelib && haxelib setup /haxelib
  253. WORKDIR tests
  254. ARG --required TEST
  255. ENV TEST="$TEST"
  256. RUN haxe RunCi.hxml
  257. test-macro:
  258. FROM +test-environment
  259. ARG GITHUB_ACTIONS
  260. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  261. DO +RUN_CI --TEST=macro
  262. test-neko:
  263. FROM +test-environment
  264. ARG GITHUB_ACTIONS
  265. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  266. DO +RUN_CI --TEST=neko
  267. test-js:
  268. FROM +test-environment-js
  269. ARG GITHUB_ACTIONS
  270. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  271. DO +RUN_CI --TEST=js
  272. test-hl:
  273. FROM +test-environment-hl
  274. ARG GITHUB_ACTIONS
  275. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  276. DO +RUN_CI --TEST=hl
  277. test-cpp:
  278. FROM +test-environment-cpp
  279. ARG GITHUB_ACTIONS
  280. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  281. DO +RUN_CI --TEST=cpp
  282. test-java:
  283. FROM +test-environment-java
  284. ARG GITHUB_ACTIONS
  285. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  286. DO +RUN_CI --TEST=java
  287. test-jvm:
  288. FROM +test-environment-java
  289. ARG GITHUB_ACTIONS
  290. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  291. DO +RUN_CI --TEST=jvm
  292. test-cs:
  293. FROM +test-environment-cs
  294. ARG GITHUB_ACTIONS
  295. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  296. DO +RUN_CI --TEST=cs
  297. test-php:
  298. FROM +test-environment-php
  299. ARG GITHUB_ACTIONS
  300. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  301. DO +RUN_CI --TEST=php
  302. test-python:
  303. FROM +test-environment-python
  304. ARG GITHUB_ACTIONS
  305. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  306. DO +RUN_CI --TEST=python
  307. test-lua:
  308. FROM +test-environment-lua
  309. ARG GITHUB_ACTIONS
  310. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  311. DO +RUN_CI --TEST=lua
  312. test-flash:
  313. FROM +test-environment-flash
  314. ARG GITHUB_ACTIONS
  315. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  316. DO +RUN_CI --TEST=flash9
  317. test-all:
  318. ARG TARGETPLATFORM
  319. BUILD +test-macro
  320. BUILD +test-neko
  321. BUILD +test-php
  322. BUILD +test-python
  323. BUILD +test-java
  324. BUILD +test-jvm
  325. BUILD +test-cs
  326. BUILD +test-cpp
  327. # BUILD +test-lua
  328. BUILD +test-js
  329. BUILD +test-flash
  330. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  331. BUILD +test-hl # FIXME: hl can't compile on arm64 (JIT issue?)
  332. END
  333. github-actions:
  334. DO +INSTALL_NEKO
  335. DO +INSTALL_HAXE
  336. RUN mkdir -p "$WORKDIR"/.github/workflows
  337. COPY extra/github-actions extra/github-actions
  338. WORKDIR extra/github-actions
  339. RUN haxe build.hxml
  340. SAVE ARTIFACT --keep-ts "$WORKDIR"/.github/workflows AS LOCAL .github/workflows
  341. ghcr-login:
  342. LOCALLY
  343. RUN echo "$GITHUB_CR_PAT" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin