x-env: &env POSTGRES_DB: accounts POSTGRES_USER: accounts POSTGRES_PASSWORD: accounts TBA_DEV: yes services: postgres: image: postgres:17 volumes: - "db:/var/lib/postgresql/data" ports: - "5433:5432" # Note: host is exposed to 5433! environment: POSTGRES_USER: accounts POSTGRES_DB: accounts POSTGRES_PASSWORD: accounts # set shared memory limit when using docker-compose shm_size: 128mb # Keycloak's postgres database kcpostgres: image: postgres:17 volumes: - "kcdb:/var/lib/postgresql/data" ports: - "5434:5434" # Note: host is exposed to 5434! environment: POSTGRES_USER: kc POSTGRES_DB: keycloak POSTGRES_PASSWORD: kc PGPORT: 5434 # set shared memory limit when using docker-compose shm_size: 128mb redis: image: redis/redis-stack volumes: - "cache:/data" ports: - "6380:6379" # Redis exposed on port 6380 - "8071:8001" # Insights exposed on port 8071 accounts: &accounts build: context: . dockerfile: ./Dockerfile ports: - "8087:8087" environment: <<: *env ALLOWED_HOSTS: '*' volumes: - "./.env:/app/.env:z" - "./.env.test:/app/.env.test:z" - "./src/thunderbird_accounts:/app/src/thunderbird_accounts:z" - "./assets:/app/assets:z" - "./keycloak:/app/assets/keycloak:z" - "./templates:/app/templates:z" - "./coverage:/app/coverage:z" depends_on: - postgres - redis develop: watch: - action: rebuild path: .env - action: rebuild path: .env.test - action: rebuild path: ./src - action: rebuild path: ./assets - action: rebuild path: ./keycloak - action: rebuild path: ./templates celery: <<: *accounts ports: [] # Workaround for embedded beat (--beat) spinning at 100% CPU in Docker. # Docker inherits a huge SC_OPEN_MAX (~1B) causing close_open_fds() to loop. # https://github.com/celery/celery/issues/8306 ulimits: nofile: soft: 10000 hard: 10000 environment: <<: *env TBA_CELERY: yes flower: <<: *accounts ports: - "5555:5555" environment: <<: *env TBA_FLOWER: yes # Only used when APP_DEBUG=True vite-dev: build: context: . dockerfile: ./Dockerfile # Run both vite devserver for accounts frontend, and the keycloak theme builder entrypoint: bash -c 'npm run dev & npm run dev-theme' ports: - "5173:5173" volumes: - "./.env:/app/.env:z" - "./.env.test:/app/.env.test:z" - "./vite.config.mts:/app/vite.config.mts:z" - "./tsconfig.json:/app/tsconfig.json:z" - "./src/thunderbird_accounts:/app/src/thunderbird_accounts:z" - "./assets:/app/assets:z" - "./templates:/app/templates:z" - "./keycloak/themes:/app/keycloak/themes:z" stalwart_legacy: image: stalwartlabs/stalwart:v0.15.4 #build: # context: ../stalwart # dockerfile: Dockerfile volumes: - "./mail/stalwart_legacy:/opt/stalwart:z" ports: - "443:443" - "8080:8080" - "8081:8081" - "25:25" - "587:587" - "465:465" - "143:143" - "993:993" - "4190:4190" - "110:110" - "995:995" environment: <<: *env ADMIN_SECRET: "{plain}accounts" MAIL_STALWART_PATH: "/opt/stalwart" # Seeds an empty stalwart_data with the shipped Keycloak OIDC directory and example.org domain, without which a # clean v0.16 rejects every user token. Runs as the image's stalwart user, which owns a freshly created volume. stalwart_new_seed: image: stalwartlabs/stalwart:v0.16 entrypoint: ["sh", "-c", "[ -e /var/lib/stalwart/main.db ] || cp /seed/main.db.example /var/lib/stalwart/main.db"] volumes: - "./mail/stalwart/lib/main.db.example:/seed/main.db.example:ro,Z" - "stalwart_data:/var/lib/stalwart" stalwart_new: image: stalwartlabs/stalwart:v0.16 hostname: 'stalwart_new' domainname: 'stalwart_new.local' #entrypoint: bash # Stalwart fetches the seeded OIDC directory's discovery document once, at startup, and never retries. depends_on: stalwart_new_seed: condition: service_completed_successfully keycloak: condition: service_healthy volumes: - "./mail/stalwart/etc:/etc/stalwart:Z" - "stalwart_data:/var/lib/stalwart" ports: - "8443:443" - "8180:8080" # - "8081:8081" # - "25:25" # - "587:587" # - "465:465" # - "143:143" # - "993:993" # - "4190:4190" # - "110:110" # - "995:995" environment: STALWART_RECOVERY_ADMIN: "admin:admin" networks: default: aliases: - stalwart_new.local keycloak: #image: quay.io/keycloak/keycloak:latest build: context: . dockerfile: Dockerfile.keycloak ports: - "8999:8999" - "9000:9000" # If you need to export the realm uncomment this. You'll see the data in ./keycloak/data/export #entrypoint: '/opt/keycloak/bin/kc.sh export --dir /opt/keycloak/data/export' environment: KC_HTTP_PORT: 8999 KC_HOSTNAME: keycloak KC_HOSTNAME_STRICT_BACKCHANNEL: "true" KC_HEALTH_ENABLED: "true" KC_LOG_LEVEL: info KC_DB: "postgres" KC_DB_URL_HOST: "kcpostgres" KC_DB_URL_PORT: '5434' KC_DB_USERNAME: "kc" KC_DB_PASSWORD: "kc" KC_DEV: yes # Run the container with start-dev instead of start KC_SPI_THEME_WELCOME_THEME: "tbpro" KC_TBPRO_HOME: "http://localhost:8087/" KC_TBPRO_SIGN_UP: "http://localhost:8087/sign-up" KC_TBPRO_CONTACT: "http://localhost:8087/contact" KC_TBPRO_PRIMARY_DOMAIN: "example.org" # keycloak-mfa-rest: allow the accounts OIDC client's user tokens to self-manage MFA. KC_SPI_REALM_RESTAPI_EXTENSION_MFA_AUTHORIZED_CLIENTS: "thunderbird-accounts" # keycloak-mfa-rest step-up gate: sensitive mutations on an account with MFA already # in place need a token at this acr with auth_time no older than this window. Keep # the window aligned with accounts' MFA_RECENT_AUTH_SECONDS (600) so the accounts # pre-check and the provider's token check expire together. KC_SPI_REALM_RESTAPI_EXTENSION_MFA_STEP_UP_ACR: "2" KC_SPI_REALM_RESTAPI_EXTENSION_MFA_STEP_UP_MAX_AGE_SECONDS: "600" # keycloak-config-cli (see scripts/apply-cli-config.sh) reconciles the MFA step-up flow # on startup (among other scripts), authenticating as the same admin client the accounts # app uses (pulled from.env). # MFA_L1_LOA_MAX_AGE MUST be at least the realm's longest possible SSO session — # that is ssoSessionMaxLifespanRememberMe (7776000, 90 days, reconciled everywhere by # keycloak/config-cli/tbpro-mfa-stepup.yaml) — or a still-valid remember-me session # re-prompts for the password when the L1 window lapses. KEYCLOAK_ADMIN_CLIENT_ID: "${KEYCLOAK_ADMIN_CLIENT_ID:-tb-accounts-admin}" KEYCLOAK_ADMIN_CLIENT_SECRET: "${KEYCLOAK_ADMIN_CLIENT_SECRET:-}" MFA_L1_LOA_MAX_AGE: "7776000" # Thundermail provisioning gate (see keycloak/config-cli/tbpro-mfa-stepup.yaml); the # realm import provides the role, scope and thunderbird-accounts exemption. DISABLED turns it off. TBPRO_MAIL_GATE: "CONDITIONAL" volumes: - "./keycloak/themes:/opt/keycloak/themes:z" - "./keycloak/data/export:/opt/keycloak/data/export:z" # Healthy once the tbpro realm's discovery document is served. The image has bash but no curl. healthcheck: test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8999 && printf 'GET /realms/tbpro/.well-known/openid-configuration HTTP/1.1\\r\\nHost: keycloak:8999\\r\\nConnection: close\\r\\n\\r\\n' >&3 && read -r status <&3 && [[ $$status == *' 200'* ]]"] interval: 5s start_period: 60s retries: 60 # Capturing keycloak emails for dev mailpit: image: axllent/mailpit environment: - MP_SMTP_AUTH_ALLOW_INSECURE=true ports: - "8025:8025" # Web UI - "1025:1024" # SMTP volumes: db: {} kcdb: {} cache: {} stalwart_data: {}