services:
  frontend:
    restart: always
    image: wavtool.com/frontend-dev
    build:
      context: frontend
      dockerfile: Dockerfile.dev
    user: "1000:1000"
    volumes:
      - .:/WavTool
    ports:
      - 3002:3002
    environment:
      VITE_API_BASE_URL: "https://localhost:3001"
      VITE_LANDING_PAGE_URL: "https://localhost:3000"
    command:
      - /bin/sh
      - -c
      - |
        set -e
        cd /WavTool/frontend
        yarn install --frozen-lockfile
        exec yarn start
  landing-page:
    restart: always
    image: wavtool.com/landing-page-dev
    build:
      context: landing-page
      dockerfile: Dockerfile.dev
    user: "1000:1000"
    volumes:
      - .:/WavTool
    ports:
      - 3000:3000
    environment:
      NEXT_PUBLIC_SERVER_URL: "https://localhost:3001"
      NEXT_PUBLIC_APP_URL: "https://localhost:3002"
    command:
      - /bin/sh
      - -c
      - |
        set -e
        cd /WavTool/landing-page
        yarn install --frozen-lockfile
        PORT=3000 exec yarn dev
  server:
    restart: always
    image: wavtool.com/server-dev
    build:
      context: server
      dockerfile: Dockerfile.dev
    user: "1000:1000"
    depends_on:
      database:
        condition: service_healthy
    environment:
      SERVER_URI: "https://localhost:3001"
      APP_URI: "https://localhost:3002"
      LANDING_URI: "https://localhost:3000"
      COOKIE_DOMAIN: localhost
      DATABASE_HOST: database
      DATABASE_USER: wavtool
      DATABASE_NAME: wavtool
      DATABASE_PASSWORD: wavtool
      DATABASE_PORT: 5432
      REDIS_HOST: forward_prod
      REDIS_PORT: 6379
      FUSIONAUTH_URI: "http://forward_prod:9011"
      # DATABASE_PASSWORD: rdv_WTG4kxk2tag2tmj
      # DATABASE_HOST: forward_prod
      # DATABASE_USER: wavtool_readonly
      # DATABASE_PORT: 5433
      # PGSSLMODE: require
    volumes:
      - .:/WavTool
      - $HOME/.kube:/home/node/.kube:ro
      - $HOME/.aws:/home/node/.aws:ro
    ports:
      - 3001:3001
    command:
      - /bin/sh
      - -c
      - |
        set -e
        cd /WavTool/server
        yarn install --frozen-lockfile
        [ ! -f ./built/src/main.js ] && yarn tsc
        yarn ts &
        exec yarn start-exitcrash
  database:
    restart: always
    image: wavtool.com/database-dev
    build:
      context: server
      dockerfile: Dockerfile.pgvector
    user: "1000:1000"
    shm_size: 128mb
    environment:
      POSTGRES_USER: wavtool
      POSTGRES_PASSWORD: wavtool
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./db/local-postgres-data:/var/lib/postgresql/data
    ports:
      - 5434:5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U wavtool -d wavtool"]
      interval: 5s
      retries: 30
      start_period: 5s
      timeout: 5s
  forward_prod:
    restart: always
    image: wavtool.com/kubectl-dev
    build:
      dockerfile: server/Dockerfile.kubectl
    user: "1000:1000"
    volumes:
      - $HOME/.kube:/.kube:ro
      - $HOME/.aws:/.aws:ro
    ports:
      - 5433:5433
      - 6379:6379
      - 9011:9011
    command:
      - /forward_prod_container.sh
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "pg_isready -h localhost -p 5433 -U wavtool_readonly -d wavtool && redis-cli ping",
        ]
      interval: 30s
      retries: 10
      start_period: 10s
      timeout: 10s
  migrate:
    profiles: ["cli-only"]
    user: "1000:1000"
    depends_on:
      database:
        condition: service_healthy
      forward_prod:
        condition: service_healthy
    image: wavtool.com/migrate-dev
    build:
      context: db/migrate
      dockerfile: Dockerfile.dev
    volumes:
      - ./db/migrations:/wavtool/db/migrations
      - ./db/wavtool_schema.sql:/wavtool/db/wavtool_schema.sql
      - ./db/clone_prod.sql:/wavtool/db/clone_prod.sql
      - ./db/migrate/.env:/wavtool/db/migrate/.env
    environment:
      PGHOST: database
      PGUSER: wavtool
      PGPASSWORD: wavtool
      PGDATABASE: wavtool
      PGPORT: "5432"
      PRODUCTION_PGHOST: forward_prod
      PRODUCTION_PGPORT: "5433"
