Skip to content

Commit 344b3f8

Browse files
committed
OP-291: Add docker support
1 parent 5e7c0e0 commit 344b3f8

File tree

7 files changed

+217
-1
lines changed

7 files changed

+217
-1
lines changed

.docker/fpm.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[www]
2+
user = www-data
3+
group = www-data
4+
5+
listen = /var/run/php-www.sock
6+
listen.owner = www-data
7+
listen.group = www-data
8+
listen.mode = 0660
9+
10+
clear_env = no
11+
12+
pm = dynamic
13+
pm.max_children = 5
14+
pm.start_servers = 2
15+
pm.min_spare_servers = 1
16+
pm.max_spare_servers = 3
17+
18+
pm.status_path = /status
19+
catch_workers_output = yes
20+
21+
security.limit_extensions = .php

.docker/nginx.conf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
user www-data;
2+
worker_processes auto;
3+
daemon off;
4+
pid /run/nginx.pid;
5+
6+
include /etc/nginx/modules-enabled/*.conf;
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
http {
13+
include /etc/nginx/mime.types;
14+
default_type application/octet-stream;
15+
16+
server_tokens off;
17+
18+
client_max_body_size 64m;
19+
sendfile on;
20+
tcp_nodelay on;
21+
tcp_nopush on;
22+
23+
gzip_vary on;
24+
25+
access_log /var/log/nginx/access.log;
26+
error_log /var/log/nginx/error.log;
27+
28+
server {
29+
listen 80;
30+
31+
root /app/tests/Application/public;
32+
index index.php;
33+
34+
location / {
35+
try_files $uri /index.php$is_args$args;
36+
}
37+
38+
location ~ \.php$ {
39+
include fastcgi_params;
40+
41+
fastcgi_pass unix:/var/run/php-www.sock;
42+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
43+
44+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
45+
fastcgi_param DOCUMENT_ROOT $realpath_root;
46+
}
47+
}
48+
}

.docker/php.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[PHP]
2+
memory_limit=512M
3+
4+
[date]
5+
date.timezone=${PHP_DATE_TIMEZONE}
6+
7+
[opcache]
8+
opcache.enable=0
9+
opcache.memory_consumption=256
10+
opcache.max_accelerated_files=20000
11+
opcache.validate_timestamps=0
12+
;opcache.preload=/app/config/preload.php
13+
opcache.preload_user=www-data
14+
opcache.jit=1255
15+
opcache.jit_buffer_size=256M

.docker/supervisord.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[supervisord]
2+
nodaemon = true
3+
user = root
4+
pidfile = /run/supervisord.pid
5+
6+
[program:nginx]
7+
command = /usr/sbin/nginx
8+
user = root
9+
autostart = true
10+
11+
[program:php-fpm]
12+
command = /usr/sbin/php-fpm -F
13+
user = root
14+
autostart = true

Dockerfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
FROM ubuntu:20.04
2+
ARG DEBIAN_FRONTEND=noninteractive
3+
ARG PHP_VERSION=8.1
4+
ENV LC_ALL=C.UTF-8
5+
6+
# Install basic tools
7+
RUN apt-get update && apt-get install -y \
8+
software-properties-common \
9+
curl \
10+
make \
11+
supervisor \
12+
unzip \
13+
python2 \
14+
g++
15+
16+
# Append NODE, NGINX and PHP repositories
17+
RUN add-apt-repository ppa:ondrej/php \
18+
&& add-apt-repository ppa:ondrej/nginx \
19+
&& curl -sL https://deb.nodesource.com/setup_14.x | bash -
20+
21+
# Install required PHP extensions
22+
RUN apt-get update && apt-get install -y \
23+
nodejs \
24+
nginx \
25+
php${PHP_VERSION} \
26+
php${PHP_VERSION}-apcu \
27+
php${PHP_VERSION}-calendar \
28+
php${PHP_VERSION}-common \
29+
php${PHP_VERSION}-cli \
30+
php${PHP_VERSION}-ctype \
31+
php${PHP_VERSION}-curl \
32+
php${PHP_VERSION}-dom \
33+
php${PHP_VERSION}-exif \
34+
php${PHP_VERSION}-fpm \
35+
php${PHP_VERSION}-gd \
36+
php${PHP_VERSION}-intl \
37+
php${PHP_VERSION}-mbstring \
38+
php${PHP_VERSION}-mysql \
39+
php${PHP_VERSION}-opcache \
40+
php${PHP_VERSION}-pdo \
41+
php${PHP_VERSION}-pgsql \
42+
php${PHP_VERSION}-sqlite \
43+
php${PHP_VERSION}-xml \
44+
php${PHP_VERSION}-xsl \
45+
php${PHP_VERSION}-yaml \
46+
php${PHP_VERSION}-zip
47+
48+
# Install Composer
49+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename composer
50+
51+
# Cleanup
52+
RUN apt-get remove --purge -y software-properties-common curl && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* /usr/share/man/*
53+
54+
# Create directory for php-fpm socket
55+
# Link php-fpm binary file without version
56+
# -p Creates missing intermediate path name directories
57+
RUN ln -s /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm && mkdir -p /run/php
58+
59+
# Install yarn
60+
RUN npm install -g yarn && npm cache clean --force
61+
62+
# Initialize config files
63+
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisor.conf
64+
COPY .docker/nginx.conf /etc/nginx/nginx.conf
65+
COPY .docker/fpm.conf /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
66+
COPY .docker/php.ini /etc/php/${PHP_VERSION}/fpm/php.ini
67+
COPY .docker/php.ini /etc/php/${PHP_VERSION}/cli/php.ini
68+
69+
WORKDIR /app
70+
71+
EXPOSE 80
72+
73+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

docker-compose.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
services:
2+
app:
3+
container_name: app
4+
build:
5+
context: .
6+
environment:
7+
APP_ENV: "dev"
8+
DATABASE_URL: "mysql://root:mysql@mysql/sylius_%kernel.environment%?charset=utf8mb4"
9+
# DATABASE_URL: "pgsql://root:postgres@postgres/sylius_%kernel.environment%?charset=utf8" # When using postgres
10+
PHP_DATE_TIMEZONE: "Europe/Warsaw"
11+
volumes:
12+
- ./:/app:delegated
13+
- ./.docker/php.ini:/etc/php8/php.ini:delegated
14+
- ./.docker/nginx.conf:/etc/nginx/nginx.conf:delegated
15+
ports:
16+
- 80:80
17+
depends_on:
18+
- mysql
19+
networks:
20+
- sylius
21+
22+
mysql:
23+
container_name: mysql
24+
image: mysql:8.0
25+
platform: linux/amd64
26+
environment:
27+
MYSQL_ROOT_PASSWORD: mysql
28+
ports:
29+
- ${MYSQL_PORT:-3306}:3306
30+
networks:
31+
- sylius
32+
33+
# postgres:
34+
# image: postgres:14-alpine
35+
# environment:
36+
# POSTGRES_USER: root
37+
# POSTGRES_PASSWORD: postgres
38+
# ports:
39+
# - ${POSTGRES_PORT:-5432}:5432
40+
# networks:
41+
# - sylius
42+
43+
networks:
44+
sylius:
45+
driver: bridge

tests/Application/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ APP_SECRET=EDITME
1212
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
1313
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
1414
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
15-
DATABASE_URL=mysql://root@127.0.0.1/sylius_wish_list_plugin_%kernel.environment%?serverVersion=5.7
15+
DATABASE_URL=mysql://root@127.0.0.1/sylius_wish_list_plugin_%kernel.environment%
1616
###< doctrine/doctrine-bundle ###
1717

1818
###> symfony/swiftmailer-bundle ###

0 commit comments

Comments
 (0)