version: '3'

services:
  nodejs:
    build:
      context: .
      dockerfile: Dockerfile
    image: nodejs
    container_name: beuwiapi
    restart: unless-stopped
    env_file: .env
    volumes:
      - ./production.config.json:/home/beuwi/production.config.json
    networks:
      - app-network
    command: /home/node/app/node_modules/.bin/nodemon index.js
  webserver:
    image: nginx:mainline-alpine
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - web-root:/var/www/html
      - ./nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
      - certbot-var:/var/lib/letsencrypt
      - dhparam:/etc/ssl/certs
    depends_on:
      - nodejs
    networks:
      - app-network
  certbot:
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - certbot-var:/var/lib/letsencrypt
      - web-root:/var/www/html
    depends_on:
      - webserver
    command: certonly --webroot --webroot-path=/var/www/html --email uwiprofinder@gmail.com --agree-tos --no-eff-email --staging -d api.beuwi.app

volumes:
  certbot-etc:
  certbot-var:
  node_modules:
  web-root:
    driver: local
    driver_opts:
      type: none
      device: /home/beuwi/functions/files/
      o: bind
  dhparam:
    driver: local
    driver_opts:
      type: none
      device: /home/beuwi/dhparam/
      o: bind

networks:
  app-network:
    driver: bridge

