version: '3.8'

services:
  bitwarden-frontend:
    image: nginx:1.15-alpine
    container_name: bitwarden-frontend
    restart: unless-stopped
    volumes:
      - ./bitwarden.conf:/etc/nginx/conf.d/bitwarden.conf
    networks:
      - traefik
      - db
    depends_on:
      - bitwarden-backend
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.bw.entrypoints=websecure"
      - "traefik.http.routers.bw.rule=Host(`bw.$DOMAIN_NAME`)"
      - "traefik.http.routers.bw.tls.certresolver=letsencr"
      - "traefik.docker.network=traefik"
      - "traefik.http.services.bw.loadbalancer.server.port=80"
    logging:
      driver: "json-file"
      options:
        max-size: "1m"

  bitwarden-backend:
    image: vaultwarden/server:latest
    container_name: bitwarden-backend
    restart: unless-stopped
    volumes:
      - /srv/vaultwarden_data:/data
    environment:
      - WEBSOCKET_ENABLED=true
    networks:
      - db
    logging:
      driver: "json-file"
      options:
        max-size: "1m"

  bitwarden-backup:
    image: bruceforce/bw_backup:latest
    container_name: bitwarden-backup
    restart: unless-stopped
    depends_on:
      - bitwarden-backend
    volumes:
      - /srv/vaultwarden_data:/data
      - /srv/vaultwarden_data_backup:/backup
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - DB_FILE=/data/db.sqlite3
      - BACKUP_FILE=/backup/backup.sqlite3
      - CRON_TIME=0 1 * * *
      - TIMESTAMP=false
      - UID=0
      - GID=0
    networks:
      - db
    logging:
      driver: "json-file"
      options:
        max-size: "1m"


# version: '3.9'

# services:
#   vaultwarden:
#     image: vaultwarden/server:latest #swap tag to raspberry to run on a raspberry pi
#     volumes:
#       - '/srv/vaultwarden_data:/data'
#     restart: on-failure
#     environment:
#       WEBSOCKET_ENABLED: '${WEBSOCKET_ENABLED}'
#       SIGNUPS_ALLOWED: '${SIGNUPS_ALLOWED}'
# #      SIGNUPS_DOMAINS_WHITELIST: '${SIGNUPS_DOMAINS_WHITELIST}'
#       SIGNUPS_VERIFY: '${SIGNUPS_VERIFY}'
#       INVITATIONS_ALLOWED: '${INVITATIONS_ALLOWED}'
#       SHOW_PASSWORD_HINT: '${SHOW_PASSWORD_HINT}'
# #      ADMIN_TOKEN: '${ADMIN_TOKEN}'
# #      DISABLE_ADMIN_TOKEN: '${DISABLE_ADMIN_TOKEN}'

#       # Mail Server
# #      SMTP_HOST: '${SMTP_HOST}'
# #      SMTP_FROM: '${SMTP_FROM}'
# #      SMTP_PORT: '${SMTP_PORT}'
# #      SMTP_SECURITY: '${SMTP_SECURITY}'
# #      SMTP_USERNAME: '${SMTP_USERNAME}'
# #      SMTP_PASSWORD: '${SMTP_PASSWORD}'

#       # Logging
#       LOG_FILE: '/data/vaultwarden.log'
#       LOG_LEVEL: '${LOG_LEVEL}'
# #      USE_SYSLOG: '${USE_SYSLOG}'
# #      EXTENDED_LOGGING: '${EXTENDED_LOGGING}'

#       # YubiKey authentication
# #      YUBICO_CLIENT_ID: '${YUBICO_CLIENT_ID}'
# #      YUBICO_SECRET_KEY: '${YUBICO_SECRET_KEY}'
# #      YUBICO_SERVER: '${YUBICO_SERVER}'

#   nginx:
#     build: './Docker/nginx'
#     links:
#       - vaultwarden
#       - vw_backup
#     environment:
#       VIRTUAL_HOST: '${VIRTUAL_HOST}'
#     command: /bin/sh -c "/run_nginx.sh"
#     restart: on-failure
#     networks:
#       - traefik
#       - db
#     labels:
#       - "traefik.enable=true"
#       - "traefik.http.routers.bw.entrypoints=websecure"
#       - "traefik.http.routers.bw.rule=Host(`bw.$DOMAIN_NAME`)"
#       - "traefik.http.routers.bw.tls.certresolver=letsencr"
#       - "traefik.docker.network=traefik"
#       - "traefik.http.services.bw.loadbalancer.server.port=80"

#   vw_backup:
#     image: bruceforce/bw_backup:latest #swap tag to rpi3 to run on a raspberry pi
#     restart: on-failure
#     depends_on:
#       - vaultwarden
#     networks:
#       - db
#     volumes:
#       - '/srv/vaultwarden_data:/data'
#       - '/srv/vaultwarden_data_backup:/backup'
#       - '/etc/timezone:/etc/timezone:ro'
#       - '/etc/localtime:/etc/localtime:ro'
#     environment:
#       - DB_FILE=/data/db.sqlite3
#       - BACKUP_FILE=/backup/backup.sqlite3
#       - BACKUP_FILE_PERMISSIONS=700
#       - CRON_TIME=0 1 * * *
#       - TIMESTAMP=false
#       - UID=0
#       - GID=0
networks:
  traefik:
    external: true
  db:
    external: false