Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Cannot start or build reason app inside node:9-alpine container #62

Closed
portenez opened this issue Jun 16, 2018 · 10 comments
Closed

Cannot start or build reason app inside node:9-alpine container #62

portenez opened this issue Jun 16, 2018 · 10 comments

Comments

@portenez
Copy link

portenez commented Jun 16, 2018

yarn start and yarn build both fail inside a docker container built using the instructions in the docs. Running inside alpine is a must for compiling inside a CI pipeline.

To reproduce:

  1. Build image using this Dockerfile. e.g.: docker build . -t sad-reson
FROM node:9-alpine

RUN apk update && apk upgrade && \
  apk add build-base bzip2 git tar curl ca-certificates python

RUN addgroup -S app && adduser -S -G app app 

USER app

RUN mkdir ~/.npm-global
RUN npm config set prefix '~/.npm-global'
ENV PATH=~/.npm-global/bin:$PATH
# RUN npm install -g reason-cli@3.2.0-linux # fails the same, with or withouth this line
RUN npm install -g bs-platform

RUN cd ~ \ 
  && yarn create react-app my-app --scripts-version reason-scripts \
  && cd my-app

WORKDIR /home/app/my-app
  1. yarn start fails. try by: docker run --rm -it sad-reason yarn start
  2. yarn build fails. try by: docker run --rm -it sad-reason yarn build

Sample error:

docker run --rm -it sad-reason yarn start
Failed to compile.

./src/index.re
Module build failed: Error:
/bin/sh: script: not found
    at Array.map (<anonymous>)
    at <anonymous>
error An unexpected error occurred: "Command failed.
Exit signal: SIGINT
Command: sh
Arguments: -c react-scripts start
Directory: /home/app/my-app
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/home/app/my-app/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@anmonteiro
Copy link
Collaborator

Does this work with the stock create-react-app (in JS)?

@rrdelaney
Copy link
Owner

Hi @portenez, thanks for filing this issue!

Could you please paste the full output of the error logs? I don't know if any of the maintainers here use Docker, and installing it to debug this issue would be a serious time commitment from us. Additionally, pasting the error logs could give us a lot for information and we can tell if it's a known issue from Reason, or from the upstream create-react-app.

I also recommend searching the create-react-app repo for more information on using it with Docker.

Thanks again!

@portenez
Copy link
Author

Create react app does work. I have another project with a similar setup (create react app) , but no reasonml. that one work just fine. I'll double check versions and post a dockerfile for that one (just create react app) as soon as I have a chance. How do I enable the debug logs? I'll post them here.

@rrdelaney
Copy link
Owner

You said the “start” command fails? What do yoya mean by fails? This is a difficult and time consuming set up to replicate, so we would appreciate knowing how it fails, there may be a different error than just running it in docket.

@portenez
Copy link
Author

portenez commented Jun 16, 2018

Create React App versions

working = YES

Version 1 with npx

FROM node:9-alpine

RUN addgroup -S app && adduser -S -G app app 

USER app

RUN mkdir ~/.npm-global
RUN npm config set prefix '~/.npm-global'
ENV PATH=~/.npm-global/bin:$PATH

RUN cd ~ \ 
  && npx create-react-app my-app

WORKDIR /home/app/my-app

Version 2 with yarn

FROM node:9-alpine

RUN addgroup -S app && adduser -S -G app app 

USER app

RUN mkdir ~/.npm-global
RUN npm config set prefix '~/.npm-global'
ENV PATH=~/.npm-global/bin:$PATH

RUN cd ~ \ 
  && yarn create react-app my-app

WORKDIR /home/app/my-app

To run

  1. Create a Dockerfile with the code above
  2. Build image using the Dockerfile. e.g.: docker build . -t happy-js
  3. yarn start succeeds. try by: docker run --rm -it happy-js yarn start
  4. yarn build fails. try by: docker run --rm -it happy-js yarn build

Sample succesful output:

docker run --rm -it happy-js yarn build                                                                         8s 148ms
yarn run v1.5.1
$ react-scripts build
Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  36.94 KB  build/static/js/main.a0b7d8d3.js
  299 B     build/static/css/main.c17080f1.css

The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:

  "homepage" : "http://myname.github.io/myapp",

The build folder is ready to be deployed.
You may serve it with a static server:

  yarn global add serve
  serve -s build

Find out more about deployment here:

  http://bit.ly/2vY88Kr

Done in 9.46s.

@portenez
Copy link
Author

@rrdelaney I updated the original ticket with the output that I'm getting.

More than docker, looks like a Linux issue. To replicate any of the scenarios pretty much these are the steps:

  1. Get/install docker: https://www.docker.com/docker-mac
  2. In a dir touch Dockerfile, and add the contents of any of my examples. At this point you have docker + the Dockefile with the instructions on how to create the container.
  3. Build the container by calling docker build in the same dir as the Dockerfile docker build . -t ${tagUseAsRefToRun}.
  4. Run the built container by using docker run: docker run --rm -it ${tagUseAsRefToRun} ${comandsToExecute}.

So for example

mkdir dockerTest
cd dockerTest
touch Dockerfile
vim Dockerfile #here paste the contents
docker build . -t test-container
docker run --rm -it test-container yarn start # the last tokens in the cli are passed to the container
#or
docker run --rm -it test-container yarn build 

An alternative way to reproduce it is to just open a terminal in node:9-alpine and type all the commands in there. More difficult IMO.

You could start such terminal by:

docker run --rm -it node:9-alpine /bin/ash

Which will give you a completely clean node:9-alpine container

@rrdelaney
Copy link
Owner

It looks like Alpine Linux doesn’t have the script command. reason-scripts running on Linux system requires that command to be present.

Please see rrdelaney/bs-loader#35 and gliderlabs/docker-alpine#160 for more information.

@portenez
Copy link
Author

portenez commented Jun 17, 2018

I see, that's a shame. I guess I'm going to try using debían instead. Thanks for the help.

Perhaps, it'd be useful to have some Linux info in the docs. Or maybe I missed it?

@portenez
Copy link
Author

portenez commented Jun 17, 2018

As reference, xenial based container did work just fine:

FROM ubuntu:xenial

RUN apt-get update \
  && apt-get install -y curl \
    build-essential \
    git \
  && apt-get clean \
  && apt-get autoremove --purge

RUN curl -sL https://deb.nodesource.com/setup_9.x | bash - \
  && apt-get install -y nodejs \
  && apt-get clean

RUN npm install -g yarn
RUN yarn add global reason-cli@3.2.0-linux
RUN yarn add global bs-platform

RUN mkdir -p /opt \
  && yarn create react-app my-app --scripts-version reason-scripts \
  && cd my-app

WORKDIR /opt/my-app

CMD ["yarn", "start"]

build contianerdocker build . -t reason-builder
serve docker run --rm -it reason-builder
build assets docker run --rm -it reson-builder yarn build

@anmonteiro
Copy link
Collaborator

@portenez I just ran into this myself and apk add util-linux adds script for me. Perhaps that's an alternative for you if you wanna get a slimmer container.

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

3 participants