Skip to content

Commit

Permalink
feat: docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
bezumkin committed Jul 22, 2022
1 parent 173c1bf commit b1e7987
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/.env
/.env.local
/core/vendor
/docker/.env
/docker/log
/docker/mariadb/data
/frontend/node_modules
/frontend/.nuxt
/frontend/.eslintcache
Expand Down
43 changes: 43 additions & 0 deletions docker/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### Docker
COMPOSE_PROJECT_NAME=vesp

NGINX_VERSION=1.22
NGINX_PORT=8080

MARIADB_VERSION=10
MARIADB_USERNAME=vesp
MARIADB_PASSWORD=vesp
MARIADB_DATABASE=vesp
MARIADB_PORT=3333

PHP_VERSION=8.1

NODE_VERSION=18.6
NODE_ADMIN_PORT=4000
NODE_SITE_PORT=4100

### Vesp
APP_NAME="Vesp Framework"

SITE_URL=http://127.0.0.1:8080/
API_URL=http://127.0.0.1:8080/api/

CORS=1

DB_DRIVER=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_PREFIX=app_
DB_DATABASE=vesp
DB_USERNAME=vesp
DB_PASSWORD=vesp
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_general_ci
DB_FOREIGN_KEYS=1

JWT_SECRET=secret
JWT_EXPIRE=2592000
JWT_MAX=3

UPLOAD_DIR=/vesp/upload/
CACHE_DIR=/vesp/tmp/
67 changes: 67 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3.9'
services:

mariadb:
image: mariadb:${MARIADB_VERSION}
environment:
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=yes
- MARIADB_DATABASE=${MARIADB_DATABASE}
- MARIADB_USER=${MARIADB_USERNAME}
- MARIADB_PASSWORD=${MARIADB_PASSWORD}
volumes:
- ./mariadb/data:/var/lib/mysql
ports:
- ${MARIADB_PORT}:3306
working_dir: /vesp

nginx:
image: nginx:${NGINX_VERSION}
volumes:
- ./nginx/config.conf:/etc/nginx/conf.d/default.conf
- ./log/nginx:/var/log/nginx
- ../frontend:/vesp/frontend
- ../www:/vesp/www
ports:
- ${NGINX_PORT}:80
depends_on:
- php-fpm
- mariadb
working_dir: /vesp

php-fpm:
build:
context: ./php-fpm
args:
- PHP_VERSION
volumes:
- ./.env:/vesp/.env
- ./php-fpm/config.conf:/usr/local/etc/php-fpm.d/www.conf
- ./php-fpm/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./log/php-fpm:/var/log/php
- ../core:/vesp/core
- ../www:/vesp/www
- ../upload:/vesp/upload
- ../tmp:/vesp/tmp
- ../composer.json:/vesp/composer.json
cap_add:
- SYS_PTRACE
depends_on:
- mariadb
environment:
PHP_IDE_CONFIG: "serverName=VespDocker"
working_dir: /vesp

node:
build:
context: ./node
args:
- NODE_VERSION
volumes:
- ./.env:/vesp/.env
- ../frontend:/vesp/frontend
environment:
NODE_OPTIONS: "--openssl-legacy-provider"
ports:
- ${NODE_ADMIN_PORT}:4000
- ${NODE_SITE_PORT}:4100
working_dir: /vesp/frontend
55 changes: 55 additions & 0 deletions docker/nginx/config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
server {
listen 80 default;
charset utf-8;
root /vesp/www/;

location ~ ^/(api|__clockwork)/ {
rewrite ^/(api|__clockwork)/(.*)$ /api.php;
}

location /admin {
absolute_redirect off;
return 301 /admin/;
}

location /admin/ {
root /vesp/frontend/dist/;
access_log off;
log_not_found off;
gzip on;
gzip_types text/css application/javascript application/x-javascript text/javascript image/svg+xml;
expires 1y;
try_files $uri /admin/200.html;
}

location / {
# proxy_http_version 1.1;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header Host $http_host;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# proxy_redirect off;
# proxy_read_timeout 240s;
# proxy_pass http://127.0.0.1:20001;

root /vesp/frontend/dist/site/;
access_log off;
log_not_found off;
gzip on;
gzip_types text/css application/javascript application/x-javascript text/javascript image/svg+xml;
expires 1y;
try_files $uri /200.html;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_pass php-fpm:9000;
}

location ~ /\.(?!well-known).* {
deny all;
}
}

9 changes: 9 additions & 0 deletions docker/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG NODE_VERSION=${NODE_VERSION}

FROM node:${NODE_VERSION}-alpine

RUN apk update && apk upgrade

WORKDIR /vesp/frontend

CMD yarn && ([ -d dist ] || yarn generate) && yarn dev
13 changes: 13 additions & 0 deletions docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG PHP_VERSION=${PHP_VERSION}

FROM php:${PHP_VERSION}-fpm-alpine

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN apk update && apk upgrade
RUN apk add build-base autoconf libzip-dev libpng-dev bash

RUN pecl install xdebug
RUN docker-php-ext-install gd
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo_mysql
35 changes: 35 additions & 0 deletions docker/php-fpm/config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[global]
daemonize = no
error_log = /var/log/php/error.log

[www]
user = www-data
group = www-data
listen.mode = 0666
listen.backlog = -1

chdir = /vesp/

request_slowlog_timeout = 5
slowlog = /var/log/php/slow.log
catch_workers_output = 1

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

php_value[open_basedir] = /vesp
php_value[upload_tmp_dir] = /vesp/tmp
php_value[sys_temp_dir] = /vesp/tmp
php_value[post_max_size] = 500M
php_value[upload_max_filesize] = 500M
php_value[memory_limit] = 128M
php_value[sendmail_path] = /usr/sbin/sendmail -t -i

;php_value[date.timezone] = Europe/Moscow
php_value[log_errors] = 1
php_value[display_errors] = 0
php_value[error_log] = /var/log/php/error.log
php_value[error_reporting] = E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_USER_DEPRECATED
8 changes: 8 additions & 0 deletions docker/php-fpm/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.log_level=0
# xdebug.log=/var/log/php/xdebug.log

0 comments on commit b1e7987

Please sign in to comment.