services:
  app:
    build:
      context: .
      dockerfile_inline: |
        FROM php:8.2-apache

        RUN docker-php-ext-install mysqli pdo pdo_mysql \
            && a2enmod rewrite \
            && printf '%s\n' \
                '<Directory /var/www/html>' \
                '    Options FollowSymLinks' \
                '    AllowOverride All' \
                '    Require all granted' \
                '</Directory>' \
                'DirectoryIndex index.php index.html' \
                > /etc/apache2/conf-available/webgis.conf \
            && a2enconf webgis

        COPY . /var/www/html/

        RUN mkdir -p /var/www/html/02/uploads \
            /var/www/html/05/assets/uploads \
            /var/www/html/05/uploads/bukti \
            && chmod -R a+rX /var/www/html \
            && chown -R www-data:www-data /var/www/html/02/uploads \
                /var/www/html/05/assets/uploads \
                /var/www/html/05/uploads
    expose:
      - "80"
    environment:
      DB_HOST: db
      DB_USER: webgis
      DB_PASSWORD: webgis_password
      DB_NAME: webgis_project
    command: >
      bash -lc "php /var/www/html/db/migrate.php && apache2-foreground"
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mariadb:10.11
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: root_password
      MARIADB_DATABASE: webgis_project
      MARIADB_USER: webgis
      MARIADB_PASSWORD: webgis_password
    volumes:
      - webgis_project_db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  webgis_project_db:
