From 65968fa31c4dd71b7fc7e583634f9f08a7b50b9c Mon Sep 17 00:00:00 2001 From: ProtonsAndElectrons Date: Thu, 25 Jun 2026 01:40:43 +0200 Subject: [PATCH] add docker compose local stack --- .dockerignore | 13 +++++++++++ .env.example | 3 +++ .gitignore | 1 + Dockerfile | 21 +++++++++++++++++ README.md | 25 ++++++++++++++++++++ docker-compose.yml | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9ed7d14 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +node_modules +npm-debug.log* +coverage +dist +.git +.github +.env +.env.local +.env.*.local +test +docker-compose*.yml +*.log +.DS_Store diff --git a/.env.example b/.env.example index 783c72f..479c804 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,9 @@ REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD= +# PostgreSQL (used by the Docker local stack and future persistence features) +DATABASE_URL=postgres://smartdrop:smartdrop@localhost:5432/smartdrop + # Stellar Horizon STELLAR_HORIZON_URL=https://horizon.stellar.org diff --git a/.gitignore b/.gitignore index 35bd2d0..dfd5103 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ .env .env.local .env.*.local +docker-compose.override.yml dist/ *.log .DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f32837 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:20-alpine AS builder + +WORKDIR /app +ENV NODE_ENV=production + +COPY package*.json ./ +RUN npm ci --omit=dev + +FROM node:20-alpine AS production + +WORKDIR /app +ENV NODE_ENV=production + +COPY --from=builder /app/node_modules ./node_modules +COPY package*.json ./ +COPY src ./src + +USER node +EXPOSE 3000 + +CMD ["npm", "start"] diff --git a/README.md b/README.md index 986083f..7ca369c 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,31 @@ Multi-source price oracle that fetches and caches USD prices for Stellar assets. ## Setup +### Quick Start With Docker + +Run the local API, Redis, and Postgres stack with Docker Compose: + +```bash +docker compose up --build +``` + +The API listens on port `4000` in the compose environment: + +```bash +curl http://localhost:4000/health +``` + +The compose stack mounts `./src` into the API container and runs +`npm run dev`, so source changes restart the Node process automatically. Redis +and Postgres include health checks, and `docker-compose.override.yml` is ignored +for local-only secrets or service tweaks. + +To remove containers and the local Postgres volume: + +```bash +docker compose down -v +``` + ### Prerequisites - Node.js >= 20.9.0 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6c0a309 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,57 @@ +services: + api: + build: . + command: npm run dev + environment: + NODE_ENV: development + PORT: 4000 + REDIS_HOST: redis + REDIS_PORT: 6379 + REDIS_PASSWORD: '' + DATABASE_URL: postgres://smartdrop:smartdrop@postgres:5432/smartdrop + STELLAR_HORIZON_URL: https://horizon.stellar.org + USDC_ISSUER: GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335AX2OBFLDTQLNUEHRGPTM6RIA + PRICE_CACHE_TTL: 60 + PRICE_REFRESH_INTERVAL: 30 + PRICE_STALE_THRESHOLD: 5 + PRICE_ANOMALY_THRESHOLD: 10 + LOG_LEVEL: info + CORS_ALLOWED_ORIGINS: http://localhost:3000,http://localhost:3001,http://localhost:4000 + ports: + - '4000:4000' + depends_on: + redis: + condition: service_healthy + postgres: + condition: service_healthy + volumes: + - ./src:/app/src + + redis: + image: redis:7-alpine + ports: + - '6379:6379' + healthcheck: + test: ['CMD', 'redis-cli', 'ping'] + interval: 5s + timeout: 3s + retries: 12 + + postgres: + image: postgres:16-alpine + environment: + POSTGRES_USER: smartdrop + POSTGRES_PASSWORD: smartdrop + POSTGRES_DB: smartdrop + ports: + - '5432:5432' + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U smartdrop -d smartdrop'] + interval: 5s + timeout: 3s + retries: 12 + volumes: + - postgres-data:/var/lib/postgresql/data + +volumes: + postgres-data: