From f97c40317c3326009107b640510a34de9bc7e5ac Mon Sep 17 00:00:00 2001 From: MAGHFIRA IZZATI Date: Wed, 10 Jun 2026 17:26:25 +0700 Subject: [PATCH] feat: add auto DB import entrypoint script --- Dockerfile | 11 +++++++++-- docker-entrypoint.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 0909a36..1292d9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ FROM php:8.2-apache -# Install ekstensi mysqli dan pdo_mysql untuk koneksi ke database +# Install mysql client dan ekstensi PHP +RUN apt-get update && apt-get install -y default-mysql-client && rm -rf /var/lib/apt/lists/* RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable mysqli -# Aktifkan mod_rewrite Apache (berguna untuk URL yang bersih/routing) +# Aktifkan mod_rewrite Apache RUN a2enmod rewrite # Copy semua file project ke dalam container COPY . /var/www/html/ +# Copy entrypoint script +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + # Update permissions RUN chown -R www-data:www-data /var/www/html # Expose port Apache EXPOSE 80 + +ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..dfe8e6b --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +echo "=== Starting WebGIS Application ===" + +# Tunggu MySQL siap +echo "Waiting for MySQL at $DB_HOST..." +until mysql -h"$DB_HOST" -uroot -p"$DB_PASS" -e "SELECT 1" > /dev/null 2>&1; do + echo "MySQL not ready yet, retrying in 3s..." + sleep 3 +done +echo "MySQL is ready!" + +# Setup database webgis (sudah ada CREATE DATABASE di dalam file SQL) +echo "Setting up webgis database..." +mysql -h"$DB_HOST" -uroot -p"$DB_PASS" < /var/www/html/WEBGIS/01/api/setup_webgis.sql && echo "webgis OK!" || echo "webgis already exists, skipping." + +# Buat database kemiskinan_ibadah jika belum ada +echo "Creating kemiskinan_ibadah database..." +mysql -h"$DB_HOST" -uroot -p"$DB_PASS" -e "CREATE DATABASE IF NOT EXISTS kemiskinan_ibadah CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" + +# Import tabel ke kemiskinan_ibadah +echo "Importing kemiskinan_ibadah tables..." +mysql -h"$DB_HOST" -uroot -p"$DB_PASS" kemiskinan_ibadah < /var/www/html/webtugas/01/api/setup_webtugas.sql && echo "kemiskinan_ibadah OK!" || echo "kemiskinan_ibadah import done (may already exist)." + +echo "=== Database setup complete, starting Apache ===" + +# Jalankan Apache +exec apache2-foreground