Skip to content

Commit f5ab5e9

Browse files
authored
Project created (#1)
* feat: Project - Added onlinesetup file, install instructions with requirements; - Added Makefile; - Added docker-compose files; - Added project.mk file with commands - Added tools.mk with bash color support; - Added nginx default website configuration; - Added .env.dist file;
1 parent a85e7b0 commit f5ab5e9

File tree

16 files changed

+399
-5
lines changed

16 files changed

+399
-5
lines changed

.gitignore

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

CHANGELOG.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Planned
9+
- Add bin directory to checkout during installation, so it will be possible to use shell scripts.
10+
811
### Added
9-
- This CHANGELOG.md file to keep track of all changes in the project.
10-
- .gitignore file to exclude files and folders from being committed, e.g. folder .idea.
11-
- MIT LICENSE file.
12-
- README.md with short project description, contributing section and licence link.
12+
- This _CHANGELOG.md_ file to keep track of all changes in the project.
13+
- _.gitignore_ file to exclude files and folders from being committed, e.g. folder .idea.
14+
- MIT _LICENSE.md_ file.
15+
- _README.md_ with short project description, usage instructions with requirements and installation, contributing section and licence link.
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:
20+
- **help** prints list of all available commands;
21+
- **run**, **stop**, **restart** - containers management;
22+
- **init** copies .env.dist file;
23+
- **ps** shows running containers;
24+
- **logs** shows container logs;
25+
- **bash** enters to php container with bash;
26+
- _.env.dist_ file as an example for _.env_ file

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ others similar is simplicity: you run single bash command and get power of make
55
files for different purposes. After installing php-dockerizer into your project you can commit only files you want
66
to keep.
77

8+
## Usage
9+
10+
Usage of the dockerizer is pretty simple: you run online install command, it fetches changes from install repository to your project and you can commit files you want to keep.
11+
Keep in mind that dockerizer will copy the list of the files and directories to the root of your project:
12+
```text
13+
Makefile
14+
.make
15+
```
16+
* In future dockerizer will be able to detect if there is any file conflicts with your existing files, or
17+
18+
### Requirements
19+
20+
To use dockerizer you need to install [make](https://www.gnu.org/software/make/) and [docker-compose](https://docs.docker.com/compose/install/).
21+
22+
### Installation
23+
24+
To install php-dockerizer simply run command:
25+
```shell
26+
curl -s https://raw.githubusercontent.com/OleksiiBulba/php-dockerizer/master/bin/onelinesetup | bash -s -- https://github.com/OleksiiBulba/php-dockerizer origin/master dockerizer
27+
```
28+
29+
If you cloned repository to your github account, you can install php-dockerizer by a command:
30+
```shell
31+
curl -s https://raw.githubusercontent.com/{you-github-username}/php-dockerizer/master/bin/onelinesetup | bash -s -- https://github.com/{you-github-username}/php-dockerizer origin/master dockerizer
32+
```
33+
34+
You can change `origin/master` to appropriate branch you want to use, and `dockerizer` to any directory name that does not exist in your repo, do not worry, it will be removed after installation.
35+
836
## Contributing
937

1038
Please feel free to open pull request or create an issue, they are more than welcome!

bin/onlinesetup

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
REPO=${1:-https://github.com/OleksiiBulba/php-dockerizer}
4+
VERSION=${2:-origin/master}
5+
INSTALL_DIR=${3:-dockerizer}
6+
7+
mkdir $INSTALL_DIR; cd ./$INSTALL_DIR
8+
9+
git init -qqq
10+
git remote add origin $REPO
11+
git fetch origin -qqq
12+
git checkout $VERSION -- src
13+
# TODO: add bin folder so it will be possible to use shell scripts during installation
14+
15+
PREV_DOTGLOB=$(shopt -p | grep dotglob)
16+
shopt -s dotglob
17+
mv ./src/* ../
18+
$PREV_DOTGLOB
19+
cd ../; rm -rf ./$INSTALL_DIR

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/.env.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
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+
MYSQL_ROOT_PASSWORD=root # Change it on production!
11+
MYSQL_DATABASE=project
12+
13+
# Nginx
14+
NGINX_HOST=website.local

src/.make/project.mk

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.DEFAULT_GOAL := help
2+
3+
DOCKER_COMPOSE := docker-compose -f docker-compose.base.yaml -f docker-compose.${ENV}.yaml
4+
5+
.PHONY: help
6+
help::
7+
@printf "$(BROWN) Project commands:$(NC)\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"
15+
16+
.env .env.local .env.${ENV} .env.${ENV}.local:
17+
cp .env.dist $@
18+
19+
.PHONY: init
20+
init: .env .env.local .env.${ENV} .env.${ENV}.local
21+
22+
.PHONY: run
23+
run: init src composer.json composer.lock vendor .docker docker-compose.base.yaml docker-compose.${ENV}.yaml
24+
$(DOCKER_COMPOSE) up -d
25+
@touch .dc-running
26+
27+
.PHONY: ps
28+
ps: init
29+
$(DOCKER_COMPOSE) ps -a
30+
31+
.PHONY: stop
32+
stop:
33+
$(DOCKER_COMPOSE) down
34+
@rm .dc-running
35+
36+
.PHONY: restart
37+
restart: .dc-running stop run
38+
39+
.PHONY: logs
40+
logs: .dc-running
41+
$(DOCKER_COMPOSE) logs $(service)
42+
43+
.PHONY: bash
44+
bash: .dc-running
45+
$(DOCKER_COMPOSE) exec php bash

src/.make/tools.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include ./.make/tools/colors.mk
2+
3+
SHELL := $(shell which bash)

src/.make/tools/colors.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
NC :=\e[0m # No Color
2+
WHITE := \e[1;37m
3+
BLACK := \e[0;30m
4+
BLUE := \e[0;34m
5+
LIGHT_BLUE := \e[1;34m
6+
GREEN := \e[0;32m
7+
LIGHT_GREEN := \e[1;32m
8+
CYAN := \e[0;36m
9+
LIGHT_CYAN := \e[1;36m
10+
RED := \e[0;31m
11+
LIGHT_RED := \e[1;31m
12+
PURPLE := \e[0;35m
13+
LIGHT_PURPLE := \e[1;35m
14+
BROWN := \e[0;33m
15+
YELLOW := \e[1;33m
16+
GRAY := \e[0;30m
17+
LIGHT_GRAY := \e[0;37m

src/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-include .env .env.local
2+
include ./.make/tools.mk
3+
include ./.make/project.mk

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

0 commit comments

Comments
 (0)