Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dockerfile to deploy app #577

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/backend/DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:22-alpine AS base
RUN apk update
RUN apk add --no-cache libc6-compat
RUN npm i -g pnpm

FROM base AS builder
WORKDIR /app
RUN npm i -g turbo@~2.0.6
COPY . .
RUN turbo telemetry disable
RUN turbo prune backend --docker

FROM base AS installer
WORKDIR /app
COPY --from=builder /app/out/json/ .
RUN pnpm i
COPY --from=builder /app/out/full/ .
RUN pnpm turbo build --filter=backend...

FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nestjs
USER nestjs

COPY --from=installer --chown=nestjs:nodejs /app/ ./

EXPOSE 8080
ENV PORT 8080
ENV HOSTNAME "0.0.0.0"
6 changes: 3 additions & 3 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"vitnode-backend-email-smtp": "workspace:*"
},
"devDependencies": {
"@nestjs/cli": "^10.4.7",
"@nestjs/cli": "^10.4.8",
"@nestjs/schematics": "^10.2.3",
"@swc/cli": "^0.5.0",
"@swc/cli": "^0.5.1",
"@types/express": "^5.0.0",
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"@types/react": "^18.3.12",
"cross-env": "^7.0.3",
"eslint-config-typescript-vitnode": "workspace:*",
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Module } from '@nestjs/common';
import { join } from 'path';
import { VitNodeCoreModule } from 'vitnode-backend/app.module';
// import { emailResend } from 'vitnode-backend-email-resend';
// import { emailSMTP } from 'vitnode-backend-email-smtp';
Expand All @@ -13,7 +12,6 @@ import { PluginsModule } from './plugins/plugins.module';
@Module({
imports: [
VitNodeCoreModule.register({
pathToEnvFile: join(process.cwd(), '..', '..', '.env'),
database: {
config: DATABASE_ENVS,
schemaDatabase,
Expand Down
37 changes: 37 additions & 0 deletions apps/frontend/DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:22-alpine AS base
RUN apk update
RUN apk add --no-cache libc6-compat
RUN npm i -g pnpm

FROM base AS builder
WORKDIR /app
RUN npm i -g turbo@^2
COPY . .
RUN turbo prune frontend --docker

FROM base AS installer
WORKDIR /app
COPY --from=builder /app/out/json/ .
RUN pnpm i
COPY --from=builder /app/out/full/ .
COPY --from=builder /app/.prettierrc.mjs ./

ARG NEXT_PUBLIC_BACKEND_URL
ENV NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
ARG NEXT_PUBLIC_BACKEND_CLIENT_URL
ENV NEXT_PUBLIC_BACKEND_CLIENT_URL=${NEXT_PUBLIC_BACKEND_CLIENT_URL}
ARG NEXT_PUBLIC_FRONTEND_URL
ENV NEXT_PUBLIC_FRONTEND_URL=${NEXT_PUBLIC_FRONTEND_URL}

RUN pnpm turbo run build --filter=frontend...

FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

COPY --from=installer --chown=nextjs:nodejs /app/apps/frontend/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/frontend/.next/static ./apps/frontend/.next/static

CMD node apps/frontend/server.js
2 changes: 1 addition & 1 deletion apps/frontend/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NextConfig } from 'next';
import VitNodeConfig from 'vitnode-frontend/next.config';

const nextConfig: NextConfig = {
// output: 'standalone',
output: 'standalone',
logging: {
fetches: {
fullUrl: true,
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"autoprefixer": "^10.4.20",
Expand Down
2 changes: 1 addition & 1 deletion apps/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"devDependencies": {
"@types/multer": "^1.4.12",
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"eslint-config-typescript-vitnode": "workspace:*",
Expand Down
88 changes: 37 additions & 51 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
version: '3.8'

services:
# database:
# container_name: vitnode_database
# image: postgres:16.3-alpine
# restart: unless-stopped
# environment:
# POSTGRES_USER: ${DB_USER}
# POSTGRES_PASSWORD: ${DB_PASSWORD}
# POSTGRES_DB: ${DB_DATABASE:-vitnode}
# ports:
# - '${DB_PORT:-5432}:${DB_PORT:-5432}'
# volumes:
# - ./docker/prod/database:/var/lib/postgresql/data
# networks:
# - vitnode
# backend:
# container_name: vitnode_backend
# build:
# context: .
# dockerfile: ./apps/backend/Dockerfile
# restart: unless-stopped
# environment:
# - DB_HOST=${DB_HOST:-database}
# - DB_PORT=${DB_PORT:-5432}
# - DB_USER=${DB_USER}
# - DB_PASSWORD=${DB_PASSWORD}
# - DB_DATABASE=${DB_DATABASE:-vitnode}
# - LOGIN_TOKEN_SECRET=${LOGIN_TOKEN_SECRET}
# - NEXT_PUBLIC_FRONTEND_URL=${NEXT_PUBLIC_FRONTEND_URL:-http://localhost:3000}
# command: sh -c "cd backend && pnpm config:init && pnpm start:prod"
# ports:
# - '8080:8080'
# depends_on:
# - database
# volumes:
# - ./frontend/config:/app/frontend/config # config
# - ./frontend/app:/app/frontend/app # app
# - ./frontend/plugins:/app/frontend/plugins # plugins
# - ./backend/uploads:/app/backend/uploads # uploads
# - ./backend/schema.gql:/app/backend/schema.gql # schema
# - ./backend/src/plugins:/app/backend/src/plugins # plugins
# networks:
# - vitnode
database:
container_name: vitnode_database
image: postgres:16.3-alpine
restart: unless-stopped
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE:-vitnode}
ports:
- '${DB_PORT:-5432}:${DB_PORT:-5432}'
volumes:
- ./docker/prod/database:/var/lib/postgresql/data
networks:
- vitnode
backend:
container_name: vitnode_backend
build:
context: .
dockerfile: ./apps/backend/DockerFile
restart: unless-stopped
depends_on:
- database
environment:
DB_HOST: ${DB_HOST:-database}
env_file:
- .env
command: sh -c "cd apps/backend && pnpm config:init && node dist/main.js"
ports:
- '8080:8080'
volumes:
- ./apps/backend/uploads:/app/apps/backend/uploads # uploads
- ./apps/backend/src/plugins/core:/app/apps/backend/src/plugins/core # core
networks:
- vitnode
frontend:
container_name: vitnode_frontend
build:
context: .
dockerfile: ./apps/frontend/Dockerfile
dockerfile: ./apps/frontend/DockerFile
args:
- NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL:-http://localhost:8080}
- NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL:-http://backend:8080}
- NEXT_PUBLIC_BACKEND_CLIENT_URL=${NEXT_PUBLIC_BACKEND_CLIENT_URL:-http://localhost:8080}
- NEXT_PUBLIC_FRONTEND_URL=${NEXT_PUBLIC_FRONTEND_URL:-http://localhost:3000}
restart: unless-stopped
# command: sh -c "cd frontend && pnpm start:prod"
ports:
- '3000:3000'
# depends_on:
# - backend
# volumes:
# - ./frontend/config:/app/frontend/config # config
# - ./frontend/app:/app/frontend/app # app
# - ./frontend/plugins:/app/frontend/plugins # admin
networks:
- vitnode

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "turbo lint",
"lint:fix": "turbo lint:fix",
"docker:dev": "docker compose -f ./docker-compose-dev.yml -p vitnode-dev up -d",
"docker:prod": "sh docker-prod.sh",
"docker:prod": "docker compose -f ./docker-compose.yml -p vitnode-prod up -d",
"docker:clear": "sudo docker system prune -a",
"release": "node ./bump-version.mjs",
"db": "turbo db"
Expand All @@ -28,7 +28,7 @@
"packages/*"
],
"devDependencies": {
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"eslint-config-typescript-vitnode": "workspace:*",
"turbo": "^2.3.0"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/backend-ai-google/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Provide `aiGoogle` to `VitNodeCoreModule` and chose the model you want to use:

```ts title="apps/backend/src/app.module.ts"
import { Module } from '@nestjs/common';
import { join } from 'path';
import { VitNodeCoreModule } from 'vitnode-backend';
import { aiGoogle } from 'vitnode-backend-ai-google';

Expand All @@ -52,7 +51,6 @@ import { PluginsModule } from './plugins/plugins.module';
@Module({
imports: [
VitNodeCoreModule.register({
pathToEnvFile: join(process.cwd(), '..', '..', '.env'),
database: {
config: DATABASE_ENVS,
schemaDatabase,
Expand Down
8 changes: 4 additions & 4 deletions packages/backend-ai-google/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"gemini"
],
"devDependencies": {
"@swc/cli": "^0.5.0",
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.2",
"@types/node": "^22.9.0",
"ai": "^3.4.33",
"@types/node": "^22.9.1",
"ai": "^4.0.2",
"concurrently": "^9.1.0",
"eslint-config-typescript-vitnode": "workspace:*",
"typescript": "^5.6.3"
},
"dependencies": {
"@ai-sdk/google": "^0.0.55"
"@ai-sdk/google": "^1.0.1"
}
}
2 changes: 0 additions & 2 deletions packages/backend-ai-open-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Provide `aiOpenAi` to `VitNodeCoreModule` and chose the model you want to use:

```ts title="apps/backend/src/app.module.ts"
import { Module } from '@nestjs/common';
import { join } from 'path';
import { VitNodeCoreModule } from 'vitnode-backend';
import { aiOpenAi } from 'vitnode-backend-ai-open-ai';

Expand All @@ -52,7 +51,6 @@ import { PluginsModule } from './plugins/plugins.module';
@Module({
imports: [
VitNodeCoreModule.register({
pathToEnvFile: join(process.cwd(), '..', '..', '.env'),
database: {
config: DATABASE_ENVS,
schemaDatabase,
Expand Down
8 changes: 4 additions & 4 deletions packages/backend-ai-open-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"chatgpt"
],
"devDependencies": {
"@swc/cli": "^0.5.0",
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.2",
"@types/node": "^22.9.0",
"ai": "^3.4.33",
"@types/node": "^22.9.1",
"ai": "^4.0.2",
"concurrently": "^9.1.0",
"eslint-config-typescript-vitnode": "workspace:*",
"typescript": "^5.6.3"
},
"dependencies": {
"@ai-sdk/openai": "^0.0.72"
"@ai-sdk/openai": "^1.0.2"
}
}
2 changes: 0 additions & 2 deletions packages/backend-email-resend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Provide `emailResend` to `VitNodeCoreModule`:

```ts title="apps/backend/src/app.module.ts"
import { Module } from '@nestjs/common';
import { join } from 'path';
import { VitNodeCoreModule } from 'vitnode-backend';
import { emailResend } from 'vitnode-backend-email-resend';

Expand All @@ -53,7 +52,6 @@ import { PluginsModule } from './plugins/plugins.module';
@Module({
imports: [
VitNodeCoreModule.register({
pathToEnvFile: join(process.cwd(), '..', '..', '.env'),
database: {
config: DATABASE_ENVS,
schemaDatabase,
Expand Down
6 changes: 3 additions & 3 deletions packages/backend-email-resend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"resend"
],
"devDependencies": {
"@swc/cli": "^0.5.0",
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.2",
"@types/node": "^22.9.0",
"@types/node": "^22.9.1",
"concurrently": "^9.1.0",
"eslint-config-typescript-vitnode": "workspace:*",
"typescript": "^5.6.3"
},
"dependencies": {
"resend": "^4.0.0"
"resend": "^4.0.1"
}
}
2 changes: 0 additions & 2 deletions packages/backend-email-smtp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Provide `emailSMTP` to `VitNodeCoreModule`:

```ts title="apps/backend/src/app.module.ts"
import { Module } from '@nestjs/common';
import { join } from 'path';
import { VitNodeCoreModule } from 'vitnode-backend';
import { emailSMTP } from 'vitnode-backend-email-smtp';

Expand All @@ -57,7 +56,6 @@ import { PluginsModule } from './plugins/plugins.module';
@Module({
imports: [
VitNodeCoreModule.register({
pathToEnvFile: join(process.cwd(), '..', '..', '.env'),
database: {
config: DATABASE_ENVS,
schemaDatabase,
Expand Down
6 changes: 3 additions & 3 deletions packages/backend-email-smtp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"smtp"
],
"devDependencies": {
"@swc/cli": "^0.5.0",
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.2",
"@types/node": "^22.9.0",
"@types/nodemailer": "^6.4.16",
"@types/node": "^22.9.1",
"@types/nodemailer": "^6.4.17",
"concurrently": "^9.1.0",
"eslint-config-typescript-vitnode": "workspace:*",
"typescript": "^5.6.3"
Expand Down
Loading
Loading