Earthfile 13 KB

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