reactiverse / es4x

🚀 fast JavaScript 4 Eclipse Vert.x
https://reactiverse.io/es4x/
Apache License 2.0
884 stars 75 forks source link

ES4X Docker issue #425

Closed UglyHobbitFeet closed 4 years ago

UglyHobbitFeet commented 4 years ago

I created an ES4x docker file and tried to build it. It barfs with the following error: ERROR: Service 'my-project' failed to build : The command '/bin/sh -c es4x install -f' returned a non-zero code: 2

If I run that exact same command in a terminal it works fine.

Attached below is my DockerFile, docker build command and command line without docker

DOCKERFILE:

$ cat Dockerfile 
ARG BASEIMAGE=oracle/graalvm-ce:20.2.0
# Use official node for build
FROM node:lts AS NPM
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
# npm is run with unsafe permissions because the default docker user is root
RUN npm --unsafe-perm update

# Second stage (build the JVM related code)
FROM $BASEIMAGE AS JVM
ARG ES4X_VERSION=0.13.2
# Download the ES4X runtime tool
RUN curl -sL https://github.com/reactiverse/es4x/releases/download/${ES4X_VERSION}/es4x-pm-${ES4X_VERSION}-bin.tar.gz | tar zx --strip-components=1 -C /usr/local
# force es4x maven resolution only to consider production dependencies
ENV ES4X_ENV=production
# Copy the previous build step
COPY --from=NPM /usr/src/app /usr/src/app
# use the copied workspace
WORKDIR /usr/src/app
# Install the maven dependencies
RUN es4x install -f

# Third stage (contain)
FROM $BASEIMAGE
# Collect the jars from the previous step
COPY --from=JVM /usr/src/app /usr/src/app
# use the copied workspace
WORKDIR /usr/src/app
# Bundle app source
COPY . .
# Define custom java options for containers
ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:+UseContainerSupport"
# define the entrypoint
ENTRYPOINT [ "./node_modules/.bin/es4x-launcher" ]

Docker Build File:

$ docker build --tag test:1.0 .
Sending build context to Docker daemon  239.5MB
Step 1/18 : ARG BASEIMAGE=oracle/graalvm-ce:20.2.0
Step 2/18 : FROM node:lts AS NPM
 ---> 2731b47de998
Step 3/18 : WORKDIR /usr/src/app
 ---> Using cache
 ---> b5757d753687
Step 4/18 : COPY package*.json ./
 ---> dc11c2f08523
Step 5/18 : RUN npm --unsafe-perm update
 ---> Running in 4110bb9bdb67
npm WARN deprecated sortablejs@1.12.0: Object.assign was not transformed during the build of sortablejs, so it won't work in browsers where this does not exist (for example IE11). Please downgrade your version to 1.10.2 to keep supporting <=IE11 or upgrade to >2.0 where IE will no longer be supported.

> yorkie@2.0.0 install /usr/src/app/node_modules/yorkie
> node bin/install.js

setting up Git hooks
can't find .git directory, skipping Git hooks installation

> ejs@2.7.4 postinstall /usr/src/app/node_modules/ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ apollo-link-ws@1.0.20
+ apollo-link@1.2.14
+ axios@0.20.0
+ @mdi/js@5.6.55
+ chart.js@2.9.3
+ graphql-tag@2.11.0
+ graphql@14.7.0
+ dot-properties@1.0.1
+ chartjs-plugin-zoom@0.7.7
+ @vertx/web@3.9.3
+ @vertx/core@3.9.3
+ @vertx/mongo-client@3.9.3
+ fontsource-roboto@3.0.3
+ @vertx/web-client@3.9.3
+ @es4x/create@0.13.2
+ ol-contextmenu@4.1.0
+ speed-measure-webpack-plugin@1.3.3
+ sortablejs@1.12.0
+ vue-router@3.4.6
+ vue-chartjs@3.5.1
+ subscriptions-transport-ws@0.9.18
+ vue@2.6.12
+ ol@6.4.3
+ vuex@3.5.1
+ vuetify@2.3.13
added 1305 packages from 1018 contributors and audited 1309 packages in 27.888s

63 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Removing intermediate container 4110bb9bdb67
 ---> 6b0b79600cfc
Step 6/18 : FROM $BASEIMAGE AS JVM
 ---> 94c408b22947
Step 7/18 : ARG ES4X_VERSION=0.13.2
 ---> Using cache
 ---> 0c51509b7140
Step 8/18 : RUN curl -sL https://github.com/reactiverse/es4x/releases/download/${ES4X_VERSION}/es4x-pm-${ES4X_VERSION}-bin.tar.gz | tar zx --strip-components=1 -C /usr/local
 ---> Using cache
 ---> 2f05d31e6e18
Step 9/18 : ENV ES4X_ENV=production
 ---> Using cache
 ---> 4228ed7928bc
Step 10/18 : COPY --from=NPM /usr/src/app /usr/src/app
 ---> 991dbaaefec4
