version: '3.4'

networks:
  traefik-public:
    external: true

services:
  web:
    image: ${DOCKER_REGISTRY}/simple-web
    build:
      context: ./
      dockerfile: Dockerfile
    networks:
      - traefik-public
    healthcheck:
      test: curl --fail http://localhost || exit 1
      interval: 60s
      retries: 5
      start_period: 20s
      timeout: 10s
    volumes:
      - data:/usr/share/nginx/html/data/
    deploy:
      placement:
        constraints:
          - node.labels.www.ftp-data == true
      labels:
        - traefik.enable=true
        - traefik.docker.network=traefik-public
        - traefik.constraint-label=traefik-public
        - traefik.http.routers.simpleweb-http.rule=Host(`www.${PRIMARY_DOMAIN}`)
        - traefik.http.routers.simpleweb-http.entrypoints=http
        - traefik.http.routers.simpleweb-http.middlewares=https-redirect
        - traefik.http.routers.simpleweb-https.rule=Host(`www.${PRIMARY_DOMAIN}`)
        - traefik.http.routers.simpleweb-https.entrypoints=https
        - traefik.http.routers.simpleweb-https.tls=true
        - traefik.http.routers.simpleweb-https.tls.certresolver=le
        - traefik.http.services.simpleweb.loadbalancer.server.port=80
        - traefik.http.routers.simpleweb.middlewares=traefik-headers
    restart: unless-stopped
  ftpd:
    image: stilliard/pure-ftpd
    container_name: pure-ftpd
    ports:
      - "21:21"
      - "30000-30009:30000-30009"
    volumes:
      - data:/home/ftp-data/
    deploy:
      placement:
        constraints:
          - node.labels.www.ftp-data == true
    environment:
      PUBLICHOST: "localhost"
      FTP_USER_NAME: ${FTP_USERNAME?Variable not set}
      FTP_USER_PASS: ${FTP_PASSWORD?Variable not set}
      FTP_USER_HOME: /home/ftp-data
      ADDED_FLAGS: "--tls=2"
      TLS_CN: ${FTP_DOMAIN_FOR_CERT?Variable not set}
      TLS_ORG: ${FTP_ORG_FOR_CERT?Variable not set}
      TLS_C: ${FTP_COUNTRYCODE_FOR_CERT?Variable not set}
    restart: always
volumes:
  data:
