Ctrl K
ComunidadGuías…

docker-compose.dev.postgres.yml

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
# The usage ping and error reports are on by default (ADR 0003), and a development stack must not
# send either to Peekaping. These point both at an address nothing listens on. To try them against
# a test endpoint, set TELEMETRY_URL and ERROR_REPORTING_DSN in .env.
x-no-reports: &no-reports
  TELEMETRY_URL: ${TELEMETRY_URL:-http://127.0.0.1:9/v1/ping}
  ERROR_REPORTING_DSN: ${ERROR_REPORTING_DSN:-http://public@127.0.0.1:9/1}

networks:
  appnet:

services:
  database:
    image: postgres:17
    restart: unless-stopped
    ports:
      - "${DB_PORT:-5432}:5432"
    env_file:
      - .env
    environment:
      POSTGRES_USER: ${DB_USER:-postgres}
      POSTGRES_PASSWORD: ${DB_PASS:-password}
      POSTGRES_DB: ${DB_NAME:-peekaping}
    volumes:
      - ./.data/postgres:/var/lib/postgresql/data
    networks:
      - appnet
    healthcheck:
      # Check over TCP: the temporary server the image runs during first-time init only listens on the socket.
      test: ["CMD-SHELL", "pg_isready -h localhost -U ${DB_USER:-postgres} -d ${DB_NAME:-peekaping}"]
      interval: 30s
      timeout: 2s
      retries: 5
      start_period: 30s
      start_interval: 1s

  redis:
    image: redis:7
    restart: always
    ports:
      - "${REDIS_PORT:-6379}:6379"
    networks:
      - appnet
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 2s
      retries: 5
      start_period: 30s
      start_interval: 1s

  migrate:
    build:
      context: ./apps/server
      dockerfile: infra/Dockerfile.migrate
    restart: "no"
    env_file:
      - .env
    depends_on:
      database:
        condition: service_healthy
    networks:
      - appnet

  api:
    build:
      context: ./apps/server
      dockerfile: infra/Dockerfile.api
    restart: unless-stopped
    ports:
      - "8034:8034"
    env_file:
      - .env
    environment:
      <<: *no-reports
      # The web container on localhost:8383 calls the API on localhost:8034, another origin.
      CORS_ORIGINS: "${CORS_ORIGINS-http://localhost:8383}"
      # The local probe's token: the api stores it, and the probe sends it. Without it no
      # monitor is checked.
      PROBE_BOOTSTRAP_TOKEN: "${PROBE_BOOTSTRAP_TOKEN:?PROBE_BOOTSTRAP_TOKEN is not set: add it to .env as a random string of at least 32 characters, such as the output of openssl rand -hex 32}"
    depends_on:
      database:
        condition: service_healthy
      redis:
        condition: service_healthy
      migrate:
        condition: service_completed_successfully
    networks:
      - appnet
    healthcheck:
      test: ["CMD-SHELL", "wget -qO - http://localhost:8034/api/v1/health || exit 1"]
      interval: 30s
      timeout: 2s
      retries: 5
      start_period: 30s
      start_interval: 1s

  # The local probe: its instances run the checks of the monitors that run on the local probe.
  # They connect to the api, so they need no database, no Redis and no volume.
  probe:
    build:
      context: ./apps/server
      dockerfile: infra/Dockerfile.probe
    restart: unless-stopped
    # the probe takes up to 25 seconds to shut down cleanly
    stop_grace_period: 30s
    environment:
      PEEKAPING_URL: http://api:8034
      # The probe refuses a plain http:// address to another host unless told otherwise.
      # This one stays on the compose network.
      PROBE_ALLOW_INSECURE: "true"
      # The token the api stores on the local probe (PROBE_BOOTSTRAP_TOKEN)
      PROBE_TOKEN: "${PROBE_BOOTSTRAP_TOKEN:?PROBE_BOOTSTRAP_TOKEN is not set: add it to .env as a random string of at least 32 characters, such as the output of openssl rand -hex 32}"
      LOG_LEVEL: ${LOG_LEVEL:-info}
    depends_on:
      api:
        condition: service_healthy
    networks:
      - appnet

  web:
    build:
      context: .
      dockerfile: ./apps/web/Dockerfile
    restart: unless-stopped
    ports:
      - "8383:80"
    environment:
      - API_URL=http://localhost:8034
    depends_on:
      api:
        condition: service_healthy
    networks:
      - appnet
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:80 || exit 1"]
      interval: 30s
      timeout: 2s
      retries: 5
      start_period: 30s
      start_interval: 1s