Baheth - Rails/PostgreSQL/Memcached/Redis/Meilisearch/ChromaDB

Submitted by @AliOsm

Kamal deploy.yml

service: baheth

image: ieasybooks/baheth

registry:
  username: ieasybooks

  password:
    - KAMAL_REGISTRY_PASSWORD

servers:
  web:
    hosts:
      - 127.0.0.1
    options:
      network: "kamal_network"
    labels:
      traefik.http.routers.baheth.entrypoints: websecure
      traefik.http.routers.baheth.rule: Host(`baheth-revamp.ieasybooks.com`)
      traefik.http.routers.baheth.tls: true
      traefik.http.routers.baheth.tls.certresolver: letsencrypt
  worker:
    hosts:
      - 127.0.0.1
    options:
      network: "kamal_network"
    cmd: bundle exec good_job start

volumes:
  - /root/baheth/storage:/rails/storage

traefik:
  options:
    network: "kamal_network"
    publish:
      - "443:443"
    volume:
      - "/letsencrypt/acme.json:/letsencrypt/acme.json"
  args:
    entryPoints.web.address: ":80"
    entryPoints.websecure.address: ":443"
    entryPoints.web.http.redirections.entryPoint.to: websecure
    entryPoints.web.http.redirections.entryPoint.scheme: https
    entryPoints.web.http.redirections.entrypoint.permanent: true
    certificatesResolvers.letsencrypt.acme.email: "[email protected]"
    certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json"
    certificatesResolvers.letsencrypt.acme.httpchallenge: true
    certificatesResolvers.letsencrypt.acme.httpchallenge.entrypoint: web

# Remember to run `kamal env push` after making changes!
env:
  clear:
    DB_HOST: baheth-postgres
    REDIS_URL: redis://baheth-redis:6379
    MEMCACHE_SERVERS: baheth-memcached:11211
    MEILISEARCH_URL: http://baheth-meilisearch:7700
    CHROMA_DB_URL: http://baheth-chromadb:9610
  secret:
    - RAILS_MASTER_KEY
    - POSTGRES_PASSWORD
    - MEILI_MASTER_KEY
    - BLAZER_DATABASE_URL

accessories:
  postgres:
    image: postgres:16
    roles:
      - web
    options:
      network: "kamal_network"
    env:
      clear:
        POSTGRES_DB: baheth_production
        POSTGRES_USER: baheth
      secret:
        - POSTGRES_PASSWORD
    cmd: [
      postgres,
      -c, "pg_stat_statements.track=all",
      -c, "shared_preload_libraries=pg_stat_statements"
    ]
    files:
      - db/production.sql:/docker-entrypoint-initdb.d/setup.sql
    directories:
      - data:/var/lib/postgresql/data

  redis:
    image: redis:7.2.3
    roles:
      - web
    options:
      network: "kamal_network"
    directories:
      - data:/data

  memcached:
    image: memcached:1.6.22
    roles:
      - web
    options:
      network: "kamal_network"
    env:
      clear:
        MEMCACHED_MEMORY_LIMIT: 4096
    directories:
      - data:/var/lib/memcached/data

  meilisearch:
    image: getmeili/meilisearch:v1.5
    roles:
      - web
    options:
      network: "kamal_network"
    env:
      clear:
        --env: production
        --no-analytics: true
        --http-addr: localhost:7700
        --max-indexing-memory: 10Gb
      secret:
        - MEILI_MASTER_KEY
    directories:
      - data.ms:/meili_data/data.ms
      - dumps:/meili_data/dumps
      - snapshots:/meili_data/snapshots

  chromadb:
    image: chromadb/chroma:0.4.18.dev24
    roles:
      - web
    options:
      network: "kamal_network"
    env:
      clear:
        IS_PERSISTENT: 'TRUE'
    cmd: uvicorn chromadb.app:app --workers 1 --host 0.0.0.0 --port 9610 --log-config chromadb/log_config.yml
    directories:
      - data:/chroma/chroma

healthcheck:
  log_lines: 10_000
  max_attempts: 25

asset_path: /rails/public/assets