version: '3.9'

services:
  vaultwarden:
    image: vaultwarden/server:1.30.5
    environment:
      DOMAIN: https://vaultwarden.pressmess.duckdns.org
      SIGNUPS_ALLOWED: 'false'
      SMTP_HOST: smtp
      SMTP_FROM: noreply@local
      SMTP_PORT: 587
      SMTP_SECURITY: starttls
      SMTP_USERNAME_FILE: /run/secrets/smtp_user
      SMTP_PASSWORD_FILE: /run/secrets/smtp_pass
      # PostgreSQL database configuration
      DATABASE_URL: postgresql://vaultwarden:vaultwarden123@postgres:5432/vaultwarden
      # Enable admin interface for database management
      ADMIN_TOKEN_FILE: /run/secrets/vaultwarden_admin_token
    ports:
      - "8088:80"
    secrets:
      - smtp_user
      - smtp_pass
      - vaultwarden_admin_token
    volumes:
      - vaultwarden_data:/data
    networks:
      - caddy-public
    deploy:
      placement:
        constraints:
          - "node.labels.role==db"
      replicas: 1

volumes:
  vaultwarden_data:
    driver: local
    driver_opts:
      type: nfs
      o: addr=192.168.50.229,nolock,soft,rw
      device: :/export/vaultwarden

secrets:
  smtp_user:
    external: true
  smtp_pass:
    external: true
  vaultwarden_admin_token:
    external: true

networks:
  caddy-public:
    external: true
