version: "3.7"

services:
  nginx:
    image: index.docker.io/appsmith/appsmith-editor
    env_file: ./.env
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./data/nginx/app.conf.template:/nginx.conf.template
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & /start-nginx.sh'"
    depends_on:
      - appsmith-internal-server
    labels:
      com.centurylinklabs.watchtower.enable: "true"
    networks:
      - appsmith

  certbot:
    image: certbot/certbot
    restart: always
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
    networks:
      - appsmith

  appsmith-internal-server:
    image: index.docker.io/appsmith/appsmith-server
    env_file:
      - ./.env
      - ./encryption.env
    restart: always
    expose:
      - "8080"
    links:
      - mongo
    depends_on:
      - mongo
      - redis
    labels:
      com.centurylinklabs.watchtower.enable: "true"
    networks:
      - appsmith

  mongo:
    image: mongo
    restart: always
    expose:
      - "27017"
    environment:
      - MONGO_INITDB_DATABASE=appsmith
      - MONGO_INITDB_ROOT_USERNAME=test
      - MONGO_INITDB_ROOT_PASSWORD=test
    volumes:
      - ./data/mongo/db:/data/db
      - ./data/mongo/init.js:/docker-entrypoint-initdb.d/init.js:ro
    networks:
      - appsmith

  redis:
    image: redis
    restart: always
    expose:
      - "6379"
    networks:
      - appsmith

  watchtower:
    image: containrrr/watchtower
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    # Update check interval in seconds.
    command: --interval 300 --label-enable --cleanup
    networks:
      - appsmith

networks:
  appsmith:
    driver: bridge
