Fixed looping health check, composer installation, and set proper permissions

This commit is contained in:
Daniel Teves 2025-03-30 21:53:21 +08:00
parent 939ee01615
commit b04d5c8e49
6 changed files with 31 additions and 10 deletions

View File

@ -1,5 +1,9 @@
# Use official PHP 8.2 FPM image
FROM php:8.2-fpm
# Set working directory
WORKDIR /var/www/html
# Install dependencies
RUN apt-get update && apt-get install -y \
libpng-dev \
@ -9,14 +13,26 @@ RUN apt-get update && apt-get install -y \
zip \
unzip \
curl \
git \
libonig-dev \
libxml2-dev \
procps \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd pdo pdo_mysql
# Set working directory
WORKDIR /var/www/html
# Copy the rest of Laravel files
COPY laravel/ .
# Copy application
COPY . .
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy only essential files for better build caching
COPY laravel/composer.json laravel/composer.lock ./
RUN composer install --no-dev --optimize-autoloader
# Set permissions
RUN chown -R www-data:www-data /var/www/html
RUN chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
# Copy entrypoint script and make it executable
COPY entrypoint.sh /entrypoint.sh
@ -30,7 +46,6 @@ CMD ["php-fpm"]
# FROM php:8.2-fpm
# RUN apt-get update && apt-get install -y \

View File

@ -29,7 +29,7 @@ services:
- DB_USERNAME=root
- DB_PASSWORD=rootpassword
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
test: ["CMD", "pgrep", "php-fpm"] # Corrected to check PHP-FPM instead of relying on Nginx
interval: 10s
timeout: 5s
retries: 5
@ -50,6 +50,7 @@ services:
volumes:
mysql-data:
# services:
# mysql:
# image: mysql:latest

View File

@ -8,6 +8,12 @@ until nc -z -v -w30 mysql 3306; do
done
echo "✅ MySQL is up and running!"
# Fix ownership and permissions for storage and cache directories
echo "🔧 Setting permissions for storage and cache..."
chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
echo "✅ Permissions set successfully!"
# Run Laravel migrations
php artisan migrate --force
@ -15,7 +21,6 @@ php artisan migrate --force
exec "$@"
# #!/bin/bash
# # Fix ownership and permissions for storage directories
# chown -R www-data:www-data /var/www/html/storage

@ -1 +1 @@
Subproject commit a6b9153dc1438eeb542f2bbe3f8687e9c078c0fa
Subproject commit 939ee016159d4f344b644a61819b6f96e66e49cb

View File

@ -1,3 +1,4 @@
server {
listen 80;
index index.php index.html;
@ -21,7 +22,6 @@ server {
add_header X-XSS-Protection "1; mode=block";
}
# server {
# listen 80;
# index index.php index.html;

View File

@ -11,4 +11,4 @@ until nc -z "$HOST" "$PORT"; do
done
echo "$host:$port is now available, running command..."
exec $cmd
exec $cmd