version: '3.6'

services:

  cms:
    image: androiddrew/datasketch:0.1.4
    command: gunicorn cms.wsgi:application --bind 0.0.0.0:5000 --workers 3
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    secrets:
      - datasketch_key
      - pg_passwd_datasketch
    environment:
      - DJANGO_SETTINGS_MODULE=cms.settings.production
      - DB_HOST=db
      - DB_PORT=5432
      - DB_USER=datasketch
    volumes:
      - datasketch-media-vol:/code/media
      - datasketch-static-vol:/code/staticout
    depends_on:
      - db
    networks:
      - datasketch_net

  nginx:
    image: androiddrew/datasketch_nginx:0.1.0
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - 8000:80
    depends_on:
      - cms
    networks:
      - datasketch_net
    volumes:
      - datasketch-media-vol:/var/www/datasketch/media
      - datasketch-static-vol:/var/www/datasketch/static


  db:
    image: postgres:10.5-alpine
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
      # Docker secrets for postgres are referenced by /run/secrets/<secret_name>
    secrets:
      - pg_passwd_datasketch
    environment:
      - POSTGRES_USER=datasketch
      - POSTGRES_PASSWORD_FILE=/run/secrets/pg_passwd_datasketch
      - POSTGRES_DB=datasketch
    expose:
      - 5432
    volumes:
      - datasketch-db-vol:/var/lib/postgresql/data
    networks:
      - datasketch_net


networks:
  datasketch_net:
    driver: overlay

volumes:
  datasketch-db-vol:
    driver: local
    driver_opts:
      type: nfs
      o: addr=nas1.androiddrew.com,rw
      device: ":/volume1/expanse/datasketch_pg_data"
  datasketch-media-vol:
    driver: local
    driver_opts:
      type: nfs
      o: addr=nas1.androiddrew.com,rw
      device: ":/volume1/expanse/datasketch_media"
  datasketch-static-vol:
    driver: local
    driver_opts:
      type: nfs
      o: addr=nas1.androiddrew.com,rw
      device: ":/volume1/expanse/datasketch_static"


secrets:
  pg_passwd_datasketch:
    external: true
  datasketch_key:
    external: true