job "wordpress" {
  datacenters = ["alo"]

  meta {
    uuid = uuidv4()
  }

  group "web" {
    network {
      port "http" {
        to = 80
      }
    }

    task "server" {
      driver = "docker"
      user = "237"

      config {
        image = "gitea.v.paler.net/ppetru/wordpress"
        ports = ["http"]
        volumes = [
          "/data/services/wordpress:/var/www/html",
          "local/php-custom.ini:/usr/local/etc/php/conf.d/php-custom.ini",
        ]
      }

      env {
        WORDPRESS_DB_HOST = "mysql.service.consul"
        WORDPRESS_DB_USER = "wordpress"
        WORDPRESS_DB_PASSWORD = "Cayuquai3Eesh6gohph0"
        WORDPRESS_DB_NAME = "wordpress"
        #WORDPRESS_DEBUG = "1"
        WORDPRESS_CONFIG_EXTRA =<<EOH
          define('MULTISITE', true);
          define('SUBDOMAIN_INSTALL', true);
          define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
          define('PATH_CURRENT_SITE', '/');
          define('SITE_ID_CURRENT_SITE', 1);
          define('BLOG_ID_CURRENT_SITE', 4);
          //define('DOMAIN_CURRENT_SITE', 'wordpress.paler.net');
          //define('WP_HOME', 'https://wordpress.paler.net');
          //define('WP_SITEURL', 'https://wordpress.paler.net');
          define('WP_REDIS_HOST', 'redis.service.consul');
          // these are to stop Paymattic from doing a silly amount of Github API calls
          define('XENDIT_PAYMENT_FOR_PAYMATTIC', false);
          define('FLUTTERWAVE_PAYMENT_FOR_PAYMATTIC', false);
          define('MONERIS_PAYMENT_FOR_PAYMATTIC', false);
          define('VIVAWALLET_PAYMENT_FOR_PAYMATTIC', false);
        EOH
      }

      template {
        destination = "local/php-custom.ini"
        data = <<EOH
          upload_max_filesize = 100M
          post_max_size = 100M
          max_execution_time = 600
        EOH
      }

      resources {
        cpu = 2000
        memory = 1024
      }

      service {
        name = "wordpress"
        port = "http"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.wordpress.entryPoints=web4proxy",
          "traefik.http.routers.wordpress.rule=Host(`wordpress.paler.net`) || Host(`ines.paler.net`) || Host(`coachingfor.me`) || Host(`coachingfor.work`) || Host(`petru.ines.paler.net`) || Host(`liam.paler.net`) || Host(`tomas.paler.net`) || Host(`musictogethersilvercoast.pt`) || Host(`alo.land`)",
          "traefik.http.routers.wordpress.middlewares=compress@file",
        ]

        check {
          type = "http"
          port = "http"
          path = "/wp-admin/install.php"
          interval = "10s"
          timeout = "3s"
  
          check_restart {
            limit = 5
            grace = "60s"
          }
        }
      }

      restart {
        interval = "1m"
        attempts = "5"
        delay = "15s"
        mode = "delay"
      }
    }
  }
}
