Dockerize project

This commit is contained in:
Ben van Hartingsveldt 2025-05-25 19:36:22 +02:00
parent a635331669
commit 10da9c87d7
No known key found for this signature in database
GPG key ID: 261AA214130CE7AB
6 changed files with 108 additions and 0 deletions

16
.github/workflows/docker-image.yml vendored Normal file
View file

@ -0,0 +1,16 @@
name: Docker Image CI
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)

57
Dockerfile Normal file
View file

@ -0,0 +1,57 @@
FROM php:8.4.7-fpm-alpine
# Install PHPize packages
RUN apk add --no-cache --virtual .phpize $PHPIZE_DEPS
# Install Source Packages
ENV SRC_DEPS="gmp-dev icu-dev"
RUN apk add --no-cache --virtual .source $SRC_DEPS
# Install Binary Packages
ENV BIN_DEPS="gmp git icu nginx"
RUN apk add --no-cache --virtual .binary $BIN_DEPS
RUN docker-php-ext-install opcache
# Delete PHPize packages
RUN apk del --no-network --no-cache --purge .phpize
# Delete Source packages
RUN apk del --no-network --no-cache --purge .source
# Remove files
RUN rm -rf /tmp/pear
RUN rm -rf ~/.pearrc
RUN rm -rf /var/cache/apk/*
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Copy files
WORKDIR /var/www/html
COPY . .
RUN mv nginx.conf /etc/nginx/http.d/default.conf
# Install project using Composer
RUN --mount=type=cache,target=/root/.composer composer install --no-interaction --optimize-autoloader --no-dev
# Change permissions
RUN chown -R www-data:www-data storage/
# Setup Process Manager
RUN echo "pm = ondemand" >> /usr/local/etc/php-fpm.d/zz-docker.conf
RUN echo "pm.process_idle_timeout = 10s" >> /usr/local/etc/php-fpm.d/zz-docker.conf
# Setup PHP
RUN mv php.ini /usr/local/etc/php/conf.d/
# Setup Opcache
RUN mv opcache.ini /usr/local/etc/php/conf.d/
# Setup CRON
RUN echo -e "*\t*\t*\t*\t*\tcd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root
VOLUME /var/www/html/storage/framework/cache/data
# Cache project and Start PHP-FPM and NGINX
CMD php artisan optimize; php artisan event:cache; php artisan view:cache; sh -c "php artisan queue:work &"; n crond; nginx -g "daemon off;"

20
nginx.conf Normal file
View file

@ -0,0 +1,20 @@
server{
listen 80;
root /var/www/html/public;
index index.php;
gzip on;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_buffers 16 1024k;
fastcgi_buffer_size 1024k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass localhost:9000;
include /etc/nginx/fastcgi_params;
}
}

7
opcache.ini Normal file
View file

@ -0,0 +1,7 @@
opcache.jit_buffer_size=256M
opcache.max_accelerated_files=20000
opcache.memory_consumption=256
opcache.preload = '/var/www/html/preload.php'
;opcache.preload = '/app/preload.php'
opcache.preload_user = 'www-data'
opcache.validate_timestamps=0

1
php.ini Normal file
View file

@ -0,0 +1 @@
memory_limit = ${PHP_MEMORY_LIMIT}

7
preload.php Normal file
View file

@ -0,0 +1,7 @@
<?php
echo '[Preloading] Started'.PHP_EOL;
/**@var \Composer\Autoload\ClassLoader $loader*/
$loader = require_once 'vendor/autoload.php';
echo '[Preloading] Ended'.PHP_EOL;