version: "3.7"
services:

  db:
    image: registry.danova.id/new-pmb-development/pmb-ummat/dbpmb:0.0.1
    restart: unless-stopped

    deploy:
      placement:
        constraints:
          - node.labels.vps == true
      resources:
        limits:
          cpus: '0.25'
          memory: 256M

    volumes:
      - db_data:/var/lib/mysql
    networks:
      - pmb-net

  app:
    image: registry.danova.id/new-pmb-development/pmb-ummat/apppmb:0.0.3
    working_dir: /var/www
    restart: unless-stopped

    deploy:
      placement:
        constraints:
          - node.labels.vps == true
      resources:
        limits:
          cpus: '0.25'
          memory: 256M

    depends_on:
      - db

    volumes:
      - app_data:/var/www
    networks:
      - pmb-net

  nginx:
    image: registry.danova.id/new-pmb-development/pmb-ummat/nginxpmb:0.0.1
    working_dir: /var/www
    restart: unless-stopped

    depends_on:
      - db

    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.vps == true
      resources:

        limits:
          cpus: '0.25'
          memory: 128M

      labels:
        - 'traefik.enable=true'
        - 'traefik.constraint-label=traefik-public'
        - 'traefik.docker.network=traefik-public'
        # It can be re-used by other stacks in other Docker Compose files
        - 'traefik.http.middlewares.https-redirect.redirectscheme.scheme=https'
        - 'traefik.http.middlewares.https-redirect.redirectscheme.permanent=true'
        - 'traefik.http.routers.devpmb-http.rule=Host("newpmb.danova.id")'
        - 'traefik.http.routers.devpmb-http.entrypoints=http'
        - 'traefik.http.routers.devpmb-http.middlewares=https-redirect'
        - 'traefik.http.routers.devpmb-https.rule=Host("newpmb.danova.id")'
        - 'traefik.http.routers.devpmb-https.entrypoints=https'
        - 'traefik.http.routers.devpmb-https.tls=true'
        - 'traefik.http.routers.devpmb-https.tls.certresolver=le'
        - 'traefik.http.services.devpmb.loadbalancer.server.port=80'

    volumes:
      - app_data:/var/www
    networks:
      - traefik-public
      - pmb-net

networks:
  traefik-public:
    external: true
  pmb-net:
    driver: overlay

volumes:
  app_data:
  db_data: