Vanilla docker compose configuration?

few fixes:

  • comments use # and not //
  • web command was missing a coma
  • missing DATABASE_URL in migrations (and worker I guess)
  • &ssl=false at the end of DATABASE_URL to avoid erorr
  • DATABASE_URL not using the .env vars
  • remove web command
  • health check not using the dynamic port
  • port messing port (ecto) and port_url (public port, possibly managed by reverse proxy)
  • worker port need to use the internal port as it will contact the web through the compose internal network
  • missing env file to the worker (therefore not access to worker_secret)
  • adding the collections link in worker as proposed by ReferenceError: collections is not defined - #5 by mtuchi
  • (bonus) i added traefik config for the ingress
version: '3.8'

services:
  postgres:
    deploy:
      resources:
        limits:
          cpus: '${DOCKER_POSTGRES_CPUS:-0}'
          memory: '${DOCKER_POSTGRES_MEMORY:-0}'
    environment:
      - POSTGRES_USER=${POSTGRES_USER:-postgres}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
      - POSTGRES_DB=${POSTGRES_DB:-lightning_dev}
    image: 'postgres:14.2-alpine'
    restart: '${DOCKER_RESTART_POLICY:-unless-stopped}'
    stop_grace_period: '3s'
    volumes:
      - 'postgres-lightning-latest:/var/lib/postgresql/data'

  migrations:
    image: 'openfn/lightning:latest'
    command: ["/app/bin/lightning", "eval", "Lightning.Release.migrate"]
    env_file:
      - 'OpenFn/openfn.env'
    environment:
      - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-lightning_dev}?ssl=false
    depends_on:
      - postgres

  web:
    image: openfn/lightning:latest
    env_file:
      - 'OpenFn/openfn.env'    
    environment:
            - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-lightning_dev}?ssl=false
    deploy:
      resources:
        limits:
          cpus: '${DOCKER_WEB_CPUS:-0}'
          memory: '${DOCKER_WEB_MEMORY:-0}'
    depends_on:
      migrations:
        condition: service_completed_successfully
      postgres: 
        condition: service_started
    healthcheck:
      test: '${DOCKER_WEB_HEALTHCHECK_TEST:-curl localhost:${PORT}/health_check}'
      interval: '10s'
      timeout: '3s'
      start_period: '5s'
      retries: 3
    ports:
      - '${LIGHTNING_EXTERNAL_PORT:-127.0.0.1:${PORT-4000}}:${PORT-4000}'
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.lighning.rule=Host(`${URL_HOST}`)"
      - "traefik.http.routers.lighning.entrypoints=websecure"
      - "traefik.http.services.lighning.loadbalancer.server.port=4000"
    volumes:
      - "./adaptors:/adaptors"
  worker:
    image: 'openfn/ws-worker:latest'
    env_file:
      - 'OpenFn/openfn.env'
    environment:
      - WORKER_COLLECTIONS_URL: "http://web:4000/collections"
    deploy:
      resources:
        limits:
          cpus: '${DOCKER_WORKER_CPUS:-0}'
          memory: '${DOCKER_WEB_MEMORY:-0}'
    depends_on:
      web:
        condition: service_healthy
        restart: true
    command:
      ['pnpm', 'start:prod', '-l', 'ws://web:${PORT-4000}/worker']
    restart: '${DOCKER_RESTART_POLICY:-unless-stopped}'
    stop_grace_period: '3s'
    expose:
      - '2222'
    volumes:
      - "./adaptors:/adaptors"
volumes:
  postgres-lightning-latest: {}