services:
  webserver-astrokia:
    image: php:8.2-apache
    restart: on-failure
    networks:
      - astrozapnet

    volumes:
      - webserver-astrokia-data:/usr/local/apache2/htdocs

    command: >

      bash -c '
      set -e;

      if ! php -m | grep -qi pdo_pgsql; then
        apt-get update;
        apt-get install -y --no-install-recommends default-mysql-client libpq-dev;
        docker-php-ext-install pdo pdo_mysql mysqli pdo_pgsql pgsql;
      fi;

      if ! grep -q "/usr/local/apache2/htdocs" /etc/apache2/apache2.conf; then
        sed -i "s!/var/www/html!/usr/local/apache2/htdocs!g" /etc/apache2/sites-available/*.conf;
        sed -i "s!/var/www/!/usr/local/apache2/htdocs!g" /etc/apache2/apache2.conf;
      fi;

      mkdir -p /usr/local/apache2/htdocs;
      printf "%s\n" "log_errors = On" "error_reporting = E_ALL" "display_errors = Off" "error_log = /dev/stderr" > /usr/local/etc/php/conf.d/zz-custom.ini;

      apache2-foreground
      '

    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager
      labels:
        - traefik.enable=true
        - traefik.http.routers.webserver-astrokia.rule=Host(`sys.astrozap.com.br`)
        - traefik.http.routers.webserver-astrokia.entrypoints=web,websecure
        - traefik.http.routers.webserver-astrokia.tls.certresolver=letsencryptresolver
        - traefik.http.services.webserver-astrokia.loadbalancer.server.port=80
        - traefik.http.routers.webserver-astrokia.service=webserver-astrokia

volumes:
  webserver-astrokia-data:

networks:
  astrozapnet:
    external: true
    attachable: true
    name: astrozapnet