Skip to content

Commit

Permalink
fix: dockers
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Jan 28, 2024
1 parent 7328bfb commit 8da34c9
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 58 deletions.
91 changes: 91 additions & 0 deletions docker/docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
version: "3.8"

services:
app:
build:
context: .
dockerfile: packages/app/Dockerfile
container_name: #{PROJECT_NAME}#_app
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
ports:
- "3000:3000"

crons:
build:
context: .
dockerfile: packages/app/crons/Dockerfile
container_name: #{PROJECT_NAME}#_crons
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"

docs:
build:
context: .
dockerfile: packages/docs/Dockerfile
container_name: #{PROJECT_NAME}#_docs
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
ports:
- "3001:3000"
#? You can comment the volumes section if you are not using the static files
volumes:
- .:/docs/.docusaurus

landing:
build:
context: .
dockerfile: packages/landing/Dockerfile
container_name: #{PROJECT_NAME}#_landing
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
ports:
- "3002:3000"

db:
image: postgres:latest
container_name: #{PROJECT_NAME}#_db
restart: unless-stopped
volumes:
- #{PROJECT_NAME}#-postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASS}
POSTGRES_DB: ${DATABASE_NAME}

logging:
driver: "json-file"
options:
max-size: "50m"
ports:
- "5432:5432"

redis:
image: redis:latest
restart: unless-stopped
container_name: #{PROJECT_NAME}#_redis
command: /bin/sh -c "redis-server --requirepass ${REDIS_PASSWORD}"
logging:
driver: "json-file"
options:
max-size: "50m"
volumes:
- #{PROJECT_NAME}#-redis-data:/data
ports:
- "6379:6379"

volumes:
#{PROJECT_NAME}#-postgres-data:
#{PROJECT_NAME}#-redis-data:
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ services:
- "5432:5432"

redis:
image: redis:latest
restart: unless-stopped
container_name: #{PROJECT_NAME}#_redis
image: redis:latest
command: /bin/sh -c "redis-server --requirepass ${REDIS_PASSWORD}"
logging:
driver: "json-file"
Expand Down
29 changes: 6 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 32 additions & 9 deletions packages/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
FROM node:20-alpine
FROM node:20-alpine AS deps

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ENV NODE_ENV production

#? Copy the necessary files to install dependencies
COPY package*.json .
COPY packages/lib/package*.json ./packages/lib/
COPY packages/app/package*.json ./packages/app/
COPY packages/app/prisma/schema.prisma ./packages/app/prisma/schema.prisma

RUN npm i --only=production


FROM node:20-alpine AS builder

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

COPY package.json .
COPY package-lock.json .
COPY prisma/schema.prisma ./prisma/schema.prisma
COPY --from=deps /usr/src/app .

RUN npm i --only=production
COPY packages/lib ./packages/lib
COPY packages/app ./packages/app

RUN npm run build -w packages/app


FROM node:20-alpine AS runner

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . .
ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

RUN npm run build
COPY --from=builder /usr/src/app .

EXPOSE 3000

CMD [ "npm", "start" ]
CMD [ "npm", "start", "-w", "packages/app" ]
27 changes: 18 additions & 9 deletions packages/app/crons/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
FROM node:20-alpine
FROM node:20-alpine AS deps

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

COPY package.json .
COPY package-lock.json .
COPY prisma/schema.prisma ./prisma/schema.prisma
#? Copy the necessary files to install dependencies
COPY package*.json .
COPY packages/lib/package*.json ./packages/lib/
COPY packages/app/package*.json ./packages/app/
COPY packages/app/prisma/schema.prisma ./packages/app/prisma/schema.prisma

RUN npm i --only=production

COPY . .

CMD [ "npm", "run", "cron" ]
FROM node:20-alpine AS runner

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY --from=deps /usr/src/app .

COPY packages/lib ./packages/lib
COPY packages/app ./packages/app


CMD [ "npm", "run", "cron", "-w", "packages/app" ]
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scripts": {
"dev": "npm run is-initialized && prisma migrate dev && cross-env FORCE_COLOR=1 next dev",
"build": "next build",
"start": "npm run deploy-db:prod && next start",
"start": "npm run deploy-db:prod && next start --port ${PORT:-3000}",
"start:with-cron": "npm run deploy-db:prod && concurrently \"next start\" \"npm run cron\"",
"deploy-db:prod": "prisma migrate deploy && npm run seed",
"cron": "tsx ./crons/index.ts",
Expand Down
Loading

0 comments on commit 8da34c9

Please sign in to comment.