mirror of
https://github.com/Leado123/sharesyllabus-server.git
synced 2025-12-13 22:57:28 +00:00
docker deploy
This commit is contained in:
51
.dockerignore
Normal file
51
.dockerignore
Normal file
@@ -0,0 +1,51 @@
|
||||
# Dependencies
|
||||
node_modules
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# IDE
|
||||
.idea
|
||||
.vscode
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Build artifacts
|
||||
dist
|
||||
build
|
||||
|
||||
# Test files
|
||||
*.test.ts
|
||||
*.spec.ts
|
||||
__tests__
|
||||
coverage
|
||||
|
||||
# Documentation
|
||||
README.md
|
||||
*.md
|
||||
|
||||
# Docker
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
.dockerignore
|
||||
|
||||
# Misc
|
||||
*.txt
|
||||
.graphqlconfig
|
||||
vercel.json
|
||||
scripts
|
||||
14
.env.example
Normal file
14
.env.example
Normal file
@@ -0,0 +1,14 @@
|
||||
# Database Configuration
|
||||
DATABASE_URL=postgresql://sms:smspassword@db:5432/smsdb?schema=public
|
||||
|
||||
# PostgreSQL settings (used by docker-compose)
|
||||
POSTGRES_USER=sms
|
||||
POSTGRES_PASSWORD=smspassword
|
||||
POSTGRES_DB=smsdb
|
||||
|
||||
# JWT Secret Key - CHANGE THIS IN PRODUCTION!
|
||||
SECRET_KEY=your-super-secret-key-change-me-in-production
|
||||
|
||||
# Server Configuration
|
||||
NODE_ENV=production
|
||||
PORT=4000
|
||||
45
Dockerfile
Normal file
45
Dockerfile
Normal file
@@ -0,0 +1,45 @@
|
||||
# Use official Bun image
|
||||
FROM oven/bun:1 AS base
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies into a temp directory for caching
|
||||
FROM base AS install
|
||||
RUN mkdir -p /temp/dev
|
||||
COPY package.json bun.lockb /temp/dev/
|
||||
RUN cd /temp/dev && bun install --frozen-lockfile
|
||||
|
||||
# Install production dependencies only
|
||||
RUN mkdir -p /temp/prod
|
||||
COPY package.json bun.lockb /temp/prod/
|
||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
||||
|
||||
# Copy node_modules from temp directory and all source files
|
||||
FROM base AS prerelease
|
||||
COPY --from=install /temp/dev/node_modules node_modules
|
||||
COPY . .
|
||||
|
||||
# Generate Prisma client
|
||||
RUN bunx prisma generate
|
||||
|
||||
# Final production image
|
||||
FROM base AS release
|
||||
COPY --from=install /temp/prod/node_modules node_modules
|
||||
COPY --from=prerelease /app/src ./src
|
||||
COPY --from=prerelease /app/prisma ./prisma
|
||||
COPY --from=prerelease /app/package.json .
|
||||
COPY --from=prerelease /app/tsconfig.json .
|
||||
COPY --from=prerelease /app/node_modules/.prisma ./node_modules/.prisma
|
||||
COPY --from=prerelease /app/node_modules/@prisma ./node_modules/@prisma
|
||||
|
||||
# Create syllabi directory for file uploads
|
||||
RUN mkdir -p /app/syllabi
|
||||
|
||||
# Set environment variables
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=4000
|
||||
|
||||
# Expose port
|
||||
EXPOSE 4000
|
||||
|
||||
# Run database migrations and start the application
|
||||
CMD ["sh", "-c", "bunx prisma migrate deploy && bun run src/index.ts"]
|
||||
38
docker-compose.yml
Normal file
38
docker-compose.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "4000:4000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URL=postgresql://${POSTGRES_USER:-sms}:${POSTGRES_PASSWORD:-smspassword}@db:5432/${POSTGRES_DB:-smsdb}?schema=public
|
||||
- SECRET_KEY=${SECRET_KEY:-your-secret-key-change-in-production}
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- syllabi_data:/app/syllabi
|
||||
restart: unless-stopped
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
- POSTGRES_USER=${POSTGRES_USER:-sms}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-smspassword}
|
||||
- POSTGRES_DB=${POSTGRES_DB:-smsdb}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-sms} -d ${POSTGRES_DB:-smsdb}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
syllabi_data:
|
||||
Reference in New Issue
Block a user