diff --git a/.dockerignore b/.dockerignore index de67b71b..fff02c8f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,26 +1,26 @@ -**/node_modules -**/vendor -.env -.env.backup -.git -.phpunit.result.cache -Homestead.json -Homestead.yaml -auth.json -npm-debug.log -yarn-error.log -.idea -.vscode -storage/app/public -storage/app/temp -storage/app/uploads -storage/debugbar -storage/framework/views/* -public/modules/* -.qodo -.camel-jbang +# **/node_modules +# **/vendor +# #.env +# .env.backup +# .git +# .phpunit.result.cache +# Homestead.json +# Homestead.yaml +# auth.json +# npm-debug.log +# yarn-error.log +# .idea +# .vscode +# storage/app/public +# storage/app/temp +# storage/app/uploads +# storage/debugbar +# storage/framework/views/* +# public/modules/* +# .qodo +# .camel-jbang -# Ignore large archives that slow down docker build context -*.zip -*.tar.gz -*.sql +# # Ignore large archives that slow down docker build context +# *.zip +# *.tar.gz +# *.sql diff --git a/Dockerfile b/Dockerfile index 8e9cfb98..c85eed02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,92 +1,51 @@ -FROM php:8.2-fpm-alpine +FROM php:8.4-fpm -# Install system dependencies -RUN apk add --no-cache \ - vim \ - xxd \ - libzip-dev \ - postgresql-dev \ - libpng-dev \ - libjpeg-turbo-dev \ - freetype-dev \ - oniguruma-dev \ +# 1. Setup NodeSource untuk instalasi Node.js v20 (Cepat & Stabil) +RUN apt-get update && apt-get install -y ca-certificates curl gnupg \ + && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ + && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list + +# 2. Install dependencies utama dengan apt-get +RUN apt-get update && apt-get install -y \ git \ - curl \ - nodejs \ - npm \ - && docker-php-ext-configure gd --with-freetype --with-jpeg \ - && docker-php-ext-install -j$(nproc) \ - pdo_pgsql \ - pgsql \ - opcache \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + libpq-dev \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libzip-dev \ zip \ - bcmath \ - gd \ - exif \ - pcntl + unzip \ + nodejs \ + && apt-get clean && rm -rf /var/lib/apt/lists/* -# Configure git to allow safe directory -RUN git config --global --add safe.directory /var/www/html +# 3. Install PHP Extensions (TERMASUK pgsql / pdo_pgsql) +RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install pdo_mysql pdo_pgsql pgsql mbstring exif pcntl bcmath gd zip -# Install Composer +# 4. Get latest Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -WORKDIR /var/www/html +WORKDIR /var/www -# Copy ONLY composer files first -COPY composer.json ./ +# 5. Copy existing application directory contents +COPY . /var/www -# Create storage and bootstrap directories needed for composer scripts -RUN mkdir -p storage/framework/cache \ - && mkdir -p storage/framework/sessions \ - && mkdir -p storage/framework/views \ - && mkdir -p storage/framework/testing \ - && mkdir -p storage/logs \ - && mkdir -p bootstrap/cache \ - && chmod -R 777 storage \ - && chmod -R 777 bootstrap/cache +# 6. Install dependencies +# (Hapus --no-dev sementara jika Anda mau testing dengan Error Page Laravel yang rapi) +RUN composer install --no-interaction --optimize-autoloader -# Configure Composer for stability on unstable networks -ENV COMPOSER_ALLOW_SUPERUSER=1 \ - COMPOSER_MEMORY_LIMIT=-1 \ - COMPOSER_PROCESS_TIMEOUT=2000 - -# Install PHP dependencies (this layer will be cached) -RUN composer config -g repo.packagist composer https://packagist.org \ - && composer install --no-interaction --no-progress --no-scripts --prefer-dist - -# Isolate the clean vendor directory -#RUN mv vendor /vendor_clean - -# Copy the rest of the application files (will ignore vendor because of .dockerignore) -COPY --chown=www-data:www-data . . - -# Restore the clean vendor directory and set proper permissions -#RUN rm -rf vendor && mv /vendor_clean vendor && chown -R www-data:www-data vendor - -# Final build verification -RUN if [ ! -f vendor/laravel/prompts/src/helpers.php ]; then \ - echo "ERROR: laravel/prompts/src/helpers.php missing!" && exit 1; \ - fi - -# Final check and debug listing -RUN ls -l vendor/laravel/prompts/src/helpers.php \ - && du -sh vendor/laravel/prompts - -# Copy package files for NPM -COPY package*.json ./ -COPY vite.config.js ./ - -# Install NPM dependencies -RUN npm install --legacy-peer-deps --no-audit - -# Build Vite assets +# 7. Install & Build Frontend +RUN npm install RUN npm run build -# Copy entrypoint script and ensure it's executable -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh +# 8. Set permissions +RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache \ + && chmod -R 775 /var/www/storage /var/www/bootstrap/cache -# Let the entrypoint handle artisan commands at runtime -EXPOSE 8000 9000 -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +# 9. Expose port 8000 and start php artisan serve +EXPOSE 8000 + +# artisan serve berjalan langsung +CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"] diff --git a/Dockerfile2 b/Dockerfile2 new file mode 100644 index 00000000..c85eed02 --- /dev/null +++ b/Dockerfile2 @@ -0,0 +1,51 @@ +FROM php:8.4-fpm + +# 1. Setup NodeSource untuk instalasi Node.js v20 (Cepat & Stabil) +RUN apt-get update && apt-get install -y ca-certificates curl gnupg \ + && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ + && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list + +# 2. Install dependencies utama dengan apt-get +RUN apt-get update && apt-get install -y \ + git \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + libpq-dev \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libzip-dev \ + zip \ + unzip \ + nodejs \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# 3. Install PHP Extensions (TERMASUK pgsql / pdo_pgsql) +RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install pdo_mysql pdo_pgsql pgsql mbstring exif pcntl bcmath gd zip + +# 4. Get latest Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www + +# 5. Copy existing application directory contents +COPY . /var/www + +# 6. Install dependencies +# (Hapus --no-dev sementara jika Anda mau testing dengan Error Page Laravel yang rapi) +RUN composer install --no-interaction --optimize-autoloader + +# 7. Install & Build Frontend +RUN npm install +RUN npm run build + +# 8. Set permissions +RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache \ + && chmod -R 775 /var/www/storage /var/www/bootstrap/cache + +# 9. Expose port 8000 and start php artisan serve +EXPOSE 8000 + +# artisan serve berjalan langsung +CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"] diff --git a/dockerfile.txt b/dockerfile.txt new file mode 100644 index 00000000..8e9cfb98 --- /dev/null +++ b/dockerfile.txt @@ -0,0 +1,92 @@ +FROM php:8.2-fpm-alpine + +# Install system dependencies +RUN apk add --no-cache \ + vim \ + xxd \ + libzip-dev \ + postgresql-dev \ + libpng-dev \ + libjpeg-turbo-dev \ + freetype-dev \ + oniguruma-dev \ + git \ + curl \ + nodejs \ + npm \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) \ + pdo_pgsql \ + pgsql \ + opcache \ + zip \ + bcmath \ + gd \ + exif \ + pcntl + +# Configure git to allow safe directory +RUN git config --global --add safe.directory /var/www/html + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www/html + +# Copy ONLY composer files first +COPY composer.json ./ + +# Create storage and bootstrap directories needed for composer scripts +RUN mkdir -p storage/framework/cache \ + && mkdir -p storage/framework/sessions \ + && mkdir -p storage/framework/views \ + && mkdir -p storage/framework/testing \ + && mkdir -p storage/logs \ + && mkdir -p bootstrap/cache \ + && chmod -R 777 storage \ + && chmod -R 777 bootstrap/cache + +# Configure Composer for stability on unstable networks +ENV COMPOSER_ALLOW_SUPERUSER=1 \ + COMPOSER_MEMORY_LIMIT=-1 \ + COMPOSER_PROCESS_TIMEOUT=2000 + +# Install PHP dependencies (this layer will be cached) +RUN composer config -g repo.packagist composer https://packagist.org \ + && composer install --no-interaction --no-progress --no-scripts --prefer-dist + +# Isolate the clean vendor directory +#RUN mv vendor /vendor_clean + +# Copy the rest of the application files (will ignore vendor because of .dockerignore) +COPY --chown=www-data:www-data . . + +# Restore the clean vendor directory and set proper permissions +#RUN rm -rf vendor && mv /vendor_clean vendor && chown -R www-data:www-data vendor + +# Final build verification +RUN if [ ! -f vendor/laravel/prompts/src/helpers.php ]; then \ + echo "ERROR: laravel/prompts/src/helpers.php missing!" && exit 1; \ + fi + +# Final check and debug listing +RUN ls -l vendor/laravel/prompts/src/helpers.php \ + && du -sh vendor/laravel/prompts + +# Copy package files for NPM +COPY package*.json ./ +COPY vite.config.js ./ + +# Install NPM dependencies +RUN npm install --legacy-peer-deps --no-audit + +# Build Vite assets +RUN npm run build + +# Copy entrypoint script and ensure it's executable +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Let the entrypoint handle artisan commands at runtime +EXPOSE 8000 9000 +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint2.sh b/entrypoint2.sh new file mode 100644 index 00000000..0a93efbb --- /dev/null +++ b/entrypoint2.sh @@ -0,0 +1,52 @@ +#!/bin/sh +set -e + +echo "========================================" +echo "Starting KulakPOS Container Setup..." +echo "========================================" + +# Tampilkan info dasar untuk debugging +echo "Current user: $(whoami)" +echo "Current directory: $(pwd)" + +# 1. Fallback untuk kelengkapan env (agar container minimal bisa booting) +if [ ! -f .env ]; then + echo "⚠️ .env tidak ditemukan!" + if [ -f .env.example ]; then + echo "Menyalin dari .env.example..." + cp .env.example .env + fi +fi + +# 2. Pastikan permission path krusial aman (berguna jika terkena Volume Mount di Docker Compose) +echo "Menyesuaikan izin (permissions) untuk storage & bootstrap/cache..." +mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views storage/framework/testing storage/logs bootstrap/cache +chown -R www-data:www-data storage bootstrap/cache +chmod -R 775 storage bootstrap/cache + +# 3. Bersihkan cache instalasi/config lama +echo "Membersihkan cache Laravel..." +php artisan config:clear || true + + +# 4. Verifikasi Vite Build +if [ -f public/build/manifest.json ]; then + echo "✅ Vite manifest ditemukan." +else + echo "⚠️ Peringatan: Vite manifest public/build/manifest.json tidak ditemukan." +fi + +# ======================================== +# PENTING: Dihilangkan dari script ini: +# - composer install (Sudah dijamin ada pada Dockerfile, bukan di runtime) +# - chmod 777 (Diganti menjadi 775 dan chown www-data) +# - php -S (Kita standarkan aplikasi menggunakan php-fpm murni dari CMD Dockerfile) +# - Paksaan export APP_DEBUG +# ======================================== + +echo "========================================" +echo "Selesai. Menjalankan proses utama ($@)..." +echo "========================================" + +# Serahkan eksekusi ke CMD milik Dockerfile (yaitu php-fpm) +exec "$@"