Skip to content

Commit 10da9c8

Browse files
committed
Dockerize project
1 parent a635331 commit 10da9c8

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed

.github/workflows/docker-image.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Build the Docker image
16+
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM php:8.4.7-fpm-alpine
2+
3+
# Install PHPize packages
4+
RUN apk add --no-cache --virtual .phpize $PHPIZE_DEPS
5+
6+
# Install Source Packages
7+
ENV SRC_DEPS="gmp-dev icu-dev"
8+
RUN apk add --no-cache --virtual .source $SRC_DEPS
9+
10+
# Install Binary Packages
11+
ENV BIN_DEPS="gmp git icu nginx"
12+
RUN apk add --no-cache --virtual .binary $BIN_DEPS
13+
14+
RUN docker-php-ext-install opcache
15+
16+
# Delete PHPize packages
17+
RUN apk del --no-network --no-cache --purge .phpize
18+
19+
# Delete Source packages
20+
RUN apk del --no-network --no-cache --purge .source
21+
22+
# Remove files
23+
RUN rm -rf /tmp/pear
24+
RUN rm -rf ~/.pearrc
25+
RUN rm -rf /var/cache/apk/*
26+
27+
# Install Composer
28+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
29+
30+
# Copy files
31+
WORKDIR /var/www/html
32+
COPY . .
33+
RUN mv nginx.conf /etc/nginx/http.d/default.conf
34+
35+
# Install project using Composer
36+
RUN --mount=type=cache,target=/root/.composer composer install --no-interaction --optimize-autoloader --no-dev
37+
38+
# Change permissions
39+
RUN chown -R www-data:www-data storage/
40+
41+
# Setup Process Manager
42+
RUN echo "pm = ondemand" >> /usr/local/etc/php-fpm.d/zz-docker.conf
43+
RUN echo "pm.process_idle_timeout = 10s" >> /usr/local/etc/php-fpm.d/zz-docker.conf
44+
45+
# Setup PHP
46+
RUN mv php.ini /usr/local/etc/php/conf.d/
47+
48+
# Setup Opcache
49+
RUN mv opcache.ini /usr/local/etc/php/conf.d/
50+
51+
# Setup CRON
52+
RUN echo -e "*\t*\t*\t*\t*\tcd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root
53+
54+
VOLUME /var/www/html/storage/framework/cache/data
55+
56+
# Cache project and Start PHP-FPM and NGINX
57+
CMD php artisan optimize; php artisan event:cache; php artisan view:cache; sh -c "php artisan queue:work &"; n crond; nginx -g "daemon off;"

nginx.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server{
2+
listen 80;
3+
4+
root /var/www/html/public;
5+
index index.php;
6+
7+
gzip on;
8+
9+
location / {
10+
try_files $uri $uri/ /index.php?$args;
11+
}
12+
13+
location ~ \.php$ {
14+
fastcgi_buffers 16 1024k;
15+
fastcgi_buffer_size 1024k;
16+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
17+
fastcgi_pass localhost:9000;
18+
include /etc/nginx/fastcgi_params;
19+
}
20+
}

opcache.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
opcache.jit_buffer_size=256M
2+
opcache.max_accelerated_files=20000
3+
opcache.memory_consumption=256
4+
opcache.preload = '/var/www/html/preload.php'
5+
;opcache.preload = '/app/preload.php'
6+
opcache.preload_user = 'www-data'
7+
opcache.validate_timestamps=0

php.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
memory_limit = ${PHP_MEMORY_LIMIT}

preload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
echo '[Preloading] Started'.PHP_EOL;
3+
4+
/**@var \Composer\Autoload\ClassLoader $loader*/
5+
$loader = require_once 'vendor/autoload.php';
6+
7+
echo '[Preloading] Ended'.PHP_EOL;

0 commit comments

Comments
 (0)