version: "3.7"

services:
  mixpost-pro:
    image: inovector/mixpost-pro-team:latest
    container_name: mixpost-pro
    environment:
      - APP_NAME=Mixpost
      - LICENSE_KEY=${MIXPOST_LICENSE_KEY}
      - APP_KEY=${MIXPOST_APP_KEY}
      - APP_URL=${APP_PROTOCOL:-http}://${APP_DOMAIN}
      - DB_HOST=mixpost-pro-mysql
      - DB_DATABASE=mixpost
      - DB_USERNAME=tipi
      - DB_PASSWORD=${MIXPOST_MYSQL_PASSWORD}
      - REDIS_HOST=mixpost-pro-redis
      - REDIS_PASSWORD=${MIXPOST_REDIS_PASSWORD}
    restart: unless-stopped
    volumes:
      - ${APP_DATA_DIR}/data/mixpost-pro:/var/www/html/storage/app
    ports:
      - ${APP_PORT}:80
    depends_on:
      - mixpost-pro-mysql
      - mixpost-pro-redis
    networks:
      - tipi_main_network
    labels:
      # Main
      traefik.enable: true
      traefik.http.middlewares.mixpost-pro-web-redirect.redirectscheme.scheme: https
      traefik.http.services.mixpost-pro.loadbalancer.server.port: 80
      # Web
      traefik.http.routers.mixpost-pro-insecure.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.mixpost-pro-insecure.entrypoints: web
      traefik.http.routers.mixpost-pro-insecure.service: mixpost-pro
      traefik.http.routers.mixpost-pro-insecure.middlewares: mixpost-pro-web-redirect
      # Websecure
      traefik.http.routers.mixpost-pro.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.mixpost-pro.entrypoints: websecure
      traefik.http.routers.mixpost-pro.service: mixpost-pro
      traefik.http.routers.mixpost-pro.tls.certresolver: myresolver
      # Local domain
      traefik.http.routers.mixpost-pro-local-insecure.rule: Host(`mixpost-pro.${LOCAL_DOMAIN}`)
      traefik.http.routers.mixpost-pro-local-insecure.entrypoints: web
      traefik.http.routers.mixpost-pro-local-insecure.service: mixpost-pro
      traefik.http.routers.mixpost-pro-local-insecure.middlewares: mixpost-pro-web-redirect
      # Local domain secure
      traefik.http.routers.mixpost-pro-local.rule: Host(`mixpost-pro.${LOCAL_DOMAIN}`)
      traefik.http.routers.mixpost-pro-local.entrypoints: websecure
      traefik.http.routers.mixpost-pro-local.service: mixpost-pro
      traefik.http.routers.mixpost-pro-local.tls: true

  mixpost-pro-mysql:
    image: mysql/mysql-server:8.0
    container_name: mixpost_mysql
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=${MIXPOST_MYSQL_PASSWORD}
      - MYSQL_USER=tipi
      - MYSQL_PASSWORD=${MIXPOST_MYSQL_PASSWORD}
      - MYSQL_DATABASE=mixpost
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-p ${MIXPOST_MYSQL_PASSWORD}"]
      retries: 3
      timeout: 5s
    volumes:
      - ${APP_DATA_DIR}/data/mysql:/var/lib/mysql
    networks:
      - tipi_main_network

  mixpost-pro-redis:
    image: "redis:latest"
    container_name: mixpost-pro-redis
    command: redis-server --appendonly yes --replica-read-only no --requirepass "${MIXPOST_REDIS_PASSWORD}"
    volumes:
      - "${APP_DATA_DIR}/data/redis:/data"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      retries: 3
      timeout: 5s
    networks:
      - tipi_main_network
