FROM node:16-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN rm -f next.config.js
COPY ./next.config.local.js ./next.config.js
RUN rm -f .env.production && mv .env.local .env.production
RUN npm run build
# Production image, copy all the files and run next
FROM node:16-alpine AS runner
RUN apk --update --no-cache --virtual build-dependencies add \
nginx
RUN npm install -g pm2
WORKDIR /app
ENV NODE_ENV production
ENV APP_ENV local
ENV NEXT_TELEMETRY_DISABLED 1
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/pages ./pages
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/ecosystem.config.js ./ecosystem.config.js
# RUN cd /app/data/en-gb/products && cp me-888-marathon-ultra.json me-888-marathon-ultra-oth.json
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/entrypoint.sh /usr/local/bin/entrypoint
RUN chmod +x /usr/local/bin/entrypoint
ENTRYPOINT [ "entrypoint" ]
CMD ["nginx"]
# Create a file app/docker/entrypoint.sh
# ------------------------------------------
#!/bin/sh
set -e
# pm2-docker --max-memory-restart 300M --deep-monitoring start "npm start" & nginx
pm2-runtime ecosystem.config.js & nginx
## Create a file in app/ecosystem.config.js
module.exports = {
apps: [
{
name: "app",
cwd: "/app",
script: "node_modules/next/dist/bin/next",
args: "start",
max_memory_restart: "900M"
}
]
};
Comments