Skip to content

Commit 079c2be

Browse files
committed
feat: refactoring
- Reorganized files into .docker file; - Added Dockerfile for php container based on php-fpm-alpine image; - Nginx used alpine image; - Added php ini files; - Refactored nginx conf file into template for nginx container; instead of three different conf files for every env now only one conf template;
1 parent 6c5d1ee commit 079c2be

File tree

16 files changed

+178
-150
lines changed

16 files changed

+178
-150
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Usage of the dockerizer is pretty simple: you run online install command, it fet
1111
Keep in mind that dockerizer will copy the list of the files and directories to the root of your project:
1212
```text
1313
Makefile
14+
.docker
1415
.make
1516
```
1617
* In future dockerizer will be able to detect if there is any file conflicts with your existing files, or

src/.docker/.env.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#APP_ENV=dev
2+
#
3+
## defines prefix to all container names
4+
##PROJECT_NAME=project
5+
#
6+
## MySQL database
7+
#MYSQL_HOST=localhost
8+
#MYSQL_USER=db_user
9+
#MYSQL_PASSWORD=db_password
10+
## Change it on production!
11+
#MYSQL_ROOT_PASSWORD=root
12+
#MYSQL_DATABASE=project
13+
#
14+
## Nginx
15+
#NGINX_HOST=website.local
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
upstream fastcgi_backend {
2+
server php:9000;
3+
}
4+
5+
server {
6+
listen ${NGINX_PORT:-80};
7+
server_name ${NGINX_HOST:-website.local};
8+
root ${SITE_ROOT:-/app/public};
9+
10+
location / {
11+
# try to serve file directly, fallback to index.php
12+
try_files $uri /index.php$is_args$args;
13+
}
14+
15+
location /public {
16+
alias ${SITE_ROOT:-/app/public};
17+
add_header X-Frame-Options "SAMEORIGIN";
18+
}
19+
20+
# optionally disable falling back to PHP script for the asset directories;
21+
# nginx will return a 404 error when files are not found instead of passing the
22+
# request to Symfony (improves performance but Symfony's 404 page is not displayed)
23+
#location /bundles {
24+
# try_files $uri =404;
25+
#}
26+
27+
index index.php;
28+
autoindex off;
29+
charset off;
30+
31+
add_header 'X-Content-Type-Options' 'nosniff';
32+
add_header 'X-XSS-Protection' '1; mode=block';
33+
34+
35+
location ~ ^/index\.php(/|$) {
36+
try_files $uri =404;
37+
fastcgi_pass fastcgi_backend;
38+
39+
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
40+
fastcgi_param PHP_VALUE "max_execution_time=600";
41+
fastcgi_read_timeout 600s;
42+
fastcgi_connect_timeout 600s;
43+
44+
fastcgi_index index.php;
45+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
46+
fastcgi_param DOCUMENT_ROOT $realpath_root;
47+
include fastcgi_params;
48+
49+
internal;
50+
}
51+
52+
# return 404 for all other php files not matching the front controller
53+
# this prevents access to other php files you don't want to be accessible.
54+
location ~ \.php$ {
55+
return 404;
56+
}
57+
58+
error_log /var/log/nginx/project_error.log;
59+
access_log /var/log/nginx/project_access.log;
60+
}

