Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow-bin exiting with ENOENT in alpine docker container #3649

Closed
mightyguava opened this issue Apr 3, 2017 · 29 comments
Closed

Flow-bin exiting with ENOENT in alpine docker container #3649

mightyguava opened this issue Apr 3, 2017 · 29 comments

Comments

@mightyguava
Copy link

@mightyguava mightyguava commented Apr 3, 2017

I have flow working just fine in a project running locally on a Mac, but trying to run this on the official Node alpine base image is not working. Error and minimal repro steps pasted below.

I think #1605 fixes compilation of flow in a docker container, and I'm able to build a working flow binary following instructions there, but it'd be nice if the yarn installed flow could either "just work", or only requiring installing some os-dependencies, versus building flow from scratch.

Error with yarn installed flow

# Start a container
docker run -ti --rm node:7.8.0-alpine sh
# Now in container
mkdir test
cd test
yarn init
yarn add flow flow-bin --dev
yarn run flow

Errors:

yarn run v0.21.3
$ "/test/node_modules/.bin/flow"
events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: spawn /test/node_modules/flow-bin/flow-linux64-v0.42.0/flow ENOENT
    at exports._errnoException (util.js:1034:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:423:7)
    at startup (bootstrap_node.js:147:9)
    at bootstrap_node.js:538:3
error Command failed with exit code 1.

workaround (partial): To build flow in alpine node, in case this is useful to anyone

FROM node:7.7.2-alpine
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
  && apk --no-cache add \
     alpine-sdk \
     ocaml \
     ocamlbuild \
     libelf \
     libelf-dev \
     ncurses \
     inotify-tools \
     linux-headers \
     git \
     bash \
     diffutils \
  && git clone --depth 1 https://github.com/facebook/flow.git /tmp/flow \
  && cd /tmp/flow \
  && make \
  && cp bin/flow /usr/bin/flow \
  && apk --no-cache del \
     alpine-sdk \
     ocaml \
     ocamlbuild \
     libelf-dev \
     ncurses \
     inotify-tools \
     linux-headers \
     git \
     bash \
     diffutils \
  && cd / \
  && rm -rf /tmp/flow
@montogeek
Copy link
Contributor

@montogeek montogeek commented Apr 3, 2017

Funny, I am trying to do the same, the problem is that this dep is missing:
Error loading shared library libelf.so.1,
I am unable to install it

@mightyguava
Copy link
Author

@mightyguava mightyguava commented Apr 3, 2017

@montogeek did that come from the apk add libelf? I had libelf installed and the flow binary from npm still didn't work for me

@montogeek
Copy link
Contributor

@montogeek montogeek commented Apr 3, 2017

@mightyguava I tried with ocaml, libelf, libelf-dev without luck, I gave up and switched to Debian: https://hub.docker.com/r/montogeek/docker-yarn-flow/

@izumin5210
Copy link

@izumin5210 izumin5210 commented Apr 5, 2017

elfutils-libelf seems to contain libelf.so.1. https://pkgs.alpinelinux.org/contents?file=&path=&name=elfutils-libelf&branch=edzge&repo=main&arch=x86_64
I tried with elfutils-dev, elfutils-dev, libelf but still didn't work...

@montogeek
Copy link
Contributor

@montogeek montogeek commented Apr 5, 2017

@izumin5210 So, Flow is running after installing elfutils-libelf?

@vkurchatkin
Copy link
Contributor

@vkurchatkin vkurchatkin commented Apr 5, 2017

libc might be the culprit, binaries compiled against glibc don't work on alpine

@xdissent
Copy link

@xdissent xdissent commented Apr 13, 2017

It's definitely glibc. I tried the alpine glibc-compat stuff too but ultimately gave up. For building, the correct packages are elfutils-* not libelf-*:

FROM node:alpine

ENV FLOW_VERSION 0.43.1

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
  && apk add --no-cache --virtual .build-deps-flow \
     alpine-sdk \
     bash \
     diffutils \
     elfutils-dev \
     git \
     linux-headers \
     ncurses \
     ocaml \
     ocamlbuild \
  && git clone --depth 1 --branch "v$FLOW_VERSION" https://github.com/facebook/flow.git \
  && cd flow \
  && make test \
  && cp bin/flow /usr/bin/flow \
  && apk del .build-deps-flow \
  && apk add --no-cache elfutils-libelf \
  && cd .. \
  && rm -rf flow