Step 11/18 : WORKDIR /usr/src/app
 ---> Running in c3ee472f02cf
Removing intermediate container c3ee472f02cf
 ---> 55e47f3b5ca6
Step 12/18 : RUN es4x install -f
 ---> Running in 5753641ae12d
Usage: es4x install [OPTIONS] [arg...]

Installs required jars from maven to 'node_modules'.

Options and Arguments:
 -f,--force                             Will always install a basic runtime in the current working dir.
 -v,--vendor <value>    Comma separated list of vendor jars.
 -l,--link                              Symlink jars instead of copy.
 -s,--silent                            Return statuscode 65 on success.

The command '/bin/sh -c es4x install -f' returned a non-zero code: 2

CMD LIne (No Docker):


$ /bin/sh -c es4x install -f
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/.../StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/node_modules/@es4x/create/slf4j-jdk14-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
ES4X is using graaljs in interpreted mode! Add the JVMCI compiler module in order to run in optimal mode!
Succeeded in deploying verticle```
UglyHobbitFeet commented 4 years ago

FWIW I notice the output above (step 8 of 18) references es4x-pm and not @es4x/create. Dunno if the es4x-pm calls should be removed from the docker stuff and if that's an issue or not. I only have @es4x/create installed on my machine

UglyHobbitFeet commented 4 years ago

Also FWIW I'm using Docker version 19.03.13

pmlopes commented 4 years ago

The docker file downloads the pm tools (same as @es4x/create) to ensure its always available but probably having it globally + already installed from node is causing trouble.

frank-dspeed commented 4 years ago

@pmlopes can you tell me the refactor branch where you did move the install parts to runtime? i am at present lost and do not know where to work on fixes as we goot the require branch that needs merge into upstream asap

pmlopes commented 4 years ago

All development happens on develop, master is the exact code of the latest published release.

pmlopes commented 4 years ago

@UglyHobbitFeet, there's a bug on the generated Dockerfile, I'll fix it soon as vert.x 3.9.4 is about to be released so I'll ship it together, in the mean time this should be the dockerfile:

ARG BASEIMAGE=oracle/graalvm-ce:20.2.0
# Use official node for build
FROM node:lts AS NPM
# Create app directory
WORKDIR /usr/src/app
# Add the application to the container
COPY . .
# Install app dependencies
# npm is run with unsafe permissions because the default docker user is root
RUN npm --unsafe-perm ci

# Second stage (build the JVM related code)
FROM $BASEIMAGE AS JVM
ARG ES4X_VERSION=0.13.2
ARG ES4X_OPTS=""
# Download the ES4X runtime tool
RUN curl -sL https://github.com/reactiverse/es4x/releases/download/${ES4X_VERSION}/es4x-pm-${ES4X_VERSION}-bin.tar.gz | tar zx --strip-components=1 -C /usr/local
# force es4x maven resolution only to consider production dependencies
ENV ES4X_ENV=production
# Copy the previous build step
COPY --from=NPM /usr/src/app /usr/src/app
# use the copied workspace
WORKDIR /usr/src/app
# Install the maven dependencies
RUN find .
RUN es4x install $ES4X_OPTS

# Third stage (contain)
FROM $BASEIMAGE
# Collect the jars from the previous step
COPY --from=JVM /usr/src/app /usr/src/app
# use the copied workspace
WORKDIR /usr/src/app
# Bundle app source
COPY . .
# Define custom java options for containers
ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:+UseContainerSupport"
# define the entrypoint
ENTRYPOINT [ "./node_modules/.bin/es4x-launcher" ]
UglyHobbitFeet commented 4 years ago

Works as expected. Thanks!

On Tue, Oct 13, 2020 at 6:04 AM Paulo Lopes notifications@github.com wrote:

Closed #425 https://github.com/reactiverse/es4x/issues/425 via bf67f36 https://github.com/reactiverse/es4x/commit/bf67f36f906fa78829a60bd343a9d46ee69c5bef .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/reactiverse/es4x/issues/425#event-3870436694, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALBDS7UGLAT4LZIPBYJN4HLSKQQ4JANCNFSM4SKBHWQQ .

UglyHobbitFeet commented 4 years ago

Just curious but it seems like the docker images are fairly high out of the box. I did a bare bones test with 4 small js files and this package.json and when I run a 'docker images' I see my image is 1.21GB. It looks like GraaalVM takes up 900MB of that. Is there an alternative you can recommend or a flag we could pass when doing 'es4x dockerfile' that would toggle between a slim and fat version?

{
  "name": "my-test",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "dependencies": {
    "@vertx/core": "3.9.3",
    "@vertx/mongo-client": "^3.9.3",
    "@vertx/web": "^3.9.3",
    "@vertx/web-client": "^3.9.3"
  },
  "devDependencies": {
    "@es4x/create": "0.13.2"
  },
  "scripts": {
    "postinstall": "es4x install",
    "start": "es4x"
  }
}