From 0a2494cd7e94465e1365d1bd03f1f621e422c1a0 Mon Sep 17 00:00:00 2001 From: Sanjib Kumar Sen Date: Sun, 16 Feb 2025 12:27:04 +0600 Subject: [PATCH 1/3] added prod --- Dockerfile | 32 ++++++++++++++++++++++++++++ docker-compose.yml | 45 +++++++++++++++++++++++++++++++++++++++ package.json | 5 +++-- src/app.ts | 3 ++- src/config/minioClient.ts | 12 +++++------ 5 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4e5bc80 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Build stage +FROM oven/bun:1 AS builder + +WORKDIR /app + +# Copy package files +COPY package.json . +COPY bun.lockb . + +# Install dependencies +RUN bun install --frozen-lockfile + +# Copy source code +COPY . . + +# RUN DB Migrations and build +RUN bun run db:migrate && bun run build + +# Production stage +FROM debian:bookworm-slim + +WORKDIR /app + +# Copy only the compiled binary from builder +COPY --from=builder /app/server . + +# Expose the port your app runs on +EXPOSE 3000 + +# Run the binary +CMD ["./server"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e363536 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +services: + api: + build: + context: . + dockerfile: Dockerfile + ports: + - "${SERVER_PORT}:${SERVER_PORT}" + depends_on: + - db + - minio + environment: + NODE_ENV: production + DATABASE_URL: ${DATABASE_URL} + + db: + image: postgres:latest + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_NAME} + ports: + - "${DB_PORT}:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + minio: + image: minio/minio:latest + ports: + - "9000:9000" + - "9001:9001" + environment: + MINIO_ROOT_USER: ${MINIO_ROOT_USER} + MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD} + command: server /data --console-address ":9001" + volumes: + - minio_data:/data + healthcheck: + test: ["CMD", "mc", "ready", "local"] + interval: 30s + timeout: 20s + retries: 3 + +volumes: + postgres_data: + minio_data: diff --git a/package.json b/package.json index abb47f0..3d937cf 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", "db:push": "drizzle-kit push:pg", + "build": "bun build --compile --minify-whitespace --minify-syntax --target bun --outfile server ./src/app.ts", "dev": "bun run --watch src/app.ts" }, "dependencies": { @@ -14,6 +15,7 @@ "@elysiajs/cookie": "^0.8.0", "@elysiajs/cors": "^1.2.0", "@elysiajs/swagger": "^1.2.0", + "drizzle-kit": "^0.30.2", "dotenv": "^16.4.7", "drizzle-orm": "^0.38.4", "elysia": "latest", @@ -26,8 +28,7 @@ "devDependencies": { "@types/pg": "^8.11.10", "bun-types": "latest", - "drizzle-kit": "^0.30.2", "tsx": "^4.19.2" }, "module": "src/app.js" -} \ No newline at end of file +} diff --git a/src/app.ts b/src/app.ts index 86f25ab..251e3fe 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,7 +8,8 @@ import { api } from "./api"; const allowedOrigins = [ "http://localhost:5175", "http://localhost:5173", - "https://your-production-site.com", + "https://dashboard.planpostai.com", + "https://canvas.planpostai.com", ]; const app = new Elysia({ diff --git a/src/config/minioClient.ts b/src/config/minioClient.ts index 798b1a1..3cb989f 100644 --- a/src/config/minioClient.ts +++ b/src/config/minioClient.ts @@ -2,9 +2,9 @@ import { Client } from "minio"; import { ENV } from "../config/env"; export const minioClient = new Client({ - endPoint: ENV.MINIO_ENDPOINT!, - port: ENV.MINIO_PORT, - useSSL: false, - accessKey: ENV.MINIO_ACCESS_KEY, - secretKey: ENV.MINIO_SECRET_KEY, -}) \ No newline at end of file + endPoint: ENV.MINIO_ENDPOINT!, + port: ENV.MINIO_PORT, + useSSL: false, + accessKey: ENV.MINIO_ACCESS_KEY, + secretKey: ENV.MINIO_SECRET_KEY, +}) -- 2.45.3 From b247985a93cce47090e3e9ef0b2911f243299183 Mon Sep 17 00:00:00 2001 From: Sanjib Kumar Sen Date: Wed, 19 Feb 2025 10:57:22 +0600 Subject: [PATCH 2/3] done --- Dockerfile | 25 +++++++++++++++---------- docker-compose.yml | 12 ++++++++++-- entrypoint.sh | 9 +++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 4e5bc80..92c9f67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,20 +13,25 @@ RUN bun install --frozen-lockfile # Copy source code COPY . . -# RUN DB Migrations and build -RUN bun run db:migrate && bun run build +# Build the application +RUN bun run build # Production stage -FROM debian:bookworm-slim +# FROM debian:bookworm-slim -WORKDIR /app +# WORKDIR /app -# Copy only the compiled binary from builder -COPY --from=builder /app/server . +# # Copy only the compiled binary from builder +# COPY --from=builder /app/server . -# Expose the port your app runs on -EXPOSE 3000 +# # Expose the port your app runs on +# EXPOSE 3000 -# Run the binary -CMD ["./server"] +# # Copy the entrypoint script +# COPY entrypoint.sh . +# Make the entrypoint script executable +RUN chmod +x ./entrypoint.sh + +# Set the entrypoint +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e363536..2adf7e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,10 @@ services: ports: - "${SERVER_PORT}:${SERVER_PORT}" depends_on: - - db - - minio + db: + condition: service_healthy + minio: + condition: service_healthy environment: NODE_ENV: production DATABASE_URL: ${DATABASE_URL} @@ -22,6 +24,12 @@ services: - "${DB_PORT}:5432" volumes: - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s minio: image: minio/minio:latest diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..628bb4d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +# Run migrations +bun run db:migrate + +# Start the application +echo "Starting the application..." +./server \ No newline at end of file -- 2.45.3 From 53d2c7b46af0d25702c01f3c415b7b6bfced3976 Mon Sep 17 00:00:00 2001 From: Sanjib Kumar Sen Date: Wed, 19 Feb 2025 11:26:00 +0600 Subject: [PATCH 3/3] coolify needs no port --- docker-compose.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2adf7e1..954a020 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,8 @@ services: build: context: . dockerfile: Dockerfile - ports: - - "${SERVER_PORT}:${SERVER_PORT}" + # ports: + # - "${SERVER_PORT}:${SERVER_PORT}" depends_on: db: condition: service_healthy @@ -20,8 +20,8 @@ services: POSTGRES_USER: ${DB_USER} POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_DB: ${DB_NAME} - ports: - - "${DB_PORT}:5432" + # ports: + # - "${DB_PORT}:5432" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: @@ -33,9 +33,9 @@ services: minio: image: minio/minio:latest - ports: - - "9000:9000" - - "9001:9001" + # ports: + # - "9000:9000" + # - "9001:9001" environment: MINIO_ROOT_USER: ${MINIO_ROOT_USER} MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD} -- 2.45.3