From 0671fdcbf80c59addd77693e5eeda8ae2431d7be Mon Sep 17 00:00:00 2001 From: Lutfi Hakim Date: Thu, 12 Mar 2026 10:26:30 +0700 Subject: [PATCH 1/4] feat:create deployment setup --- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ nginx/conf.d/app.conf | 23 +++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/conf.d/app.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5495a09 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM php:8.2-fpm + +# Set working directory +WORKDIR /var/www + +# 1. Install system dependencies & NODE.JS (Kita gabung disini) +RUN apt-get update && apt-get install -y \ + git \ + curl \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + zip \ + unzip \ + libzip-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + libfreetype6-dev \ + gnupg \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y nodejs \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Config & Install PHP extensions +RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip intl + +# Get latest Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Copy files +COPY . /var/www + +# Set Permission +RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache + +EXPOSE 9000 +CMD ["php-fpm"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c42e1b1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3' + +services: + sig_php: + build: + context: . + dockerfile: Dockerfile + image: sig-app + container_name: sig-php-container + restart: unless-stopped + working_dir: /var/www + volumes: + - .:/var/www + networks: + - sig-network + - laravel-network + + sig_nginx: + image: nginx:alpine + container_name: sig-nginx-container + restart: unless-stopped + ports: + - "8089:80" + volumes: + - .:/var/www + - ./nginx/conf.d:/etc/nginx/conf.d + networks: + - sig-network + depends_on: + - sig_php + +networks: + sig-network: + driver: bridge + + laravel-network: + external: true + name: bpbd_laravel-network diff --git a/nginx/conf.d/app.conf b/nginx/conf.d/app.conf new file mode 100644 index 0000000..3b00f6f --- /dev/null +++ b/nginx/conf.d/app.conf @@ -0,0 +1,23 @@ +server { + listen 80; + server_name sig-tpsnganjuk.web.id + + root /var/www/public; + index index.php index.html; + + access_log /var/log/nginx/sig_access.log; + error_log /var/log/nginx/sig_error.log; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass sig_php:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} From 1aba739e67217304c8db21a341b65a5ea9e55cfb Mon Sep 17 00:00:00 2001 From: Lutfi Hakim Date: Thu, 12 Mar 2026 11:07:54 +0700 Subject: [PATCH 2/4] feat:setup CI/CD for SIG TPS Nganjuk --- .github/workflows/deploy.yml | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7973d21 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,44 @@ +name: Auto Deploy SIG TPS Nganjuk + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: self-hosted + + steps: + - name: Deployment Logic SIG TPS Nganjuk + run: | + cd /www/wwwroot/sig-tps + + # 1. Ambil ID commit lama untuk deteksi perubahan + OLD_COMMIT=$(git rev-parse HEAD) + + # 2. Tarik kode terbaru + git fetch --all + git reset --hard origin/master + + # 3. Ambil ID commit baru + NEW_COMMIT=$(git rev-parse HEAD) + + # 4. Build dependencies (Container temporary) + docker run --rm -v $(pwd):/app -w /app composer:2 install --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs + + # 5. Perbaikan permission untuk user www/docker (PUID 33) + # Sekalian fix untuk storage dan cache biar aman + chown -R 33:33 vendor/ storage/ bootstrap/cache/ + chmod -R 775 storage/ bootstrap/cache/ + + # 6. Refresh cache Laravel + docker compose exec -T sig_php php artisan optimize:clear + + # 7. Deteksi otomatis migrasi database + if [ "$OLD_COMMIT" != "$NEW_COMMIT" ] && git diff --name-only $OLD_COMMIT $NEW_COMMIT | grep -q "^database/migrations/"; then + echo "🚀 Perubahan database terdeteksi! Menjalankan migrate..." + docker compose exec -T sig_php php artisan migrate --force + else + echo "✅ Tidak ada file migrasi baru. Skip migrate." + fi From 8fe55ae644f09a5994a0b0bbdda5cbcc61c73ba7 Mon Sep 17 00:00:00 2001 From: Lutfi Hakim Date: Thu, 12 Mar 2026 11:14:31 +0700 Subject: [PATCH 3/4] fix:deployment.yml --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7973d21..d3ef52a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,7 +19,7 @@ jobs: # 2. Tarik kode terbaru git fetch --all - git reset --hard origin/master + git reset --hard origin/main # 3. Ambil ID commit baru NEW_COMMIT=$(git rev-parse HEAD) From d19c950c490acc1d850a262e3e77d28adf554962 Mon Sep 17 00:00:00 2001 From: Lutfi Hakim Date: Thu, 12 Mar 2026 11:28:46 +0700 Subject: [PATCH 4/4] fix github issue --- .github/workflows/deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d3ef52a..f4fe650 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,7 +18,8 @@ jobs: OLD_COMMIT=$(git rev-parse HEAD) # 2. Tarik kode terbaru - git fetch --all + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/rahmagustin/sig-tps.git + git fetch -4 --all git reset --hard origin/main # 3. Ambil ID commit baru