src/.docker/build/php/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ARG PHP_VERSION=8.0.0
2+
FROM composer:latest AS composer
3+
FROM php:${PHP_VERSION}-fpm-alpine
4+
5+
LABEL maintainer="Oleksii Bulba <oleksii.bulba@gmail.com>"
6+
7+
WORKDIR /app
8+
9+
# Install PHP modules
10+
RUN apk add --no-cache --virtual \
11+
.phpize-deps $PHPIZE_DEPS \
12+
autoconf \
13+
pkgconf \
14+
libssl1.0 \
15+
openssl-dev \
16+
freetype-dev \
17+
libpng-dev \
18+
libjpeg-turbo-dev \
19+
libmcrypt-dev \
20+
git \
21+
libsodium-dev \
22+
openssh-client \
23+
curl \
24+
wget \
25+
libtool \
26+
zlib-dev \
27+
icu-dev \
28+
g++ \
29+
linux-headers > /dev/null \
30+
&& pecl bundle -d /usr/src/php/ext redis \
31+
&& docker-php-ext-install -j2 redis \
32+
&& docker-php-ext-configure intl \
33+
&& docker-php-ext-install -j2 intl \
34+
&& pecl bundle -d /usr/src/php/ext mcrypt \
35+
&& docker-php-ext-configure mcrypt \
36+
&& pecl bundle -d /usr/src/php/ext apcu \
37+
&& docker-php-ext-install -j2 apcu \
38+
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
39+
&& docker-php-ext-install -j2 bcmath gd iconv mbstring mcrypt zip \
40+
&& docker-php-ext-enable opcache \
41+
&& rm /usr/src/php/ext/*.tgz \
42+
&& pecl install xdebug \
43+
&& docker-php-ext-enable xdebug
44+
45+
COPY --from=composer /usr/bin/composer /usr/bin/composer
46+
47+
RUN pecl channel-update pecl.php.net \
48+
# && pecl install mongodb \
49+
# && docker-php-ext-enable mongodb \
50+
&& composer global require "phpunit/phpunit" \
51+
&& export PATH=$PATH:/root/.composer/vendor/bin \
52+
&& ln -s /root/.composer/vendor/bin/phpunit /usr/bin/phpunit
53+
54+
CMD ["php-fpm"]

src/.docker/build/php/opcache.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
opcache.enable = 1
2+
opcache.enable_cli = 1
3+
opcache.memory_consumption = 512M
4+
opcache.max_accelerated_files = 100000
5+
opcache.validate_timestamps=0
6+
opcache.consistency_checks=0
7+
opcache.interned_strings_buffer=8
8+
opcache.fast_shutdown=1
9+
opcache.revalidate_freq = 0
10+
opcache.revalidate_path = 1

src/.docker/build/php/php.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
memory_limit = 2048M
2+
max_execution_time = 38000
3+
always_populate_raw_post_data = -1
4+
date.timezone = "UTC"
5+
upload_max_filesize = 128M
6+
zlib.output_compression = on
7+
log_errors = On
8+
display_errors = Off
9+
;sendmail_path = "/opt/go/bin/mhsendmail --smtp-addr='mailhog:1025'"

src/.docker/build/php/xdebug.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
xdebug.idekey="PHPSTORM"
2+
xdebug.mode=develop,debug
3+
xdebug.client_host=host.docker.internal
4+
xdebug.client_port=9003
5+
xdebug.start_with_request=yes
6+
xdebug.remote_handler=dbgp
7+
xdebug.output_dir="/app/var/log/xdebug"
8+
xdebug.discover_client_host=true
9+
xdebug.cli_color=1
10+
xdebug.var_display_max_depth=15
11+
xdebug.remote_cookie_expire_time=-9999

src/docker-compose.base.yaml renamed to src/.docker/docker-compose.base.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ volumes:
1010

1111
services:
1212
nginx:
13-
image: nginx:latest
13+
image: nginx:1.19.6-alpine
1414
container_name: ${PROJECT_NAME:-project}_nginx
1515
ports:
1616
- "80:80"
1717
volumes:
18-
- ./src:/var/www/html:ro
19-
- ${NGINX_SERVER_CONFIG_FILE:-./.docker/nginx/config/developer.conf}:/etc/nginx/conf.d/default.conf:ro
18+
- .:/app:ro
19+
- /app/vendor
20+
- ./build/nginx/templates:/etc/nginx/templates
21+
- ./var/log/nginx:/var/log/nginx/
2022
env_file:
23+
- SITE_ROOT=/app/public
2124
- ./.env
2225
- ./.env.local
2326
depends_on:
@@ -26,14 +29,14 @@ services:
2629
- project-network
2730

2831
php:
29-
image: php:8.0.0-fpm
32+
build:
33+
context: ./build/php/
3034
container_name: ${PROJECT_NAME:-project}_php
3135
ports:
3236
- "9000:9000"
33-
- "2222:22" # ssh connection with container
34-
- "9003:9003" # xdebug
3537
volumes:
36-
- ./src:/var/www/html:rw
38+
- .:/app:rw
39+
- ./.docker/build/php/php.ini:/etc/php/8.0/fpm/conf.d/custom.ini
3740
- ~/.composer:/var/www/.composer:rw
3841
- ~/.npm:/var/www/.npm:rw
3942
env_file:

src/docker-compose.dev.yaml renamed to src/.docker/docker-compose.dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ services:
1414
ports:
1515
- "2222:22" # ssh connection with container
1616
- "9003:9003" # xdebug default port
17+
volumes:
18+
- ./.docker/build/php/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
1719
env_file:
1820
- ./.env.dev
1921
- ./.env.dev.local
File renamed without changes.

src/.docker/nginx/config/default.conf

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/.docker/nginx/config/developer.conf

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/.docker/nginx/config/production.conf

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/.env.dist

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/.make/project.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DEFAULT_GOAL := help
22

3-
DOCKER_COMPOSE := docker-compose -f docker-compose.base.yaml -f docker-compose.${ENV}.yaml
3+
DOCKER_COMPOSE := docker-compose -f ./.docker/docker-compose.base.yaml -f ./.docker/docker-compose.${APP_ENV}.yaml
44

55
.PHONY: help
66
help::
@@ -13,14 +13,14 @@ help::
1313
@printf "$(GREEN) logs $(NC) Show containers logs\n"
1414
@printf "$(GREEN) bash $(NC) Show containers logs\n"
1515

16-
.env .env.local .env.${ENV} .env.${ENV}.local:
17-
cp .env.dist $@
16+
.env .env.local .env.${APP_ENV} .env.${APP_ENV}.local:
17+
cp ./.docker/.env.dist $@
1818

1919
.PHONY: init
20-
init: .env .env.local .env.${ENV} .env.${ENV}.local
20+
init: .env .env.local .env.${APP_ENV} .env.${APP_ENV}.local
2121

2222
.PHONY: run
23-
run: init src composer.json composer.lock vendor .docker docker-compose.base.yaml docker-compose.${ENV}.yaml
23+
run: init src composer.json composer.lock vendor .docker docker-compose.base.yaml docker-compose.${APP_ENV}.yaml
2424
$(DOCKER_COMPOSE) up -d
2525
@touch .dc-running
2626

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-include .env .env.local
2+
-include .env.$(ENV) .env.$(ENV).local
23
include ./.make/tools.mk
34
include ./.make/project.mk

0 commit comments

Comments
 (0)