version: '3.7'

services:
  app_proxy:
    environment:
      APP_HOST: sure_web_1
      APP_PORT: 3000

  web:
    image: ghcr.io/we-promise/sure:0.6.9@sha256:3d899b3eced520d8d3166a3d53184cbb1356670fb52d050f94f8e62e59754d70
    user: "1000:1000"
    volumes:
      - ${APP_DATA_DIR}/data/rails:/rails/storage
    restart: on-failure
    environment:
      POSTGRES_USER: sure_user
      POSTGRES_PASSWORD: sure_password
      POSTGRES_DB: sure_production
      SECRET_KEY_BASE: $APP_SEED
      SELF_HOSTED: "true"
      RAILS_FORCE_SSL: "false"
      RAILS_ASSUME_SSL: "false"
      DB_HOST: sure_db_1
      DB_PORT: 5432
      REDIS_URL: redis://sure_redis_1:6379/1
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy

  worker:
    image: ghcr.io/we-promise/sure:0.6.9@sha256:3d899b3eced520d8d3166a3d53184cbb1356670fb52d050f94f8e62e59754d70
    user: "1000:1000"
    command: bundle exec sidekiq
    volumes:
      - ${APP_DATA_DIR}/data/rails:/rails/storage
    restart: on-failure
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      POSTGRES_USER: sure_user
      POSTGRES_PASSWORD: sure_password
      POSTGRES_DB: sure_production
      SECRET_KEY_BASE: $APP_SEED
      SELF_HOSTED: "true"
      RAILS_FORCE_SSL: "false"
      RAILS_ASSUME_SSL: "false"
      DB_HOST: sure_db_1
      DB_PORT: 5432
      REDIS_URL: redis://sure_redis_1:6379/1

  db:
    image: postgres:18.3-alpine@sha256:52098013b4b64a746626437d38afc03cabff6cdeb4d3d92e2342aa95f0ce56ea
    user: "1000:1000"
    restart: on-failure
    volumes:
      - ${APP_DATA_DIR}/data/postgres:/data
    environment:
      POSTGRES_USER: sure_user
      POSTGRES_PASSWORD: sure_password
      POSTGRES_DB: sure_production
      PGDATA: /data/pgdata
    healthcheck:
      test: "pg_isready -U sure_user -h localhost -d sure_production"
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

  redis:
    image: redis:8.4.2@sha256:4b0ab81cf4d84e610215d0159dcc218d4ec6180f869a9bc83c33a1945d6f3e42
    user: "1000:1000"
    restart: on-failure
    volumes:
      - ${APP_DATA_DIR}/data/redis:/data
    healthcheck:
      test: redis-cli ping
      interval: 5s
      timeout: 5s
      retries: 5
      start_period: 30s
