version: '3.7'
services:
  root_db:
    image: postgres
    restart: always
    volumes:
      - postgresdatanocodb:/data/postgres
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_USER: postgres
      POSTGRES_DB: root_db
      PGDATA: /data/postgres
    networks:
      - traefik-proxy
    healthcheck:
      test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"
      interval: 10s
      timeout: 2s
      retries: 10
  nocodb:
    depends_on:
      - root_db
    image: nocodb/nocodb:latest
    logging:
      options:
        max-size: '12m'
        max-file: '5'
      driver: json-file
    labels:
      - traefik.enable=true
      - traefik.http.routers.nocodb${USER_ID:-1}.rule=Host(`${URL_NOCODB}`)
      - traefik.http.routers.nocodb${USER_ID:-1}.entrypoints=websecure
      - traefik.http.routers.nocodb${USER_ID:-1}.tls=true
      - traefik.http.routers.nocodb${USER_ID:-1}.tls.certresolver=lets-encrypt
      - traefik.http.services.nocodb${USER_ID:-1}.loadbalancer.server.port=${PORT_NOCODB}
    restart: always
    environment:
      NC_DB: "pg://root_db:5432?u=postgres&p=password&d=root_db"
    networks:
      - traefik-proxy

networks:
  traefik-proxy:
    external:
      name: ${NETWORK_TRAEFIK}

volumes:
  postgresdatanocodb:
    driver: local
    driver_opts:
      type: none
      device: ${VOLUME_POSTGRES_NOCODB}
      o: bind
