Skip to content

Commit

Permalink
chore: moving deploy to docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopr committed May 16, 2023
1 parent a3ae014 commit 4058b33
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"**/.git": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/node_modules": true,
"**/node_modules": false,
"**/.next": true,
"**/.contentlayer": true,
"**/tsconfig.tsbuildinfo": true,
Expand Down
57 changes: 57 additions & 0 deletions Dockerfile.client
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base 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

# Install dependencies based on the preferred package manager
COPY yarn.lock ./
COPY apps/client/package.json ./
RUN yarn --frozen-lockfile


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY ./apps/client .
COPY --from=deps /app/node_modules ./node_modules

RUN yarn prisma generate

# 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 during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

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

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]
5 changes: 4 additions & 1 deletion apps/client/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
NEXTAUTH_SECRET="secret"
NEXTAUTH_URL="http://localhost:3000"
NEXT_PUBLIC_BACKEND_URL="http://localhost:5000/api/v1"
NEXT_PUBLIC_BACKEND_URL="http://localhost:5000/api/v1"
APP_URL=""
EMAIL_NO_REPLY=""
EMAIL_PASS=""
5 changes: 5 additions & 0 deletions apps/client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/.pnp
.pnp.js

# robots.txt
robots.txt

# sitemaps
sitemap*.xml
# testing
/coverage

Expand Down
3 changes: 1 addition & 2 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
"vercel-build": "prisma generate && next build",
"dev": "next dev",
"lint": "next lint",
"start": "next start -p 8080",
"start": "next start -p 3001",
"prettier": "prettier --write --ignore-unknown .",
"content": "npx contentlayer build",
"prettier:check": "prettier --check --ignore-unknown .",
"lint:multi": "prettier:check && pnpm lint",
"postinstall": "npx contentlayer build",
"postbuild": "next-sitemap",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ services:
- '6379:6379'
volumes:
- cache:/data
client:
build:
context: .
dockerfile: Dockerfile.client
target: builder
command: yarn start
expose:
- "3001"
ports:
- "3001:3001"
volumes:
cache:
driver: local
11 changes: 1 addition & 10 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,5 @@ module.exports = {
autorestart: true,
watch: false,
max_memory_restart: '1G',
},
{
name: 'client',
script: 'pnpm',
args: "start",
cwd: "./apps/client",
autorestart: true,
watch: false,
max_memory_restart: '1G',
}]
}]
};

0 comments on commit 4058b33

Please sign in to comment.