Change make test to make if you don't care about tests. Random note: the tests fail if you build in /tmp/flow because it writes some test fixtures under that folder, and they accidentally find flow's own .flowconfig when they shouldn't.

@Vrtak-CZ
Copy link

@Vrtak-CZ Vrtak-CZ commented May 3, 2017

I'm just trying docker file posted by @xdissent with 0.45.0 and after I added ocaml-findlib to build-deps it fails with error:

ocamlfind ocamldep -package sedlex -modules src/flow.ml > src/flow.ml.depends
+ ocamlfind ocamldep -package sedlex -modules src/flow.ml > src/flow.ml.depends
ocamlfind: Package `sedlex' not found

😢

@xdissent
Copy link

@xdissent xdissent commented May 3, 2017

Here's an updated Dockerfile for 0.45.0. I'm unfamiliar with opam but I think adding a rm -rf ~/.opam might clean up some files that aren't needed after compilation.

FROM node:alpine

ENV FLOW_VERSION 0.45.0

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
  && apk add --no-cache --virtual .build-deps-flow \
     alpine-sdk \
     bash \
     diffutils \
     elfutils-dev \
     git \
     linux-headers \
     m4 \
     ncurses \
     ocaml \
     opam \
  && opam init -y \
  && eval `opam config env` \
  && opam update \
  && opam install -y ocamlfind sedlex \
  && git clone --depth 1 --branch "v$FLOW_VERSION" https://github.com/facebook/flow.git \
  && cd flow \
  && yarn \
  && make test \
  && cp bin/flow /usr/bin/flow \
  && apk del .build-deps-flow \
  && apk add --no-cache elfutils-libelf \
  && cd .. \
  && rm -rf flow
@Vrtak-CZ
Copy link

@Vrtak-CZ Vrtak-CZ commented May 3, 2017

@xdissent thx

@xdissent
Copy link

@xdissent xdissent commented Jun 13, 2017

Now that v0.48.0 doesn't need libelf, flow works with alpine-pkg-glibc (no compilation required).

Install flow normally (binary release or flow-bin) and run:

$ wget -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/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
@xjunior
Copy link

@xjunior xjunior commented Nov 25, 2017

I'm still having that issue running in a node:8.9-alpine container. Is alpine-pkg-glibc still required?

@juanpicado
Copy link

@juanpicado juanpicado commented Dec 2, 2017

Yes, it works with node:8.9.0-alpine. But I'd adjust the @xdissent to the readme in this repo, his example fails, but the one at the page works fine. https://github.com/sgerrand/alpine-pkg-glibc

I'm using flow@0.60.0

Here my example https://github.com/verdaccio/verdaccio/blob/feature-jest-test/Dockerfile

@FezVrasta
Copy link
Contributor

@FezVrasta FezVrasta commented Mar 29, 2018

"Yes" means, "Yes, it's still required". For anyone wondering it.

@jirutka
Copy link

@jirutka jirutka commented Jul 7, 2018

I've created Alpine package for Flow. It's available for x86_64 and aarch64 in the Alpine's testing repository for now. No glibc hacks are needed. Just install it using apk, e.g.:

apk add --no-cache --repository https://nl.alpinelinux.org/alpine/edge/testing flow

(EDIT: fixed command)

@princiya
Copy link

@princiya princiya commented Aug 21, 2018

The URL (mentioned by @xdissent ) of the public signing key has changed!

Source: https://github.com/sgerrand/alpine-pkg-glibc

Add the following into your Docker file:

apk --no-cache add ca-certificates wget
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.28-r0/glibc-2.28-r0.apk
apk add glibc-2.28-r0.apk
@kuzmenko1256
Copy link

@kuzmenko1256 kuzmenko1256 commented Aug 28, 2018

flow@0.74.0

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

RUN npm install
RUN npm run flow
@jirutka
Copy link

@jirutka jirutka commented Aug 28, 2018

@princiya @kuzmenko1256 Why do you still use this ugly hack instead of just installing flow from the Alpine repository?

apk add --no-cache --repository https://nl.alpinelinux.org/alpine/edge/testing flow

(EDIT: fixed command)

@princiya
Copy link

@princiya princiya commented Aug 29, 2018

@jirutka because the ugly hack works. I get the following error when I try the above command:
The command '/bin/sh -c apk add --repository https://nl.alpinelinux.org/alpine/edge/testing flow' returned a non-zero code: 1

More details:

RUN apk add --repository https://nl.alpinelinux.org/alpine/edge/testing flow
WARNING: Ignoring APKINDEX.865a153c.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.70c88391.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.5022a8a2.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
flow (missing): required by: world[flow]

Do you know why?

@jirutka
Copy link

@jirutka jirutka commented Aug 29, 2018

because the ugly hack works.

Well, if you don't mind that it breaks half of the system, so you can easily run into very weird issues... There are very good reasons why we (Alpine developers) don't support and recommend this hack.

Do you know why?

I forgot that you have to use --no-cache when using --repository, so:

apk add --no-cache --repository https://nl.alpinelinux.org/alpine/edge/testing flow
@princiya
Copy link

@princiya princiya commented Aug 29, 2018

@jirutka Thanks for the update, the installation works with the above command. However I get the below warning:
WARNING: This apk-tools is OLD! Some packages might not function properly. Is this ok?

flow itself doesn't seem to be working in this environment now:

Error: spawn /usr/star-web/node_modules/flow-bin/flow-linux64-v0.78.0/flow ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:229:19)
    at onErrorNT (internal/child_process.js:406:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:746:11)
    at startup (internal/bootstrap/node.js:240:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:235:12)
    at onErrorNT (internal/child_process.js:406:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)

Any pointers are greatly appreciated, so that we don't run into weird issues in the long run. The ugly hack was meant to be a temporary fix, but I would love to learn more on the better approaches. Thanks.

@jirutka
Copy link

@jirutka jirutka commented Aug 29, 2018

WARNING: This apk-tools is OLD! Some packages might not function properly. Is this ok?

This basically means that you're using an outdated image. It's not a problem though.

Error: spawn /usr/star-web/node_modules/flow-bin/flow-linux64-v0.78.0/flow ENOENT

You're running flow from the flow-bin npm package instead of the one installed from Alpine (which is in /usr/bin/flow).

@jirutka
Copy link

@jirutka jirutka commented Aug 29, 2018

The best solution would be to alter the flow build scripts in this repository to produce truly portable binaries, so even flow installed from the flow-bin package would work on Alpine without any hacks. I'll look at it once I have some time.

@princiya
Copy link

@princiya princiya commented Aug 29, 2018

@jirutka Thanks for all the help.

As a summary, the below solution now works like a charm:

in Dockerfile:
RUN apk add --no-cache --repository https://nl.alpinelinux.org/alpine/edge/testing flow

Wherever flow needs to be called, for example, npm run flow, flow should now refer to /usr/bin/flow which is installed from the above Alpine repository and not from default flow-bin npm package.

@webdeb
Copy link

@webdeb webdeb commented Sep 17, 2018

@jirutka definitely, modifying the dev-build image for every new flow version is not practical.

For now we'll not add flow to our pipeline, so I am just commenting here to keep myself updated, and to add it later once it works on alpine. Thanks!

@ftlno
Copy link

@ftlno ftlno commented Nov 27, 2018

Commenting to keep myself updated.

@VojtechVitek
Copy link

@VojtechVitek VojtechVitek commented Dec 13, 2018

For anyone interested, we've ended up installing glibc via https://github.com/sgerrand/alpine-pkg-glibc.

apk --no-cache add ca-certificates wget
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.28-r0/glibc-2.28-r0.apk
apk add glibc-2.28-r0.apk

Note: We use this dependency in our CI/CD pipeline only (a job running static check test suite using flow-bin). I'd be careful to a third party dependency like this into production Docker images.

@RajaBellebon
Copy link

@RajaBellebon RajaBellebon commented Jan 9, 2019

Hello @jirutka, by any chance did you work on altering the flow build scripts to produce truly portable binaries? We are trying to move from node image to node Alpine image in our project but in CI it failed the flow check. I tried your solution but I need to alter the script path.

@phuoctuong
Copy link

@phuoctuong phuoctuong commented Jan 12, 2019

For anyone interested, we've ended up installing glibc via https://github.com/sgerrand/alpine-pkg-glibc.

apk --no-cache add ca-certificates wget
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.28-r0/glibc-2.28-r0.apk
apk add glibc-2.28-r0.apk

Note: We use this dependency in our CI/CD pipeline only (a job running static check test suite using flow-bin). I'd be careful to a third party dependency like this into production Docker images.

Awesome, This is what we need really. I tried it successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.