Skip to content
Open
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
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.git
logs/
*.log
.env
dist/
.vscode/
.idea/
12 changes: 5 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
PORT=4000

CRYPT_SALT=10
JWT_SECRET_KEY=secret123123
JWT_SECRET_REFRESH_KEY=secret123123
TOKEN_EXPIRE_TIME=1h
TOKEN_REFRESH_EXPIRE_TIME=24h
POSTGRES_USER=youruser
POSTGRES_PASSWORD=yourpassword
POSTGRES_DB=knowledgehub
POSTGRES_HOST=db
POSTGRES_PORT=5432
58 changes: 58 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '3.9'

services:
app:
build: .
container_name: knowledge-hub-api
depends_on:
db:
condition: service_healthy
env_file:
- .env
ports:
- "4000:4000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4000/"]
interval: 10s
timeout: 5s
retries: 5
restart: on-failure
networks:
- khubnet

db:
image: postgres:16-alpine
container_name: khub-db
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
networks:
- khubnet

adminer:
image: adminer
container_name: khub-adminer
profiles: ["debug"]
restart: unless-stopped
ports:
- "8080:8080"
networks:
- khubnet

volumes:
pgdata:

networks:
khubnet:
driver: bridge
34 changes: 34 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Stage 1: Build
FROM node:24-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY tsconfig*.json ./
COPY src ./src

RUN npm run build

# Stage 2: Production
FROM node:24-alpine

WORKDIR /app

ENV NODE_ENV=production

COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist

# Install only production dependencies
RUN npm ci --omit=dev

# Use a non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

EXPOSE 4000

CMD ["node", "dist/main.js"]