
It will run your SQL migration files from apps/api-go/migrations inside a one-off container, apply them to the postgres container, then exit.
migrate/migrate is a separate CLI that just runs .up.sql/.down.sql files.
migrate:
image: migrate/migrate:v4.17.1
depends_on:
postgres:
condition: service_healthy
volumes:
- ./apps/api-go/migrations:/migrations
command: [
"-path", "/migrations",
"-database", "postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable",
"up"
]
restart: "no"
migrate servicedocker-compose.ymlversion: "3.9"
services:
postgres:
image: postgres:16
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres_go
ports:
- "5432:5432"
volumes:
- "pgdata:/var/lib/postgresql/data"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgres_go"]
interval: 5s
timeout: 3s
retries: 30
redis:
image: redis:7
ports:
- "6379:6379"
volumes:
- redisdata:/data
command: ["redis-server", "--appendonly", "yes"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 30
migrate:
image: migrate/migrate:v4.17.1
depends_on:
postgres:
condition: service_healthy
volumes:
- ./apps/api-go/migrations:/migrations
command: [
"-path", "/migrations",
"-database", "postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable",
"up"
]
restart: "no"
api:
build:
context: .
dockerfile: apps/api-go/Dockerfile
image: runstate-api-go:local
command: ["/server"]
ports:
- "3001:3001"
environment:
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable
- REDIS_ADDR=redis:6379
- APP_ENV=${APP_ENV}
- ADMIN_EMAIL=${ADMIN_EMAIL}
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
monitoring-pusher:
image: runstate-api-go:local
entrypoint: ["/monitoring-pusher"]
environment:
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable
- REDIS_ADDR=redis:6379
- MONITORING_STREAM=betteruptime:websites-ticks
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
worker-monitoring:
image: runstate-api-go:local
entrypoint: ["/worker-monitoring"]
environment:
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable
- REDIS_ADDR=redis:6379
- MONITORING_STREAM=betteruptime:websites-ticks
- MONITORING_REGION_NAME=ap-south-1
- MONITORING_GROUP=monitoring-group
- MONITORING_CONSUMER=monitoring-consumer
- STATUS_CHANGE_STREAM=betteruptime:website-status-change
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
worker-status-change:
image: runstate-api-go:local
entrypoint: ["/worker-status-change"]
environment:
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable
- REDIS_ADDR=redis:6379
- STATUS_CHANGE_STREAM=betteruptime:website-status-change
- STATUS_CHANGE_GROUP=status-change-group
- STATUS_CHANGE_CONSUMER=status-change-consumer
- NOTIFICATION_STREAM=betteruptime:website-status-notification
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
worker-notification:
image: runstate-api-go:local
entrypoint: ["/worker-notification"]
environment:
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres_go?sslmode=disable
- REDIS_ADDR=redis:6379
- ADMIN_EMAIL=${ADMIN_EMAIL}
- MAILGUN_DOMAIN=${MAILGUN_DOMAIN}
- MAILGUN_API_KEY=${MAILGUN_API_KEY}
- MAILGUN_SENDER=${MAILGUN_SENDER}
- NOTIFICATION_STREAM=betteruptime:website-status-notification
- NOTIFICATION_GROUP=notification-group
- NOTIFICATION_CONSUMER=notification-consumer
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_healthy
volumes:
pgdata:
redisdata:
docker-compose# Run from root of repo
cd runState
docker compose down -v
docker compose up --build