Skip to content

Instantly share code, notes, and snippets.

@wanderer20
Last active April 17, 2024 09:44
Show Gist options
  • Save wanderer20/4e3b847f04ac8c4ff6104d9e651359a2 to your computer and use it in GitHub Desktop.
Save wanderer20/4e3b847f04ac8c4ff6104d9e651359a2 to your computer and use it in GitHub Desktop.
[test] docker + pm2 + nuxt
ARG NODE_VERSION=node:21.7.3-alpine
ARG NGINX_VERSION=nginx:1.25.4-alpine
FROM $NODE_VERSION AS production-base
WORKDIR /usr/src/app
COPY ./../app/package*.json ./../app/pnpm-*.yaml ./
RUN apk update
RUN apk add \
--update \
--no-cache \
--upgrade \
bash \
grep \
vim \
nano \
mc \
npm \
git
RUN npm install -g pnpm
RUN NODE_ENV=production pnpm install \
--prefer-offline \
--frozen-lockfile \
--prod=true \
2> >(grep -v warning 1>&2)
RUN pnpm build
FROM $NGINX_VERSION AS production
WORKDIR /var/www/app
COPY ./../docker/default.conf /etc/nginx/conf.d
COPY ./../docker/ecosystem.config.cjs ./
COPY --from=production-base /usr/src/app/.output ./output
RUN apk update
RUN apk add \
--update \
--no-cache \
--upgrade \
bash \
grep \
vim \
nano \
mc \
npm \
git
RUN npm install -g pm2
CMD pm2 start ecosystem.config.cjs --only nuxt-prod && nginx -g 'daemon off;'
module.exports = {
apps: [
{
name: 'nuxt-prod',
port: '3000',
exec_mode: 'cluster',
instances: 'max',
script: './output/server/index.mjs'
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment