Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Doesn't work in alpine docker container #346

Closed
jfrolich opened this issue Jan 10, 2020 · 23 comments
Closed

Doesn't work in alpine docker container #346

jfrolich opened this issue Jan 10, 2020 · 23 comments

Comments

@jfrolich
Copy link

sh: /opt/app/cms/node_modules/gentype/gentype.exe: not found

Graphq_ppx_re had the same problem:

teamwalnut/graphql-ppx#44
teamwalnut/graphql-ppx#60

@cristianoc
Copy link
Collaborator

cristianoc commented Jan 10, 2020

@jfrolich are executables built on alpine compatible with other distributions and not the other way around?
These are the current Azure CI settings:

  - template: .ci/build-platform.yml
    parameters:
      platform: Linux
      vmImage: ubuntu-16.04

@cristianoc
Copy link
Collaborator

Feel free to send a PR and we can test it.

@jfrolich
Copy link
Author

Yes I believe you can just use an alpine container, and then it also works on other distributions.

@baransu
Copy link

baransu commented Jan 13, 2020

It requires building on alpine and using static linking. I figured it out thanks to @anmonteiro help

@cristianoc
Copy link
Collaborator

Is there an example of doing that on Azure?

@baransu
Copy link

baransu commented Jan 13, 2020

I'm not sure.

I'm using dune-workspace and custom release profile for that:
https://github.com/baransu/graphql_ppx_re/blob/master/dune-workspace#L3
https://github.com/baransu/graphql_ppx_re/blob/master/.github/workflows/pipeline.yml#L51

I'm also using custom docker container with esy preinstalled on alpine:
https://github.com/baransu/graphql_ppx_re/blob/master/.github/workflows/pipeline.yml#L16

I'm not familiar with how genType release pipeline works. I hope it will help.

@jfrolich
Copy link
Author

Feel free to send a PR and we can test it.

Sorry I indeed found out that genType was not already using docker. So this is probably not an easy PR. Not sure if this is already tackled in https://github.com/jchavarri/hello-ppx-esy, but that repo is a great PPX starter with CI etc. set up. It might make sense to adopt this standard tooling so every improvement to that is easy to pull in to individual ppx-es. (Just an idea).

@cristianoc
Copy link
Collaborator

@jfrolich probably a good idea to continue the discussion on discord in the native-development channel, as this is going to affect other projects too. Doing it now.

@cristianoc
Copy link
Collaborator

Btw genType produces a single binary and has zero dependencies, so a quick workaround is to just build from source, while a CI solution is investigated.

@baransu
Copy link

baransu commented Jan 15, 2020

It seems there is a fix which doesn't require genType to be compiled with alpine: facebook/flow#3649 (comment)
You have to add:

RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
    apk add glibc-2.25-r0.apk

It slightly increases image size but works with the current version of genType and flow in that case which also by default doesn't work on alpine.

@cristianoc
Copy link
Collaborator

@baransu thanks for the reference.
The next question is how to do that on azure.

@cristianoc
Copy link
Collaborator

@baransu thanks for the reference.
The next question is how to do that on azure.

Actually, I might have misunderstood the point. Are you saying that it's not necessary to make an alpine build at all?

@baransu
Copy link

baransu commented Jan 17, 2020

Probably yes. I've added the above snippet and created a custom docker image based on alpine with that line. Now genType and flow (I'm also using) works. The downside is the size of the container but I really don't care.

@jfrolich
Copy link
Author

Yeah, that fixes it because the dynamic dependency on glibc (which is quite big). To make a static binary you can compile it with musl-libc. Then it will work everywhere, even on systems that do not have glibc (like small docker images). To do that you can install musl on the CI and add a compiler flag:
https://wiki.musl-libc.org/getting-started.html#Building-a-cross-compiler-targeting-musl-libc.

@anmonteiro
Copy link

I'm still in the camp of shipping a fully static binary, given that there are Linux distributions that are explicitly no FHS compliant. NixOS is the example I use.

@cristianoc
Copy link
Collaborator

@anmonteiro if we find a general way to do this for esy projects, we can reuse it.
Looks like Azure only has a couple of linux distros, and we're currently using ubuntu. Not sure if one would have to use a docker container on top, or how else to generate the binary.

@anmonteiro
Copy link

it should be straightforward to install musl-tools in Ubuntu and use that.

@cristianoc
Copy link
Collaborator

Closing for now.

@phenax
Copy link

phenax commented Dec 22, 2020

+1 for statically linked binary. Facing the same issue on NixOS.

@quinn-dougherty
Copy link
Contributor

Is this related to gentype not installed correctly warning leading to .gen files not being produced? On nixos in a flake. I'm trying it with and without patchelfing.

@quinn-dougherty
Copy link
Contributor

Yeah, that fixes it because the dynamic dependency on glibc (which is quite big). To make a static binary you can compile it with musl-libc. Then it will work everywhere, even on systems that do not have glibc (like small docker images). To do that you can install musl on the CI and add a compiler flag:
https://wiki.musl-libc.org/getting-started.html#Building-a-cross-compiler-targeting-musl-libc.

What would this look like in a yarn install workflow?

@cristianoc
Copy link
Collaborator

cristianoc commented Aug 4, 2022

The project has moved inside the upcoming v10.1 compiler. No need to install genType separately in future.

@cristianoc
Copy link
Collaborator

cristianoc commented Aug 4, 2022

The project page will change once v10.1 is out and used regularly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants