Skip to content
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
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
dist
logs
.git
.gitignore
.env
.env.*
!.env.example
*.md
.husky
.vscode
coverage
C:\tmp
16 changes: 14 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ PORT=3001
SECRET=j!89nKO5as&Js
API_VERSION=v1

DB_HOST=localhost
DB_DATABASE=test2
# CORS
CORS_ORIGIN=*

# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100

# Database
DB_HOST=db
DB_DATABASE=appdb
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_PORT=5432
DB_DIALECT=postgres
DB_TIMEZONE=Asia/Jakarta
DB_LOG=true

# Database Connection Pool
DB_POOL_MIN=2
DB_POOL_MAX=10
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

16 changes: 0 additions & 16 deletions .eslintrc

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Build
run: npm run build

- name: Test
run: npm test
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build stage
FROM node:22-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY tsconfig.json ./
COPY src ./src

RUN npm run build

# Production stage
FROM node:22-alpine

WORKDIR /app

ENV NODE_ENV=production

COPY package*.json ./
RUN npm ci --omit=dev --ignore-scripts && npm cache clean --force

COPY --from=builder /app/dist ./dist

RUN addgroup -g 1001 -S appgroup && \
adduser -S appuser -u 1001 -G appgroup && \
mkdir -p logs && chown appuser:appgroup logs

USER appuser

EXPOSE 3001

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1

CMD ["node", "dist/index.js"]
11 changes: 0 additions & 11 deletions babel.config.json

This file was deleted.

63 changes: 63 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
services:
app:
build: .
ports:
- '${PORT:-3001}:3001'
env_file:
- path: .env
required: false
environment:
- NODE_ENV=${NODE_ENV:-development}
- APP_NAME=${APP_NAME:-my-project}
- SERVER=${SERVER:-development}
- PORT=${PORT:-3001}
- SECRET=${SECRET:-j!89nKO5as&Js}
- API_VERSION=${API_VERSION:-v1}
- CORS_ORIGIN=${CORS_ORIGIN:-*}
- RATE_LIMIT_WINDOW_MS=${RATE_LIMIT_WINDOW_MS:-900000}
- RATE_LIMIT_MAX=${RATE_LIMIT_MAX:-100}
- DB_HOST=${DB_HOST:-db}
- DB_DATABASE=${DB_DATABASE:-appdb}
- DB_USERNAME=${DB_USERNAME:-postgres}
- DB_PASSWORD=${DB_PASSWORD:-postgres}
- DB_PORT=${DB_PORT:-5432}
- DB_DIALECT=${DB_DIALECT:-postgres}
- DB_TIMEZONE=${DB_TIMEZONE:-UTC}
- DB_LOG=${DB_LOG:-true}
- DB_POOL_MIN=${DB_POOL_MIN:-2}
- DB_POOL_MAX=${DB_POOL_MAX:-10}
depends_on:
db:
condition: service_healthy
restart: unless-stopped
networks:
- app-network

db:
image: postgres:16-alpine
env_file:
- path: .env
required: false
environment:
- POSTGRES_DB=${DB_DATABASE:-appdb}
- POSTGRES_USER=${DB_USERNAME:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:-postgres}
ports:
- '${DB_PORT:-5432}:5432'
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U ${DB_USERNAME:-postgres}']
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
networks:
- app-network

volumes:
pgdata:

networks:
app-network:
driver: bridge
75 changes: 0 additions & 75 deletions docs/v1/main.yaml

This file was deleted.

52 changes: 0 additions & 52 deletions docs/v1/roles.yaml

This file was deleted.

Loading