Skip to content

Commit 6e1c398

Browse files
committed
fix dockerfile to build nextjs app
1 parent 0243854 commit 6e1c398

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.git
33
.editorconfig
4-
.gitignore
4+
.gitignore
5+
.next

Dockerfile

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
11
# Stage 1: Compile and Build the app
22

33
# Node veersion
4-
FROM node:14.15.1 as build
4+
FROM node:14.17.3-alpine as build
55

6-
# update
7-
8-
RUN apt-get update
9-
RUN apt-get -y install curl gnupg
10-
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
11-
RUN apt-get -y install nodejs
6+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7+
RUN apk add --no-cache libc6-compat git
128

139
# Set the working directory
14-
WORKDIR /usr/local/app
10+
WORKDIR /app
1511

1612
# Add the source code to app
17-
COPY ./ /usr/local/app/
13+
COPY ./js /app
1814

19-
WORKDIR js
2015
# Install all the dependencies
21-
RUN yarn install
16+
RUN yarn install --frozen-lockfile
2217
RUN yarn bootstrap
2318

2419
# HERE ADD YOUR STORE WALLET ADDRESS
2520
ENV REACT_APP_STORE_OWNER_ADDRESS_ADDRESS=""
2621

2722
# Generate the build of the application
28-
ENV GENERATE_SOURCEMAP=false
2923
RUN yarn build
3024

3125
# Stage 2: Serve app with nginx server
3226

33-
# Use official nginx image as the base image
34-
FROM nginx:latest
27+
# Production image, copy all the files and run next
28+
FROM node:14.17.3-alpine AS runner
29+
WORKDIR /app
30+
31+
ENV NODE_ENV production
32+
33+
RUN addgroup -g 1001 -S nodejs
34+
RUN adduser -S nextjs -u 1001
3535

3636
# Copy the build output to replace the default nginx contents.
37-
COPY --from=build /usr/local/app/js/build/web /usr/share/nginx/html
37+
COPY --from=build /app/packages/web/next.config.js ./
38+
COPY --from=build /app/packages/web/public ./public
39+
COPY --from=build --chown=nextjs:nodejs /app/packages/web/.next ./.next
40+
COPY --from=build /app/node_modules ./node_modules
41+
COPY --from=build /app/packages/web/package.json ./package.json
42+
43+
USER nextjs
44+
45+
EXPOSE 3000
3846

39-
# Expose port 80
40-
EXPOSE 80
47+
CMD ["yarn", "start:prod"]

js/packages/web/.env.production

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
GENERATE_SOURCEMAP=false

js/packages/web/next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const plugins = [
2727

2828
module.exports = withPlugins(plugins, {
2929
reactStrictMode: true,
30+
eslint: {
31+
ignoreDuringBuilds: true,
32+
},
3033
async rewrites() {
3134
return [
3235
{

js/packages/web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"prestart": "npm-link-shared ../common/node_modules/ . react",
4848
"start": "next dev",
4949
"build": "next build",
50+
"start:prod": "next start",
5051
"test": "jest",
5152
"deploy:ar": "arweave deploy-dir ../../build/web --key-file ",
5253
"deploy": "gh-pages -d ../../build/web --repo https://github.com/metaplex-foundation/metaplex",

0 commit comments

Comments
 (0)