Skip to content

Commit 0a62500

Browse files
committed
feat: Project
- Added docker-compose files; - Added more commands to project.mk file; - Added nginx default website configuration;
1 parent 104c0b6 commit 0a62500

File tree

9 files changed

+288
-4
lines changed

9 files changed

+288
-4
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
/.idea
1+
/.idea
2+
/src/.env*
3+
/src/.dc-running
4+
/src/composer.json
5+
/src/composer.lock
6+
/src/src/
7+
/src/vendor/

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- _.gitignore_ file to exclude files and folders from being committed, e.g. folder .idea.
1414
- MIT _LICENSE.md_ file.
1515
- _README.md_ with short project description, usage instructions with requirements and installation, contributing section and licence link.
16-
- Added _onlinesetup_ file that can be used to install project via a network, this file accepts three useful arguments: repository from which to install dockerizer (helps to debug or install own modification), branch (again, helps to debug or install own modification) and install directory in case your project uses same name as default install folder.
17-
- Added _Makefile_, _.make/tools.mk_ for helper constants, _.make/tools/colors.mk_ for CLI colors, _.make/project.mk_ with help target that prints the help message.
16+
- _onlinesetup_ file that can be used to install project via a network, this file accepts three useful arguments: repository from which to install dockerizer (helps to debug or install own modification), branch (again, helps to debug or install own modification) and install directory in case your project uses same name as default install folder.
17+
- _Makefile_ file that includes other mk helper files from _.make_ directory.
18+
- _.make/tools.mk_ files for bash constants, _.make/tools/colors.mk_ file for bash colors
19+
- _.make/project.mk_ with targets for project managing: help, start, stop, restart etc.

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
upstream fastcgi_backend {
2+
server php:9000;
3+
}
4+
5+
server {
6+
listen 80;
7+
server_name ${NGINX_HOST};
8+
9+
set $SITE_ROOT /var/www/html;
10+
root $SITE_ROOT/public;
11+
12+
index index.php;
13+
autoindex off;
14+
charset off;
15+
16+
add_header 'X-Content-Type-Options' 'nosniff';
17+
add_header 'X-XSS-Protection' '1; mode=block';
18+
19+
location / {
20+
try_files $uri $uri/ /index.php?$args;
21+
}
22+
23+
location /public {
24+
alias $SITE_ROOT/public;
25+
add_header X-Frame-Options "SAMEORIGIN";
26+
}
27+
28+
location ~ (index|get|static|report|404|503)\.php$ {
29+
try_files $uri =404;
30+
fastcgi_pass fastcgi_backend;
31+
32+
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
33+
fastcgi_param PHP_VALUE "max_execution_time=600";
34+
fastcgi_read_timeout 600s;
35+
fastcgi_connect_timeout 600s;
36+
37+
fastcgi_index index.php;
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
include fastcgi_params;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
upstream fastcgi_backend {
2+
server php:9000;
3+
}
4+
5+
server {
6+
listen 80;
7+
server_name ${NGINX_HOST};
8+
9+
set $SITE_ROOT /var/www/html;
10+
root $SITE_ROOT/public;
11+
12+
index index.php;
13+
autoindex off;
14+
charset off;
15+
16+
add_header 'X-Content-Type-Options' 'nosniff';
17+
add_header 'X-XSS-Protection' '1; mode=block';
18+
19+
location / {
20+
try_files $uri $uri/ /index.php?$args;
21+
}
22+
23+
location /public {
24+
alias $SITE_ROOT/public;
25+
add_header X-Frame-Options "SAMEORIGIN";
26+
}
27+
28+
location ~ (index|get|static|report|404|503)\.php$ {
29+
try_files $uri =404;
30+
fastcgi_pass fastcgi_backend;
31+
32+
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
33+
fastcgi_param PHP_VALUE "max_execution_time=600";
34+
fastcgi_read_timeout 600s;
35+
fastcgi_connect_timeout 600s;
36+
37+
fastcgi_index index.php;
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
include fastcgi_params;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
upstream fastcgi_backend {
2+
server php:9000;
3+
}
4+
5+
server {
6+
listen 80;
7+
server_name ${NGINX_HOST};
8+
9+
set $SITE_ROOT /var/www/html;
10+
root $SITE_ROOT/public;
11+
12+
index index.php;
13+
autoindex off;
14+
charset off;
15+
16+
add_header 'X-Content-Type-Options' 'nosniff';
17+
add_header 'X-XSS-Protection' '1; mode=block';
18+
19+
location / {
20+
try_files $uri $uri/ /index.php?$args;
21+
}
22+
23+
location /public {
24+
alias $SITE_ROOT/public;
25+
add_header X-Frame-Options "SAMEORIGIN";
26+
}
27+
28+
location ~ (index|get|static|report|404|503)\.php$ {
29+
try_files $uri =404;
30+
fastcgi_pass fastcgi_backend;
31+
32+
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
33+
fastcgi_param PHP_VALUE "max_execution_time=600";
34+
fastcgi_read_timeout 600s;
35+
fastcgi_connect_timeout 600s;
36+
37+
fastcgi_index index.php;
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
include fastcgi_params;
40+
}
41+
}

src/.make/project.mk

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

3+
DOCKER_COMPOSE := docker-compose -f docker-compose.base.yaml -f docker-compose.${ENV}.yaml
4+
35
.PHONY: help
46
help::
57
@printf "$(BROWN) Project commands:$(NC)\n"
6-
@printf "$(GREEN) help $(NC) Display this help message\n"
8+
@printf "$(GREEN) help $(NC) Display this help message\n"
9+
@printf "$(GREEN) run $(NC) Run docker containers\n"
10+
@printf "$(GREEN) ps $(NC) Show running containers\n"
11+
@printf "$(GREEN) stop $(NC) Stops all containers\n"
12+
@printf "$(GREEN) restart $(NC) Stops and runs again all containers\n"
13+
@printf "$(GREEN) logs $(NC) Show containers logs\n"
14+
@printf "$(GREEN) bash $(NC) Show containers logs\n\n\n"
15+
@printf "$(GREEN) NGINX_SERVER_CONFIG_FILE: $(NGINX_SERVER_CONFIG_FILE)\n"
16+
17+
.PHONY: run
18+
run: .env .env.local src composer.json composer.lock vendor .docker docker-compose.base.yaml docker-compose.${ENV}.yaml
19+
$(DOCKER_COMPOSE) up -d
20+
@touch .dc-running
21+
22+
.PHONY: ps
23+
ps:
24+
$(DOCKER_COMPOSE) ps -a
25+
26+
.PHONY: stop
27+
stop:
28+
$(DOCKER_COMPOSE) down
29+
@rm .dc-running
30+
31+
.PHONY: restart
32+
restart: .dc-running stop run
33+
34+
.PHONY: logs
35+
logs: .dc-running
36+
$(DOCKER_COMPOSE) logs $(service)
37+
38+
.PHONY: bash
39+
bash: .dc-running
40+
$(DOCKER_COMPOSE) exec php bash

src/docker-compose.base.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
version: '3.7'
2+
3+
networks:
4+
project-network:
5+
driver: bridge
6+
7+
volumes:
8+
db:
9+
driver: local
10+
11+
services:
12+
nginx:
13+
image: nginx:latest
14+
container_name: ${PROJECT_NAME:-project_}_nginx
15+
ports:
16+
- "80:80"
17+
volumes:
18+
- ./src:/var/www/html:ro
19+
- ${NGINX_SERVER_CONFIG_FILE:-./.docker/nginx/config/developer.conf}:/etc/nginx/conf.d/default.conf:ro
20+
env_file:
21+
- ./.env
22+
- ./.env.local
23+
depends_on:
24+
- php
25+
networks:
26+
- project-network
27+
28+
php:
29+
image: php:8.0.0-fpm
30+
container_name: ${PROJECT_NAME:-project_}_php
31+
ports:
32+
- "9000:9000"
33+
- "2222:22" # ssh connection with container
34+
- "9003:9003" # xdebug
35+
volumes:
36+
- ./src:/var/www/html:rw
37+
- ~/.composer:/var/www/.composer:rw
38+
- ~/.npm:/var/www/.npm:rw
39+
env_file:
40+
- ./.env
41+
- ./.env.local
42+
environment:
43+
- PHP_MEMORY_LIMIT=2048mb
44+
- XDEBUG_ENABLED=0
45+
depends_on:
46+
- db
47+
links:
48+
- db
49+
networks:
50+
- project-network
51+
52+
db:
53+
image: mysql:5.7
54+
container_name: ${PROJECT_NAME:-project_}_db
55+
ports:
56+
- 3300:3306
57+
env_file:
58+
- ./.env
59+
- ./.env.local
60+
volumes:
61+
- db:/var/lib/mysql:rw
62+
networks:
63+
project-network:
64+
aliases:
65+
- db-server

src/docker-compose.dev.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3.7'
2+
3+
networks:
4+
project-network:
5+
driver: bridge
6+
7+
services:
8+
nginx:
9+
env_file:
10+
- ./.env.dev
11+
- ./.env.dev.local
12+
13+
php:
14+
ports:
15+
- "2222:22" # ssh connection with container
16+
- "9003:9003" # xdebug default port
17+
env_file:
18+
- ./.env.dev
19+
- ./.env.dev.local
20+
environment:
21+
- XDEBUG_ENABLED=1
22+
- XDEBUG_CONFIG=PHPSTORM
23+
- PHP_IDE_CONFIG=serverName=nginx
24+
25+
db:
26+
env_file:
27+
- ./.env.dev
28+
- ./.env.dev.local

src/docker-compose.prod.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3.7'
2+
3+
networks:
4+
project-network:
5+
driver: bridge
6+
7+
services:
8+
nginx:
9+
ports:
10+
- "443:443"
11+
volumes:
12+
- ./.docker/nginx/ssl/nginx-selfsigned.key:/etc/nginx/ssl/nginx-selfsigned.key
13+
- ./.docker/nginx/ssl/nginx-selfsigned.crt:/etc/nginx/ssl/nginx-selfsigned.crt
14+
env_file:
15+
- ./.env.prod
16+
- ./.env.prod.local
17+
18+
php:
19+
env_file:
20+
- ./.env.prod
21+
- ./.env.prod.local
22+
23+
db:
24+
env_file:
25+
- ./.env.prod
26+
- ./.env.prod.local

0 commit comments

Comments
 (0)