name: inception

volumes:
  wp-db:
    driver: local
    driver_opts:
      type: none
      device: /home/adjoly/data/wp-db
      o: bind
  wp-site:
    driver: local
    driver_opts:
      type: none
      device: /home/adjoly/data/wp-site
      o: bind
  nginx-certs:
    driver: local
    driver_opts:
      type: none
      device: /home/adjoly/data/certs
      o: bind
  backup:
    driver: local
    driver_opts:
      type: none
      device: /home/adjoly/data/backup
      o: bind

secrets:
  ftp-pass:
    file: ../secrets/ftp/pass.txt
  root-db-pass:
    file: ../secrets/db/root_pass.txt
  user-db-pass:
    file: ../secrets/db/user_pass.txt
  borg-passphrase:
    file: ../secrets/borg/passphrase.txt
  wp-admin-pass:
    file: ../secrets/wp/admin_pass.txt

networks:
  inception:
    external: false

services:
  nginx:
    container_name: inception-nginx
    build:
      context: .
      dockerfile: docker/nginx/Dockerfile
    networks:
      - inception
    environment:
      - NGINX_PHP_HOST=inception-wordp-php
      - NGINX_SSL_KEY_FILE=/etc/nginx/ssl/adjoly-wp.key
      - NGINX_SSL_CERT_FILE=/etc/nginx/ssl/adjoly-wp.crt
    depends_on:
      wordpress-php:
        condition: service_healthy
      db:
        condition: service_healthy
    volumes:
      - wp-site:/var/www/wordpress
      - ./configs/nginx/templates:/etc/nginx/templates
      - ./configs/nginx/entry:/docker-entrypoint.d
      - nginx-certs:/etc/nginx/ssl
    ports:
      - "443:443"
    restart: unless-stopped

  wordpress-php:
    container_name: inception-wordp-php
    build:
      context: .
      dockerfile: docker/wordpress/Dockerfile
    networks:
      - inception
    depends_on:
      db:
        condition: service_healthy
    environment:
      - WP_DB_NAME=${DB_NAME}
      - WP_DB_USER=${DB_USER}
      - WP_DB_PASS_FILE=/run/secrets/user-db-pass
      - WP_DB_HOST=db
      - WP_ADMIN_EMAIL=${WP_MAIL}
      - WP_ADMIN_USER=kanel
      - WP_ADMIN_PASS_FILE=/run/secrets/wp-admin-pass
      - WP_URL=adjoly.42.fr
      - WP_TITLE=Kanel Supremacy
      - WP_SEARCH_ENGINE_VISIBILITY=false
      - PHP_MEMORY_LIMIT="512M"
      - PHP_MAX_UPLOAD="50M"
      - PHP_PORT=9000
      - REDIS_HOSTNAME=redis
      - REDIS_PORT=6379
    volumes:
      - wp-site:/var/www/wordpress
      - ./configs/wordpress/entry:/docker-entrypoint.d
    secrets:
      - user-db-pass
      - wp-admin-pass
    restart: unless-stopped

  db:
    container_name: inception-db
    build:
      context: .
      dockerfile: docker/mariadb/Dockerfile
    networks:
      - inception
    environment:
      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/root-db-pass
      - MYSQL_PASSWORD_FILE=/run/secrets/user-db-pass
      - MYSQL_USER=${DB_USER}
      - MYSQL_DATABASE=${DB_NAME}
    volumes:
      - wp-db:/var/lib/mysql
    restart: unless-stopped

  static-site:
    build: docker/bonus/static-site
    container_name: inception-kanel-supremacy
    ports:
      - 8080:443
    depends_on:
      - nginx
    environment:
      - NGINX_SSL_KEY_FILE=/etc/nginx/ssl/kanel-wp.key
      - NGINX_SSL_CERT_FILE=/etc/nginx/ssl/kanel-wp.crt
    restart: unless-stopped

  backup:
    build:
      context: .
      dockerfile: docker/bonus/borg-backup/Dockerfile
    container_name: inception-backup
    networks:
      - inception
    environment:
      - CRON_INTERVAL=0 2 * * * # handled by entrypoint
      - BORG_PASSPHRASE_FILE=/run/secrets/borg-passphrase
      - BORG_PRUNE_KEEP_DAILY=3
      - BORG_PRUNE_KEEP_WEEKLY=2
      - BORG_PRUNE_KEEP_MONTHLY=1
      - BORG_LOG_LEVEL=info
      - BORG_CHECK_LAST=3
      - BORG_CHECK_DATA=1
    depends_on:
      nginx:
        condition: service_healthy
    volumes:
      - wp-db:/source/db
      - wp-site:/source/wordpress
      - backup:/backup
    secrets:
      - borg-passphrase
    restart: unless-stopped

  adminer:
    build:
      context: .
      dockerfile: docker/bonus/adminer/Dockerfile
    container_name: inception-adminer
    networks:
      - inception
    ports:
      - 8090:8080
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped

  redis:
    build:
      context: .
      dockerfile: docker/bonus/redis/Dockerfile
    container_name: inception-redis
    networks:
      - inception
    restart: unless-stopped

  ftp:
    build:
      context: .
      dockerfile: docker/bonus/vsftpd/Dockerfile
    container_name: inception-ftp
    networks:
      - inception
    environment:
      - VSFTPD_USER=${FTP_USER}
      - VSFTPD_PASS_FILE=/run/secrets/ftp-pass
    volumes:
      - wp-site:/var/ftp
    ports:
      - 21:21
      - 30000-30100:30000-30100
    secrets:
      - ftp-pass
    restart: unless-stopped
