refactor: restructure environment
This commit is contained in:
@@ -1,23 +1,36 @@
|
||||
ARG PHP_VERSION=8.3-fpm
|
||||
FROM php:${PHP_VERSION}
|
||||
FROM php:8.3-fpm
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libpng-dev libonig-dev libxml2-dev libzip-dev \
|
||||
zip unzip git \
|
||||
zip unzip git gosu \
|
||||
netcat-traditional \
|
||||
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
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
|
||||
ARG UID
|
||||
ARG GID
|
||||
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
# Create a new user with the specified UID and GID, reusing an existing group if GID exists
|
||||
# and update php-fpm to use the new user and group
|
||||
RUN if getent group ${GID}; then \
|
||||
group_name=$(getent group ${GID} | cut -d: -f1); \
|
||||
useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \
|
||||
else \
|
||||
groupadd -g ${GID} www && \
|
||||
useradd -m -u ${UID} -g www -s /bin/bash www; \
|
||||
group_name=www; \
|
||||
fi
|
||||
|
||||
# Update php-fpm to use the new user and group
|
||||
RUN sed -i "s/user = www-data/user = www/g" /usr/local/etc/php-fpm.d/www.conf && \
|
||||
sed -i "s/group = www-data/group = $group_name/g" /usr/local/etc/php-fpm.d/www.conf
|
||||
|
||||
COPY ./docker/entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
USER www-data
|
||||
WORKDIR /var/www
|
||||
|
||||
EXPOSE 9000
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
CMD ["php-fpm"]
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
APP_ENV=${APP_ENV:-unknown}
|
||||
echo ">> Running in $APP_ENV mode"
|
||||
|
||||
# Only for Laravel project
|
||||
if [ -f "artisan" ]; then
|
||||
|
||||
echo ">> Ensuring composer dependencies are up to date..."
|
||||
if [ "$APP_ENV" = "production" ]; then
|
||||
composer install --no-dev --optimize-autoloader
|
||||
else
|
||||
composer install --optimize-autoloader
|
||||
fi
|
||||
|
||||
if [ -f ".env" ] && grep -q '^APP_KEY=$' .env; then
|
||||
echo ">> Generating application key..."
|
||||
php artisan key:generate --ansi
|
||||
fi
|
||||
|
||||
echo ">> Waiting for MySQL..."
|
||||
while ! nc -z mysql 3306; do sleep 1; done
|
||||
|
||||
echo ">> Running migrations..."
|
||||
php artisan migrate --force || true
|
||||
|
||||
if [ ! -L "public/storage" ] && [ -d "storage/app/public" ]; then
|
||||
echo ">> Creating storage link..."
|
||||
php artisan storage:link
|
||||
fi
|
||||
|
||||
if [ "$APP_ENV" = "local" ]; then
|
||||
echo ">> Running seeders..."
|
||||
php artisan db:seed --force || true
|
||||
|
||||
if composer show knuckleswtf/scribe > /dev/null 2>&1; then
|
||||
echo ">> Generating API documentation..."
|
||||
php artisan scribe:generate --no-interaction || echo ">> Documentation generation failed, continuing..."
|
||||
else
|
||||
echo ">> Scribe not installed, skipping documentation generation"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$APP_ENV" = "production" ]; then
|
||||
php artisan optimize
|
||||
fi
|
||||
else
|
||||
echo ">> Not a Laravel project"
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
57
docker/entrypoint.sh
Executable file
57
docker/entrypoint.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo ">> Running dev setup..."
|
||||
|
||||
# Only for Laravel project
|
||||
if [ ! -f "artisan" ]; then
|
||||
echo ">> Not a Laravel project"
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
if [ ! -f .composer-hash ] || ! sha1sum -c .composer-hash > /dev/null 2>&1; then
|
||||
echo ">> composer.json or composer.lock changed, installing dependencies..."
|
||||
gosu www composer install --optimize-autoloader --no-interaction
|
||||
sha1sum composer.json composer.lock > .composer-hash
|
||||
else
|
||||
echo ">> Composer dependencies up to date (hash match), skipping install."
|
||||
fi
|
||||
|
||||
if [ -f ".env" ] && grep -q '^APP_KEY=$' .env; then
|
||||
echo ">> Generating application key..."
|
||||
gosu www php artisan key:generate --ansi
|
||||
fi
|
||||
|
||||
echo ">> Waiting for MySQL..."
|
||||
while ! nc -z mysql 3306; do sleep 1; done
|
||||
|
||||
echo ">> Running migrations..."
|
||||
gosu www php artisan migrate --force
|
||||
|
||||
if [ ! -L "public/storage" ] && [ -d "storage/app/public" ]; then
|
||||
echo ">> Creating storage link..."
|
||||
gosu www php artisan storage:link
|
||||
fi
|
||||
|
||||
echo ">> Running seeders..."
|
||||
gosu www php artisan db:seed --force
|
||||
|
||||
if composer show knuckleswtf/scribe > /dev/null 2>&1; then
|
||||
# Define all directories/files Scribe cares about
|
||||
SCRIBE_SOURCES="config/scribe.php routes/ app/Http/Controllers/ app/Http/Requests/ app/Models/"
|
||||
|
||||
# Create combined hash of all .php files in those paths
|
||||
CURRENT_HASH=$(find $SCRIBE_SOURCES -type f -name "*.php" -exec sha1sum {} + | sha1sum)
|
||||
|
||||
if [ ! -f .scribe-hash ] || [ "$CURRENT_HASH" != "$(cat .scribe-hash)" ]; then
|
||||
echo ">> Generating API documentation..."
|
||||
gosu www php artisan scribe:generate --no-interaction || true
|
||||
echo "$CURRENT_HASH" > .scribe-hash
|
||||
else
|
||||
echo ">> API docs up to date, skipping Scribe generation."
|
||||
fi
|
||||
else
|
||||
echo ">> Scribe not installed, skipping API docs generation"
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,10 +0,0 @@
|
||||
[global]
|
||||
daemonize = no
|
||||
|
||||
[www]
|
||||
listen = 9000
|
||||
pm = dynamic
|
||||
pm.max_children = 5
|
||||
pm.start_servers = 2
|
||||
pm.min_spare_servers = 1
|
||||
pm.max_spare_servers = 3
|
||||
Reference in New Issue
Block a user