Earthfile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 haxe doc.hxml
  190. ARG COMMIT
  191. ARG BRANCH
  192. RUN echo "{\"commit\":\"$COMMIT\",\"branch\":\"$BRANCH\"}" > doc/info.json
  193. SAVE ARTIFACT --keep-ts ./doc AS LOCAL extra/doc
  194. test-environment:
  195. # we use a sightly newer ubuntu for easier installation of the target runtimes (e.g. php)
  196. FROM ubuntu:focal
  197. DO +INSTALL_NEKO
  198. DO +INSTALL_HAXE
  199. ENV DEBIAN_FRONTEND=noninteractive
  200. DO +INSTALL_PACKAGES --PACKAGES="ca-certificates curl wget git build-essential locales sqlite3"
  201. # Node.js is required as there are tests that use it (search "-cmd node")
  202. RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
  203. apt-get install -qqy nodejs && \
  204. apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
  205. # set locale
  206. RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
  207. ENV LANG=en_US.UTF-8
  208. ENV LANGUAGE=en_US:en
  209. ENV LC_ALL=en_US.UTF-8
  210. SAVE IMAGE --cache-hint
  211. test-environment-java:
  212. FROM +test-environment
  213. DO +INSTALL_PACKAGES --PACKAGES="default-jdk"
  214. SAVE IMAGE --cache-hint
  215. test-environment-js:
  216. # somehow js tests require hxjava which in turns require javac
  217. FROM +test-environment-java
  218. test-environment-python:
  219. FROM +test-environment
  220. DO +INSTALL_PACKAGES --PACKAGES="python3"
  221. SAVE IMAGE --cache-hint
  222. test-environment-php:
  223. FROM +test-environment
  224. DO +INSTALL_PACKAGES --PACKAGES="php-cli php-mbstring php-sqlite3"
  225. SAVE IMAGE --cache-hint
  226. test-environment-hl:
  227. FROM +test-environment
  228. DO +INSTALL_PACKAGES --PACKAGES="cmake ninja-build libturbojpeg-dev libpng-dev zlib1g-dev libvorbis-dev libsqlite3-dev"
  229. SAVE IMAGE --cache-hint
  230. test-environment-lua:
  231. # hererocks uses pip
  232. FROM +test-environment-python
  233. DO +INSTALL_PACKAGES --PACKAGES="libssl-dev libreadline-dev python3-pip unzip libpcre2-dev cmake"
  234. RUN ln -s /root/.local/bin/hererocks /bin/
  235. SAVE IMAGE --cache-hint
  236. test-environment-cpp:
  237. FROM +test-environment
  238. ARG TARGETPLATFORM
  239. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  240. DO +INSTALL_PACKAGES --PACKAGES="g++-multilib"
  241. ELSE IF [ "$TARGETPLATFORM" = "linux/arm64" ]
  242. DO +INSTALL_PACKAGES --PACKAGES="g++-multilib-arm-linux-gnueabi"
  243. ELSE
  244. RUN echo "Unsupported platform $TARGETPLATFORM" && exit 1
  245. END
  246. SAVE IMAGE --cache-hint
  247. test-environment-flash:
  248. # apache flex requires java
  249. FROM +test-environment-java
  250. # requirements for running flash player
  251. DO +INSTALL_PACKAGES --PACKAGES="libglib2.0-0 libfreetype6 xvfb libxcursor1 libnss3 libgtk2.0-0"
  252. SAVE IMAGE --cache-hint
  253. RUN_CI:
  254. COMMAND
  255. COPY tests tests
  256. RUN mkdir /haxelib && haxelib setup /haxelib
  257. WORKDIR tests
  258. ARG --required TEST
  259. ENV TEST="$TEST"
  260. RUN haxe RunCi.hxml
  261. test-macro:
  262. FROM +test-environment
  263. ARG GITHUB_ACTIONS
  264. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  265. DO +RUN_CI --TEST=macro
  266. test-neko:
  267. FROM +test-environment
  268. ARG GITHUB_ACTIONS
  269. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  270. DO +RUN_CI --TEST=neko
  271. test-js:
  272. FROM +test-environment-js
  273. ARG GITHUB_ACTIONS
  274. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  275. DO +RUN_CI --TEST=js
  276. test-hl:
  277. FROM +test-environment-hl
  278. ARG GITHUB_ACTIONS
  279. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  280. DO +RUN_CI --TEST=hl
  281. test-cpp:
  282. FROM +test-environment-cpp
  283. ARG GITHUB_ACTIONS
  284. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  285. DO +RUN_CI --TEST=cpp
  286. test-java:
  287. FROM +test-environment-java
  288. ARG GITHUB_ACTIONS
  289. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  290. DO +RUN_CI --TEST=java
  291. test-jvm:
  292. FROM +test-environment-java
  293. ARG GITHUB_ACTIONS
  294. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  295. DO +RUN_CI --TEST=jvm
  296. test-php:
  297. FROM +test-environment-php
  298. ARG GITHUB_ACTIONS
  299. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  300. DO +RUN_CI --TEST=php
  301. test-python:
  302. FROM +test-environment-python
  303. ARG GITHUB_ACTIONS
  304. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  305. DO +RUN_CI --TEST=python
  306. test-lua:
  307. FROM +test-environment-lua
  308. ARG GITHUB_ACTIONS
  309. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  310. DO +RUN_CI --TEST=lua
  311. test-flash:
  312. FROM +test-environment-flash
  313. ARG GITHUB_ACTIONS
  314. ENV GITHUB_ACTIONS=$GITHUB_ACTIONS
  315. DO +RUN_CI --TEST=flash
  316. test-all:
  317. ARG TARGETPLATFORM
  318. BUILD +test-macro
  319. BUILD +test-neko
  320. BUILD +test-php
  321. BUILD +test-python
  322. BUILD +test-java
  323. BUILD +test-jvm
  324. BUILD +test-cpp
  325. BUILD +test-lua
  326. BUILD +test-js
  327. BUILD +test-flash
  328. IF [ "$TARGETPLATFORM" = "linux/amd64" ]
  329. BUILD +test-hl # FIXME: hl can't compile on arm64 (JIT issue?)
  330. END
  331. github-actions:
  332. DO +INSTALL_NEKO
  333. DO +INSTALL_HAXE
  334. RUN mkdir -p "$WORKDIR"/.github/workflows
  335. COPY extra/github-actions extra/github-actions
  336. WORKDIR extra/github-actions
  337. RUN haxe build.hxml
  338. SAVE ARTIFACT --keep-ts "$WORKDIR"/.github/workflows AS LOCAL .github/workflows
  339. ghcr-login:
  340. LOCALLY
  341. RUN echo "$GITHUB_CR_PAT" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin