feat/docker-compose-update (#18)

Co-authored-by: jon brookes <marshyon@gmail.com>
Reviewed-on: https://codeberg.org/headshed/share-lt/pulls/18
This commit is contained in:
Jon Brookes 2026-02-08 18:04:18 +01:00
parent fd43495e2d
commit 1a22fd156d
70 changed files with 1068 additions and 745 deletions

View file

@ -1,12 +1,8 @@
FROM php:8.5-fpm-alpine
FROM php:8.4-fpm-alpine3.23
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
ENV APP_ENV=production
ENV APP_DEBUG=false
WORKDIR /var/www
# # Install dependencies
RUN apk update && apk add --no-cache \
build-base \
libpng-dev \
@ -20,70 +16,86 @@ RUN apk update && apk add --no-cache \
curl \
libzip-dev \
oniguruma-dev \
icu-dev \
sqlite \
sqlite-dev \
nodejs \
npm
npm \
icu-dev \
sqlite-dev \
sqlite-libs \
nginx \
supervisor \
su-exec \
tini \
unzip \
bash \
jq \
&& rm -rf /var/cache/apk/*
RUN curl -sSL https://github.com/nats-io/natscli/releases/download/v0.3.1/nats-0.3.1-linux-amd64.zip -o /tmp/nats.zip \
&& unzip /tmp/nats.zip -d /tmp/nats \
&& mv /tmp/nats/nats-0.3.1-linux-amd64/nats /usr/local/bin/nats \
&& chmod +x /usr/local/bin/nats \
&& rm -rf /tmp/nats /tmp/nats.zip
# # Clear cache
RUN rm -rf /var/cache/apk/*
# # Install extensions
RUN docker-php-ext-install mbstring zip exif pcntl intl pdo_sqlite
RUN docker-php-ext-install gd
# # Install composer
RUN docker-php-ext-install mbstring zip exif pcntl intl gd pdo pdo_sqlite bcmath
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN addgroup -g 1000 www
RUN adduser -u 1000 -G www -s /bin/sh -D www
# Copy entrypoint script
COPY cmd/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# # Copy existing application directory contents
COPY . /var/www
# Copy supervisord configuration
COPY ./docker/supervisord.conf /etc/supervisord.conf
RUN mkdir -p /var/log/supervisor \
&& mkdir -p /run/nginx /var/cache/nginx /var/lib/nginx /var/tmp/nginx \
&& chown -R root:root /run/nginx /var/cache/nginx /var/lib/nginx /var/tmp/nginx
# # Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www
# Create www user and add to www-data group
RUN adduser -u 1000 -G www-data -s /bin/sh -D www
# # Install PHP dependencies
RUN composer install --no-dev --optimize-autoloader
# Configure PHP-FPM to run as www user
RUN sed -i 's/user = www-data/user = www/g' /usr/local/etc/php-fpm.d/www.conf
# Install Node.js dependencies
RUN npm install
# Remove the semicolon to uncomment the listen directive
RUN sed -i 's/;listen = 127.0.0.1:9000/listen = 9000/' /usr/local/etc/php-fpm.d/www.conf
# Build assets
RUN npm run build
# Ensure the worker running the code is correct (usually www-data or nginx)
RUN sed -i 's/;listen.owner = www-data/listen.owner = www/' /usr/local/etc/php-fpm.d/www.conf
RUN sed -i 's/;listen.group = www-data/listen.group = www-data/' /usr/local/etc/php-fpm.d/www.conf
# Change ownership of /var/www to www-data
RUN chmod -R u+rw /var/www && chown -R www:www /var/www
# Update nginx.conf to use 'www' user instead of 'nginx'
RUN sed -i 's/user nginx;/user www;/' /etc/nginx/nginx.conf
# # RUN php artisan optimize
# # removed as it calls all 4 commands below and fails du to
# # multi-site configuration
# Remove user and group directives from nginx and php-fpm configs to avoid conflicts
RUN sed -i '/^user /d' /etc/nginx/nginx.conf
RUN sed -i '/^user = /d' /usr/local/etc/php-fpm.d/www.conf
RUN sed -i '/^group = /d' /usr/local/etc/php-fpm.d/www.conf
# # Clear any cached configurations
RUN php artisan config:clear
# RUN php artisan cache:clear
RUN php artisan route:clear
RUN php artisan view:clear
# Set permissions for nginx directories
RUN mkdir -p /var/lib/nginx/tmp/client_body /var/log/nginx \
&& chown -R www:www-data /var/lib/nginx /var/log/nginx \
&& chmod -R 755 /var/lib/nginx /var/log/nginx \
&& touch /run/nginx/nginx.pid \
&& chown www:www-data /run/nginx/nginx.pid
# # Build optimizations
RUN php artisan config:cache
RUN php artisan event:cache
RUN php artisan view:cache
# Copy application code (includes database/migrations/) and excluding
# files in .dockerignore
COPY --chown=www:www-data . /var/www
RUN chown -R www:www-data /var/www
RUN chown -R www:www-data /var/log/supervisor
# # RUN php artisan route:cache
# # Run Laravel artisan command
RUN php artisan storage:link
# # RUN composer install --optimize-autoloader --no-dev
# # Change current user to www
# Switch to www user
USER www
# # Expose port 9000 and start php-fpm server
# EXPOSE 9000
# Install app dependencies
RUN composer install --optimize-autoloader --no-dev
RUN npm ci
RUN npm run build
# run laravel cache optimization
RUN php artisan optimize
EXPOSE 8889
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/docker-entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]