rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.68k stars 445 forks source link

Fails to compile/install on Docker alpine linux #5144

Closed abhiyaantrix closed 3 years ago

abhiyaantrix commented 3 years ago

While trying to Dockerize another OS project, I faced some issues. Please note ReScript, ninja are all new things for me. For now, I am only trying to create a Docker-based development environment for this project.

Using docker image node:12-alpine3.10

Error log

#11 252.6 make[1]: Leaving directory '/app/node_modules/bs-platform/ocaml'
#11 252.6 Cleaning... 4 files.
#11 252.6 bsb: [1/4] ../linux/bsb_helper.exe
#11 252.6 bsb: [2/4] ../linux/bsb.exe
#11 252.6 bsb: [3/4] ../linux/bsc.exe
#11 252.6 FAILED: ../linux/bsc.exe
#11 252.6 /app/node_modules/bs-platform/native/4.06.1/bin/ocamlopt.opt -O2  -nodynlink -I 4.06.1 -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c -w A-4-9-48-40-45-41-44-50-21-30-32-34-37-27-60-42 -warn-error A      4.06.1/whole_compiler.mli 4.06.1/whole_compiler.ml -o ../linux/bsc.exe && strip ../linux/bsc.exe
#11 252.6 Killed
#11 252.6 bsb: [4/4] ../linux/refmt.exe
#11 252.6 FAILED: cannot make progress due to previous errors.
#11 252.6 child_process.js:656
#11 252.6     throw err;
#11 252.6     ^
#11 252.6
#11 252.6 Error: Command failed: /app/node_modules/bs-platform/linux/ninja.exe -f release.ninja -v
#11 252.6     at checkExecSyncError (child_process.js:635:11)
#11 252.6     at Object.execFileSync (child_process.js:653:15)
#11 252.6     at provideCompiler (/app/node_modules/bs-platform/scripts/install.js:206:8)
#11 252.6     at Object.<anonymous> (/app/node_modules/bs-platform/scripts/install.js:217:1)
#11 252.6     at Module._compile (internal/modules/cjs/loader.js:999:30)
#11 252.6     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
#11 252.6     at Module.load (internal/modules/cjs/loader.js:863:32)
#11 252.6     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
#11 252.6     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
#11 252.6     at internal/main/run_main_module.js:17:47 {
#11 252.6   status: 1,
#11 252.6   signal: null,
#11 252.6   output: [ null, null, null ],
#11 252.6   pid: 7052,
#11 252.6   stdout: null,
#11 252.6   stderr: null
#11 252.6 }
------
executor failed running [/bin/sh -c yarn install]: exit code: 1

Part of Package.json

"dependencies": {
...
    "@rescript/react": "^0.10.1",
    "bs-fetch": "^0.6.2",
    "bs-platform": "8.3.3",
    "bs-webapi": "^0.19.1",
...
}

Rudimentary Dockerfile to reproduce this

FROM node:12-alpine3.10

RUN apk --update-cache add --update --virtual build-dependencies build-base git python3 py3-pip

ENV APP_HOME /app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

COPY . $APP_HOME

RUN ln -s /usr/bin/python3 /usr/bin/python
RUN yarn install

RUN apk del build-dependencies
RUN rm -rf /var/cache/apk/*

CMD ["node"]
GlancingMind commented 3 years ago

I had the same problem. I think is was due to, that alpine uses musl instead of glib. This resulted into a complete recompilation of ninja and the ocaml toolchain. After I got it to work, the resulting image was about 1.5GB. If you only use alpine to reduce the image size, I recommend you to use node:slime image. Initially it will be a bit bigger then alpine... but a lot less headache and smaller then the alpine image with the recompiled rescript toolchain.

Shameless plug: I did myself create a docker based dev environment ~here~ here. :) It uses rescript-zora for unit testing and vite for bundling and live preview. Via docker-compose you can start various services to recompile rescript files, run automatic unit-tests and reload website on source changes.

bobzhang commented 3 years ago

the ocaml toolchain. After I got it to work, the resulting image was about 1.5GB.

The ocaml toolchain can be removed after installation. @GlancingMind do you also need musl for ocaml toolchain to work on alpine linux properly?

abhiyaantrix commented 3 years ago

@GlancingMind thanks for the insights. Makes sense. Switched to slim to avoid recompiling ninja.

Though now I have yet another issue and need to deal with that separately. Dockerizing a simple application, how hard that could be ;-)

error_building_rescript

GlancingMind commented 3 years ago

The ocaml toolchain can be removed after installation.

@bobzhang I tried via multi stage build, but I had some other difficulties. After I noticed that node:slime works out of the box, I concluded forcing myself into alpine isn't worth the trouble (for this time ;-) ). Especially as I can build and bundle with node:slime and then copy it over to node:alpine via multistage build (if container result size matters that much).

@GlancingMind do you also need musl for ocaml toolchain to work on alpine linux properly?

I don't know. I think I just installed the dependencies that where required to compile ninja. Then everything compiled successfully. So possible that my above given explanation is wrong.

I think it was due to, that alpine uses musl instead of glib.

Unfortunately I also no longer have this code. :(

@GlancingMind thanks for the insights. Makes sense. Switched to slim to avoid recompiling ninja.

@abhiyaantrix Glad it helped. :)

Though now I have yet another issue and need to deal with that separately. Dockerizing a simple application, how hard that could be ;-)

@abhiyaantrix Cannot help you with this one. I'm very new to Rescript myself (nor do I know OCaml and ReasonML). So take my following words with a grain of salt ;-). I think your code seem to use some ppx. As much as I know about them (out of the Rescript forum) is, that these are not officially supported.

bobzhang commented 3 years ago

I don't know. I think I just installed the dependencies that where required to compile ninja. Then everything compiled successfully.

Good to know, what are essential tools to compile ninja?

@GlancingMind to clarify a little bit about ppx. PPX is essentially a compiler plugin using ReScript compiler API (which is unstable ). We supported it and in retrospect it is a mistake as you can see you will come across weird issues like this. So try to avoid any use of ppx in your dependencies if you can.

GlancingMind commented 3 years ago

Good to know, what are essential tools to compile ninja?

python, g++ and make

Here is a repository with a minimal Dockerfile. The resulting image is 1.6GB in size.

bobzhang commented 3 years ago

so this issue is resolved?

GlancingMind commented 3 years ago

For me it is solved, but @abhiyaantrix uses "bs-platform": "8.3.3" while I only compiled the latest rescript version. So better get @abhiyaantrix feedback too.

GlancingMind commented 3 years ago

I successfully compiled bs-platform "8.3.3" with python3 on an node:12-alpine3.10 image. Note that the repo still has "^8.3.3" as bsb version, but I successfully compiled "8.3.3" locally. So I cannot reproduce @abhiyaantrix compilation error with the minimal dependencies required to compile bs-platform.

bobzhang commented 3 years ago

closed as it seems work when you have python and build-essentials installed. we welcome patches to get rid of python for building ninja