From b7ee6863e5536ceb48538fde9a2fc56e2f1535bb Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Mon, 31 Oct 2022 17:28:27 -0400 Subject: [PATCH] feat: docker support for easy deployment --- .gitignore | 5 ++++- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ docker-compose.example.yml | 23 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.example.yml diff --git a/.gitignore b/.gitignore index c8bb8d0..7888140 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,7 @@ yarn-error.log* #just dev stuff dev/* -yarn.lock \ No newline at end of file +yarn.lock + +# docker +docker-compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bbd5f28 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Thanks @yordis on Github! https://github.com/vercel/next.js/discussions/16995#discussioncomment-132339 + +# Install dependencies only when needed +FROM node:lts-alpine AS deps + +WORKDIR /opt/app +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile + +# Rebuild the source code only when needed +# This is where because may be the case that you would try +# to build the app based on some `X_TAG` in my case (Git commit hash) +# but the code hasn't changed. +FROM node:lts-alpine AS builder + +ENV NODE_ENV=production +WORKDIR /opt/app +COPY . . +COPY --from=deps /opt/app/node_modules ./node_modules +RUN yarn build + +# Production image, copy all the files and run next +FROM node:lts-alpine AS runner + +ARG X_TAG +WORKDIR /opt/app +ENV NODE_ENV=production +COPY --from=builder /opt/app/next.config.mjs ./ +COPY --from=builder /opt/app/public ./public +COPY --from=builder /opt/app/.next ./.next +COPY --from=builder /opt/app/node_modules ./node_modules +ENV HOST=0.0.0.0 +ENV PORT=3000 +CMD ["node_modules/.bin/next", "start"] \ No newline at end of file diff --git a/docker-compose.example.yml b/docker-compose.example.yml new file mode 100644 index 0000000..ce76c57 --- /dev/null +++ b/docker-compose.example.yml @@ -0,0 +1,23 @@ +# docker-compose.yml + +version: '3' + +services: + frontend: + container_name: libremdb + build: + context: . + network: host + ports: + - "3000:3000" + env_file: .env.local + depends_on: + - redis + restart: always + redis: + container_name: libremdb_redis + image: redis + # FOR DEBUGGING ONLY + # ports: + # - "6379:6379" + restart: always \ No newline at end of file