feat(docker): refactor to use pre-built images
- Add build/load script for image management - Use .env config for image naming and PHP version - Switch to www-data user in Dockerfile - Update compose.yaml to use pre-built images - Add .dockerignore - Simplify entrypoint script
This commit is contained in:
@@ -1,31 +1,21 @@
|
||||
FROM php:8.3-fpm
|
||||
ARG PHP_VERSION=8.3-fpm
|
||||
FROM php:${PHP_VERSION}
|
||||
|
||||
ARG UID
|
||||
ARG GID
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libpng-dev libonig-dev libxml2-dev libzip-dev \
|
||||
zip unzip git \
|
||||
netcat-traditional \
|
||||
libpng-dev \
|
||||
libonig-dev \
|
||||
libxml2-dev \
|
||||
libzip-dev \
|
||||
zip \
|
||||
unzip \
|
||||
git \
|
||||
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
|
||||
COPY --chown=www-data:www-data ./docker/docker-entrypoint.sh /usr/local/bin/
|
||||
COPY ./docker/php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf
|
||||
|
||||
COPY ./docker/docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
RUN groupadd -g $GID laravel && useradd -u $UID -g $GID -m laravel
|
||||
USER laravel
|
||||
|
||||
USER www-data
|
||||
WORKDIR /var/www
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
cd /var/www
|
||||
|
||||
echo ">> Running in ${APP_ENV:-unknown} mode"
|
||||
APP_ENV=${APP_ENV:-unknown}
|
||||
echo ">> Running in $APP_ENV mode"
|
||||
|
||||
# Only for Laravel project
|
||||
if [ -f "artisan" ]; then
|
||||
chown -R laravel:laravel storage bootstrap/cache
|
||||
chmod -R 775 storage bootstrap/cache
|
||||
|
||||
if [ ! -d "vendor" ]; then
|
||||
echo ">> Installing composer dependencies..."
|
||||
if [ "$APP_ENV" = "production" ]; then
|
||||
composer install --no-dev --optimize-autoloader
|
||||
else
|
||||
composer install --optimize-autoloader
|
||||
fi
|
||||
echo ">> Ensuring composer dependencies are up to date..."
|
||||
if [ "$APP_ENV" = "production" ]; then
|
||||
composer install --no-dev --optimize-autoloader
|
||||
else
|
||||
echo ">> Vendor directory exists, skipping installation"
|
||||
composer install --optimize-autoloader
|
||||
fi
|
||||
|
||||
if [ -f ".env" ] && grep -q '^APP_KEY=$' .env; then
|
||||
echo ">> APP_KEY is missing. Generating application key..."
|
||||
echo ">> Generating application key..."
|
||||
php artisan key:generate --ansi
|
||||
fi
|
||||
|
||||
echo ">> Waiting for MySQL to be ready..."
|
||||
while ! nc -z mysql 3306; do
|
||||
sleep 1
|
||||
done
|
||||
echo ">> MySQL is ready!"
|
||||
echo ">> Waiting for MySQL..."
|
||||
while ! nc -z mysql 3306; do sleep 1; done
|
||||
|
||||
echo ">> Running migrations..."
|
||||
php artisan migrate --force || true
|
||||
@@ -37,8 +28,6 @@ if [ -f "artisan" ]; then
|
||||
if [ ! -L "public/storage" ] && [ -d "storage/app/public" ]; then
|
||||
echo ">> Creating storage link..."
|
||||
php artisan storage:link
|
||||
else
|
||||
echo ">> Storage link already exists or storage directory missing"
|
||||
fi
|
||||
|
||||
if [ "$APP_ENV" = "local" ]; then
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
daemonize = no
|
||||
|
||||
[www]
|
||||
user = laravel
|
||||
group = laravel
|
||||
listen = 9000
|
||||
pm = dynamic
|
||||
pm.max_children = 5
|
||||
|
||||
Reference in New Issue
Block a user