Earthfile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. libpcre2-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 haxe.opam .
  81. RUN opam init --disable-sandboxing
  82. RUN opam switch create 4.08.1
  83. RUN eval $(opam env)
  84. RUN opam env
  85. RUN opam install . --yes --deps-only --no-depexts
  86. RUN opam list
  87. RUN ocamlopt -v
  88. USER root
  89. ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
  90. ARG IMAGE_TAG="development"
  91. ARG IMAGE_CACHE="$IMAGE_NAME:$IMAGE_TAG"
  92. SAVE IMAGE --cache-from="$IMAGE_CACHE" --push "$IMAGE_NAME:$IMAGE_TAG"
  93. devcontainer-multiarch-amd64:
  94. ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
  95. ARG IMAGE_TAG="development"
  96. FROM --platform=linux/amd64 +devcontainer --IMAGE_NAME="$IMAGE_NAME" --IMAGE_TAG="$IMAGE_TAG-amd64"
  97. SAVE IMAGE --push "$IMAGE_NAME:$IMAGE_TAG"
  98. devcontainer-multiarch-arm64:
  99. ARG IMAGE_NAME="$DEVCONTAINER_IMAGE_NAME_DEFAULT"
  100. ARG IMAGE_TAG="development"
  101. FROM --platform=linux/arm64 +devcontainer --IMAGE_NAME="$IMAGE_NAME" --IMAGE_TAG="$IMAGE_TAG-arm64"
  102. SAVE IMAGE --push "$IMAGE_NAME:$IMAGE_TAG"
  103. devcontainer-multiarch:
  104. BUILD +devcontainer-multiarch-amd64
  105. BUILD +devcontainer-multiarch-arm64
  106. # Usage:
  107. # COPY +earthly/earthly /usr/local/bin/
  108. # RUN earthly bootstrap --no-buildkit --with-autocomplete
  109. earthly:
  110. ARG --required TARGETARCH
  111. RUN curl -fsSL https://github.com/earthly/earthly/releases/download/v0.6.13/earthly-linux-${TARGETARCH} -o /usr/local/bin/earthly \
  112. && chmod +x /usr/local/bin/earthly
  113. SAVE ARTIFACT /usr/local/bin/earthly
  114. INSTALL_PACKAGES:
  115. COMMAND
  116. ARG PACKAGES
  117. RUN apt-get update -qqy && \
  118. apt-get install -qqy --no-install-recommends $PACKAGES && \
  119. apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
  120. INSTALL_NEKO:
  121. COMMAND
  122. ARG NEKOPATH=/neko
  123. COPY +neko/* "$NEKOPATH/"
  124. ARG PREFIX=/usr/local
  125. RUN bash -c "ln -s \"$NEKOPATH\"/{neko,nekoc,nekoml,nekotools} \"$PREFIX/bin/\""
  126. RUN bash -c "ln -s \"$NEKOPATH\"/libneko.* \"$PREFIX/lib/\""
  127. RUN bash -c "ln -s \"$NEKOPATH\"/*.h \"$PREFIX/include/\""
  128. RUN mkdir -p "$PREFIX/lib/neko/"
  129. RUN bash -c "ln -s \"$NEKOPATH\"/*.ndll \"$PREFIX/lib/neko/\""
  130. RUN ldconfig
  131. INSTALL_HAXE:
  132. COMMAND
  133. ARG PREFIX=/usr/local
  134. COPY +build/haxe +build/haxelib "$PREFIX/bin/"
  135. COPY std "$PREFIX/share/haxe/std"
  136. try-neko:
  137. DO +INSTALL_NEKO
  138. RUN neko -version
  139. RUN nekotools
  140. try-haxe:
  141. DO +INSTALL_NEKO
  142. DO +INSTALL_HAXE
  143. RUN haxe --version
  144. RUN haxelib version
  145. neko:
  146. RUN set -ex && \
  147. case "$TARGETARCH" in \
  148. amd64) PLATFORM=linux64;; \
  149. arm64) PLATFORM=linux-arm64;; \
  150. *) exit 1;; \
  151. esac && \
  152. curl -fsSL https://build.haxe.org/builds/neko/$PLATFORM/neko_latest.tar.gz -o neko_latest.tar.gz && \
  153. tar -xf neko_latest.tar.gz && \
  154. mv `echo neko-*-*` /tmp/neko-unpacked
  155. SAVE ARTIFACT /tmp/neko-unpacked/*
  156. SAVE IMAGE --cache-hint
  157. build:
  158. FROM +devcontainer
  159. USER $USERNAME
  160. # Build Haxe
  161. COPY --dir extra libs plugins src* std dune* Makefile* .
  162. # the Makefile calls git to get commit sha
  163. COPY .git .git
  164. ARG SET_SAFE_DIRECTORY="false"
  165. IF [ "$SET_SAFE_DIRECTORY" = "true" ]
  166. RUN git config --global --add safe.directory "$WORKDIR"
  167. END
  168. ARG ADD_REVISION
  169. ENV ADD_REVISION=$ADD_REVISION
  170. RUN opam config exec -- make -s -j`nproc` STATICLINK=1 haxe && ldd -v ./haxe
  171. RUN opam config exec -- make -s haxelib && ldd -v ./haxelib
  172. RUN make -s package_unix && ls -l out
  173. ARG TARGETPLATFORM
  174. SAVE ARTIFACT --keep-ts ./out/* AS LOCAL out/$TARGETPLATFORM/
  175. SAVE ARTIFACT --keep-ts ./haxe AS LOCAL out/$TARGETPLATFORM/
  176. SAVE ARTIFACT --keep-ts ./haxelib AS LOCAL out/$TARGETPLATFORM/
  177. SAVE IMAGE --cache-hint
  178. build-multiarch:
  179. ARG ADD_REVISION
  180. BUILD --platform=linux/amd64 --platform=linux/arm64 +build --ADD_REVISION=$ADD_REVISION
  181. xmldoc:
  182. DO +INSTALL_NEKO
  183. DO +INSTALL_HAXE
  184. COPY --dir extra .
  185. WORKDIR extra
  186. RUN haxelib newrepo
  187. RUN haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp
  188. RUN haxelib git hxjava https://github.com/HaxeFoundation/hxjava
  189. RUN haxelib git hxcs https://github.com/HaxeFoundation/hxcs
  190. RUN haxe doc.hxml
  191. ARG COMMIT
  192. ARG BRANCH
  193. RUN echo "{\"commit\":\"$COMMIT\",\"branch\":\"$BRANCH\"}" > doc/info.json
  194. SAVE ARTIFACT --keep-ts ./doc AS LOCAL extra/doc
  195. test-environment:
  196. # we use a sightly newer ubuntu for easier installation of the target runtimes (e.g. php)
  197. FROM ubuntu:focal
  198. DO +INSTALL_NEKO
  199. DO +INSTALL_HAXE
  200. ENV DEBIAN_FRONTEND=noninteractive
  201. DO +INSTALL_PACKAGES --PACKAGES="ca-certificates curl wget git build-essential locales sqlite3"
  202. # Node.js is required as there are tests that use it (search "-cmd node")
  203. RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
  204. apt-get install -qqy nodejs && \
  205. apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
  206. # set locale
  207. RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
  208. ENV LANG=en_US.UTF-8
  209. ENV LANGUAGE=en_US:en
  210. ENV LC_ALL=en_US.UTF-8
  211. SAVE IMAGE --cache-hint
  212. test-environment-java:
  213. FROM +test-environment
  214. DO +INSTALL_PACKAGES --PACKAGES="default-jdk"
  215. SAVE IMAGE --cache-hint
  216. test-environment-js:
  217. # somehow js tests require hxjava which in turns require javac
  218. FROM +test-environment-java
  219. test-environment-python:
  220. FROM +test-environment
  221. DO +INSTALL_PACKAGES --PACKAGES="python3"
  222. SAVE IMAGE --cache-hint
  223. test-environment-php:
  224. FROM +test-environment
  225. DO +INSTALL_PACKAGES --PACKAGES="php-cli php-mbstring php-sqlite3"
  226. SAVE IMAGE --cache-hint
  227. test-environment-cs:
  228. FROM +test-environment
  229. DO +INSTALL_PACKAGES --PACKAGES="mono-devel mono-mcs"
  230. SAVE IMAGE --cache-hint
  231. test-environment-hl:
  232. FROM +test-environment
  233. DO +INSTALL_PACKAGES --PACKAGES="cmake ninja-build libturbojpeg-dev libpng-dev zlib1g-dev libvorbis-dev libsqlite3-dev"
  234. SAVE IMAGE --cache-hint
  235. test-environment-lua:
  236. # hererocks uses pip
  237. FROM +test-environment-python
  238. DO +INSTALL_PACKAGES --PACKAGES="libssl-dev libreadline-dev python3-pip unzip libpcre2-dev cmake"
  239. RUN ln -s /root/.local/bin/hererocks /bin/
  240. SAVE IMAGE --cache-hint
  241. test-environment-cpp:
  242. FROM +test-environment
  243. ARG TARGETPLATFORM
  244. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  245. DO +INSTALL_PACKAGES --PACKAGES="g++-multilib"
  246. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  247. DO +INSTALL_PACKAGES --PACKAGES="g++-multilib-arm-linux-gnueabi"
  248. ELSE
  249. RUN echo "Unsupported platform $TARGETPLATFORM" && exit 1
  250. END
  251. SAVE IMAGE --cache-hint
  252. test-environment-flash:
  253. # apache flex requires java
  254. FROM +test-environment-java
  255. # requirements for running flash player
  256. DO +INSTALL_PACKAGES --PACKAGES="libglib2.0-0 libfreetype6 xvfb libxcursor1 libnss3 libgtk2.0-0"
  257. SAVE IMAGE --cache-hint
  258. RUN_CI:
  259. COMMAND
  260. COPY tests tests
  261. RUN mkdir /haxelib && haxelib setup /haxelib
  262. WORKDIR tests
  263. ARG --required TEST
  264. ENV TEST="$TEST"
  265. RUN haxe RunCi.hxml
  266. test-macro:
  267. FROM +test-environment
  268. ARG GITHUB_ACTIONS
  269. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  270. DO +RUN_CI --TEST=macro
  271. test-neko:
  272. FROM +test-environment
  273. ARG GITHUB_ACTIONS
  274. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  275. DO +RUN_CI --TEST=neko
  276. test-js:
  277. FROM +test-environment-js
  278. ARG GITHUB_ACTIONS
  279. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  280. DO +RUN_CI --TEST=js
  281. test-hl:
  282. FROM +test-environment-hl
  283. ARG GITHUB_ACTIONS
  284. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  285. DO +RUN_CI --TEST=hl
  286. test-cpp:
  287. FROM +test-environment-cpp
  288. ARG GITHUB_ACTIONS
  289. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  290. DO +RUN_CI --TEST=cpp
  291. test-java:
  292. FROM +test-environment-java
  293. ARG GITHUB_ACTIONS
  294. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  295. DO +RUN_CI --TEST=java
  296. test-jvm:
  297. FROM +test-environment-java
  298. ARG GITHUB_ACTIONS
  299. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  300. DO +RUN_CI --TEST=jvm
  301. test-cs:
  302. FROM +test-environment-cs
  303. ARG GITHUB_ACTIONS
  304. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  305. DO +RUN_CI --TEST=cs
  306. test-php:
  307. FROM +test-environment-php
  308. ARG GITHUB_ACTIONS
  309. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  310. DO +RUN_CI --TEST=php
  311. test-python:
  312. FROM +test-environment-python
  313. ARG GITHUB_ACTIONS
  314. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  315. DO +RUN_CI --TEST=python
  316. test-lua:
  317. FROM +test-environment-lua
  318. ARG GITHUB_ACTIONS
  319. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  320. DO +RUN_CI --TEST=lua
  321. test-flash:
  322. FROM +test-environment-flash
  323. ARG GITHUB_ACTIONS
  324. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  325. DO +RUN_CI --TEST=flash
  326. test-all:
  327. ARG TARGETPLATFORM
  328. BUILD +test-macro
  329. BUILD +test-neko
  330. BUILD +test-php
  331. BUILD +test-python
  332. BUILD +test-java
  333. BUILD +test-jvm
  334. BUILD +test-cs
  335. BUILD +test-cpp
  336. BUILD +test-lua
  337. BUILD +test-js
  338. BUILD +test-flash
  339. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  340. BUILD +test-hl # FIXME: hl can't compile on arm64 (JIT issue?)
  341. END
  342. github-actions:
  343. DO +INSTALL_NEKO
  344. DO +INSTALL_HAXE
  345. RUN mkdir -p "$WORKDIR"/.github/workflows
  346. COPY extra/github-actions extra/github-actions
  347. WORKDIR extra/github-actions
  348. RUN haxe build.hxml
  349. SAVE ARTIFACT --keep-ts "$WORKDIR"/.github/workflows AS LOCAL .github/workflows
  350. ghcr-login:
  351. LOCALLY
  352. RUN echo "$GITHUB_CR_PAT" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin