@Arcgis/core with Next JS build in Docker fails due to out of memory error

7359
6
Jump to solution
04-13-2021 10:48 AM
zhenming91
Emerging Contributor

Followed the instructions here by @BenElan in setting up ArcGIS in a Next JS app.

For this test, I have used @BenElan  repository sample   in particular, jaspi-create-next-app. 

All works fine in my local computer, and I was able to run `yarn build` successfully. 

I added a new Dockerfile. 

However, the build fails when I run `yarn build` inside a Docker container. 

I confirm that by removing the `EsriMapwithNoSSR` component will result in a successful build. So the issue lies with the way arcgis@core and Next JS works. 

I suspect a memory leak is occurring somewhere. 

Here is the logs from the build : 

 

---

Mings-MacBook-Pro:jsapi-create-next-app ming$ docker build . -t test2
[+] Building 154.9s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/node:15.5.0-alpine 0.9s
=> [1/6] FROM docker.io/library/node:15.5.0-alpine@sha256:5b91260f78485bfd4a1614f1afa9afd59920e4c35047ed1c2b8cde4 0.0s
=> [internal] load build context 0.4s
=> => transferring context: 296.34kB 0.3s
=> CACHED [2/6] WORKDIR /user/src/playstation 0.0s
=> [3/6] COPY package.json . 0.1s
=> [4/6] RUN yarn 72.0s
=> [5/6] COPY . . 0.8s
=> ERROR [6/6] RUN yarn build 80.5s
------
> [6/6] RUN yarn build:
#10 0.921 yarn run v1.22.5
#10 1.040 $ next build
#10 2.922 Browserslist: caniuse-lite is outdated. Please run:
#10 2.922 npx browserslist@latest --update-db
#10 3.278 info - Creating an optimized production build...
#10 3.309 Attention: Next.js now collects completely anonymous telemetry regarding usage.
#10 3.309 This information is used to shape Next.js' roadmap and prioritize features.
#10 3.309 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
#10 3.309 https://nextjs.org/telemetry
#10 3.309
#10 79.91 error Command failed with signal "SIGKILL".
#10 79.91 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
zhenming91
Emerging Contributor

 

This is my Docker file, and I am using Mac OS. 

FROM node:15.5.0-alpine

WORKDIR /user/src/playstation

COPY package.json .

RUN yarn

COPY . .

RUN yarn build

EXPOSE 3000

CMD yarn start


I have used the next build, and true enough the assets are no longer required. However, running using your Dockerfile result in the same error. So that didn't solve it. 

What I did was to increase my Docker resource memory from 1GB initially to 8.5GB, and it works now. I have no clue why this resolves it. 

 

zhenming91_0-1618416094614.png

 

 

View solution in original post

0 Kudos
6 Replies
ReneRubalcava
Honored Contributor

With the next build, you don't need to copy the assets by default anymore. If you have that in there, you can remove it and it will save on files copied and processed. This will cut down a solid 20MB+ of static asset files on disk in the build. Other than that, it wouldn't be a memory leak issue with the API.

0 Kudos
zhenming91
Emerging Contributor

Hey Rene, 

I am not clear with what you are suggesting. 

The map wouldn't function without the assets in the public folder. I have just tried it. The @Anonymous User/core version that I am using is 4.18.1 

0 Kudos
ReneRubalcava
Honored Contributor

Use the next build as described here.

npm install @Anonymous User/core@next

 

0 Kudos
by Anonymous User
Not applicable

When 4.19 is released I'll update the samples with the change Rene mentioned.

by Anonymous User
Not applicable

Hi,

Can you provide your Dockerfile and some more information about your environment? The sample works on my end with the Dockerfile below. I'm on Windows using the Hyper-V backend. I'll test on my Linux machine as well, but unfortunately I don't have a Mac.

 

 

# Install dependencies only when needed
FROM node:alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN mkdir -p /app/public/assets
RUN npm ci

# Rebuild the source code only when needed
FROM node:alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN npm run build

# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app

ENV NODE_ENV production

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
RUN chown -R nextjs:nodejs /app/.next
USER nextjs

EXPOSE 3000

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
RUN npx next telemetry disable

CMD ["npm", "start"]

 

Edit: most of that is from the NextJS deployment doc

0 Kudos
zhenming91
Emerging Contributor

 

This is my Docker file, and I am using Mac OS. 

FROM node:15.5.0-alpine

WORKDIR /user/src/playstation

COPY package.json .

RUN yarn

COPY . .

RUN yarn build

EXPOSE 3000

CMD yarn start


I have used the next build, and true enough the assets are no longer required. However, running using your Dockerfile result in the same error. So that didn't solve it. 

What I did was to increase my Docker resource memory from 1GB initially to 8.5GB, and it works now. I have no clue why this resolves it. 

 

zhenming91_0-1618416094614.png

 

 

0 Kudos