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
14 changes: 13 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
node_modules
npm-debug.log*
coverage
dist
.git
.github
.env
.env.local
.env.*.local
test
docker-compose*.yml
*.log
.DS_Store
npm-debug.log
coverage
.git
Expand All @@ -8,4 +20,4 @@ README.md
.env
.env.local
docker-compose.override.yml
.dockerignore
.dockerignore
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ PORT=3000
# REDIS_URL: URL. Required in production. Development/test default: redis://localhost:6379.
REDIS_URL=redis://localhost:6379

# PostgreSQL (used by the Docker local stack and future persistence features)
DATABASE_URL=postgres://smartdrop:smartdrop@localhost:5432/smartdrop

# Stellar Horizon
# DATABASE_URL: URL. Required in production. Development default: postgres://localhost/smartdrop. Test default: postgres://localhost/smartdrop_test.
DATABASE_URL=postgres://localhost/smartdrop

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
.env
.env.local
.env.*.local
docker-compose.override.yml
dist/
*.log
.DS_Store
15 changes: 14 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
FROM node:20-alpine AS builder

WORKDIR /app
ENV NODE_ENV=production
# --- Base & Development Stage ---
FROM node:20-alpine AS development
WORKDIR /app
Expand All @@ -19,6 +23,8 @@ WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev

FROM node:20-alpine AS production

COPY src ./src

# --- Production Stage ---
Expand All @@ -27,8 +33,15 @@ 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"]
COPY --from=builder /app/src ./src
COPY package*.json ./

EXPOSE 4000
CMD ["node", "src/index.js"]
CMD ["node", "src/index.js"]
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ Registers subscriber endpoints for SmartDrop lifecycle events and delivers signe

You can spin up the entire local development stack—including the API, PostgreSQL database, and Redis instance—using a single command.

### 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
* Ensure you have [Docker and Docker Compose](https://docs.docker.com/get-docker/) installed.

Expand Down
39 changes: 38 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
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'
build:
context: .
target: development
Expand All @@ -17,11 +36,18 @@ services:
postgres:
condition: service_healthy
volumes:
- ./src:/app/src
- ./src:/app/src # Hot reload en desarrollo

redis:
image: redis:7-alpine
ports:
- '6379:6379'
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 5s
timeout: 3s
retries: 12
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
Expand All @@ -36,9 +62,20 @@ services:
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:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "smartdrop"]
interval: 5s
timeout: 3s
retries: 5
retries: 5
Loading