Skip to content

Commit 72113f1

Browse files
committed
add infra
1 parent 60531f8 commit 72113f1

19 files changed

+1178
-0
lines changed

.env.example

+13
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ DB_PASS=password
1111
YII_DEBUG=true
1212
YII_ENV=dev
1313
YII_MAIL_USE_FILE_TRANSPORT=true
14+
15+
#MAIL_HOST=smtp.mailgun.org
16+
#MAIL_USERNAME=
17+
#MAIL_PASSWORD=
18+
19+
#REDIS_CACHE_HOST=redis
20+
#REDIS_CACHE_DB=1
21+
22+
#HTTP_HOST=127.0.0.1:8093
23+
#ENFORCE_HTTPS=0
24+
25+
#SERVER_NAME="user@host"
26+
#SERVER_DIR="/some/dir/on/server"

Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-include ./.env
2+
export
13
serve:
24
php yii serve --docroot=@webroot --port=8899
35
run:
@@ -32,3 +34,27 @@ codecept-bootstrap:
3234
php codecept.phar bootstrap && php codecept.phar build
3335
deploy:
3436
echo "Not implemented"
37+
38+
# Infra
39+
infra-up:
40+
cd infracture && make up
41+
infra-start:
42+
cd infracture && make start
43+
infra-stop:
44+
cd infracture && make stop
45+
infra-down:
46+
cd infracture && make down
47+
infra-rm:
48+
cd infracture && make rm
49+
infra-logs:
50+
cd infracture && make logs
51+
52+
# Server
53+
server-ssh:
54+
sh ./bin/server-tools.sh ssh
55+
server-deploy:
56+
sh ./bin/server-tools.sh deploy
57+
server-logs:
58+
sh ./bin/server-tools.sh logs
59+
server-sync:
60+
sh ./bin/server-tools.sh sync

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ vendors 3rd-party packages
1414
runtime/ contains files generated during runtime
1515
tests/ contains various tests for the basic application
1616
web/ the entry script and Web resources
17+
infracture/ the infrastructure folder (docker/docker-compose setup)
18+
bin/ scripts
1719
```
1820

1921
## REQUIREMENTS

bin/letsencrypt.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
add-apt-repository ppa:certbot/certbot
4+
apt install python-certbot-nginx

bin/server-tools.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
source ./.env
4+
5+
SYNC_EXCLUDE=(.git vendor .env .idea infracture/data/* runtime/ .DS_Store web/assets/ web/minify/ web/thumbs/ web/uploads/)
6+
7+
if (( $# < 1 )); then
8+
echo -e "Illegal number of parameters. \nUsage sh tools.sh command"
9+
exit 1
10+
fi
11+
12+
echo "Connecting to $SERVER_NAME..."
13+
14+
case $1 in
15+
"" )
16+
echo "./server-tools.sh {command}"
17+
;;
18+
"logs" )
19+
ssh $SERVER_NAME "cd $SERVER_DIR/infracture && docker-compose logs --tail 1000 -f"
20+
;;
21+
"ssh" )
22+
ssh $SERVER_NAME
23+
;;
24+
"start" )
25+
ssh $SERVER_NAME "cd $SERVER_DIR/infracture && docker-compose start"
26+
;;
27+
"stop" )
28+
ssh $SERVER_NAME "cd $SERVER_DIR/infracture && docker-compose stop"
29+
;;
30+
"restart" )
31+
ssh $SERVER_NAME "cd $SERVER_DIR/infracture && docker-compose restart"
32+
;;
33+
"htop" )
34+
ssh $SERVER_NAME -t "htop -d 10"
35+
;;
36+
"sync" )
37+
EXCLUDE=""
38+
for DIR in ${SYNC_EXCLUDE[@]}
39+
do
40+
EXCLUDE="$EXCLUDE --exclude=$DIR"
41+
done
42+
ssh $SERVER_NAME "mkdir -p $SERVER_DIR && cd $SERVER_DIR"
43+
rsync -avz $EXCLUDE . $SERVER_NAME:$SERVER_DIR
44+
;;
45+
"deploy" )
46+
EXCLUDE=""
47+
for DIR in ${SYNC_EXCLUDE[@]}
48+
do
49+
EXCLUDE="$EXCLUDE --exclude=$DIR"
50+
done
51+
ssh $SERVER_NAME "mkdir -p $SERVER_DIR && cd $SERVER_DIR"
52+
rsync -avz $EXCLUDE . $SERVER_NAME:$SERVER_DIR
53+
ssh $SERVER_NAME "cd $SERVER_DIR/infracture && export \$(cat ../.env) && docker-compose exec php composer install --ignore-platform-reqs"
54+
ssh $SERVER_NAME "cd $SERVER_DIR/infracture && export \$(cat ../.env) && docker-compose exec php php yii modules-migrate --interactive=0"
55+
;;
56+
esac

infracture/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data/

infracture/Makefile

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
include ../.env
2+
export
3+
install:
4+
make install-common-soft
5+
make install-docker
6+
make install-docker-compose
7+
install-common-soft:
8+
apt-get update && apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
9+
install-docker:
10+
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add && \
11+
apt-key fingerprint 0EBFCD88 && \
12+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" && \
13+
apt-get update && \
14+
apt-get install -y docker-ce
15+
install-docker-compose:
16+
curl -L \
17+
https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` \
18+
> /usr/local/bin/docker-compose && \
19+
chmod +x /usr/local/bin/docker-compose && \
20+
docker-compose --version
21+
rebuild:
22+
docker-compose build --force-rm
23+
up:
24+
docker-compose up --remove-orphan
25+
rebuild-and-up:
26+
docker-compose up -d --build --force-recreate
27+
start:
28+
docker-compose up -d
29+
start-mysql:
30+
docker-compose start mysql
31+
rm:
32+
docker-compose rm
33+
stop:
34+
docker-compose stop
35+
down:
36+
docker-compose down --remove-orphan
37+
restart:
38+
docker-compose restart
39+
restart-ngnix:
40+
docker-compose restart ngnix
41+
restart-php:
42+
docker-compose restart php
43+
restart-mysql:
44+
docker-compose restart mysql
45+
rebuild-up:
46+
make rebuild && make up
47+
kill:
48+
docker-compose kill
49+
50+
logs:
51+
docker-compose logs -f
52+
logs-php-queue:
53+
docker-compose logs -f php-queue
54+
55+
# Bash
56+
bash-nginx:
57+
docker-compose exec nginx bash
58+
bash-php:
59+
docker-compose exec php bash
60+
bash-php-web:
61+
docker-compose exec php-web bash
62+
bash-php-queue:
63+
docker-compose exec php-queue bash
64+
bash-mysql:
65+
docker-compose exec mysql bash

infracture/conf/nginx/conf.d/app.conf

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
server {
2+
listen 80 default_server;
3+
server_name app.dev;
4+
5+
root /var/www/app/web;
6+
7+
index index.php index.html index.htm;
8+
9+
location / {
10+
try_files $uri $uri/ /index.php$is_args$args;
11+
}
12+
13+
location ~* ".+\.(?:ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|css|swf|js|atom|jpe?g|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$"
14+
{
15+
access_log off;
16+
log_not_found off;
17+
expires max;
18+
}
19+
20+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
21+
22+
location ~ \.php$ {
23+
fastcgi_pass php:9000;
24+
fastcgi_index index.php;
25+
include fastcgi_params;
26+
fastcgi_intercept_errors on;
27+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
28+
}
29+
30+
# deny access to .htaccess files, if Apache's document root
31+
# concurs with nginx's one
32+
33+
location ~ /\.ht {
34+
deny all;
35+
}
36+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server {
2+
listen 80;
3+
4+
location / {
5+
access_log off;
6+
log_not_found off;
7+
expires max;
8+
return 418;
9+
}
10+
}

infracture/conf/nginx/fastcgi_params

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
fastcgi_param QUERY_STRING $query_string;
3+
fastcgi_param REQUEST_METHOD $request_method;
4+
fastcgi_param CONTENT_TYPE $content_type;
5+
fastcgi_param CONTENT_LENGTH $content_length;
6+
7+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
8+
fastcgi_param REQUEST_URI $request_uri;
9+
fastcgi_param DOCUMENT_URI $document_uri;
10+
fastcgi_param DOCUMENT_ROOT $document_root;
11+
fastcgi_param SERVER_PROTOCOL $server_protocol;
12+
fastcgi_param REQUEST_SCHEME $scheme;
13+
fastcgi_param HTTPS $https if_not_empty;
14+
15+
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
16+
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
17+
18+
fastcgi_param REMOTE_ADDR $remote_addr;
19+
fastcgi_param REMOTE_PORT $remote_port;
20+
fastcgi_param SERVER_ADDR $server_addr;
21+
fastcgi_param SERVER_PORT $server_port;
22+
fastcgi_param SERVER_NAME $server_name;
23+
24+
# PHP only, required if PHP was built with --enable-force-cgi-redirect
25+
fastcgi_param REDIRECT_STATUS 200;

infracture/conf/nginx/koi-utf

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# This map is not a full koi8-r <> utf8 map: it does not contain
2+
# box-drawing and some other characters. Besides this map contains
3+
# several koi8-u and Byelorussian letters which are not in koi8-r.
4+
# If you need a full and standard map, use contrib/unicode2nginx/koi-utf
5+
# map instead.
6+
7+
charset_map koi8-r utf-8 {
8+
9+
80 E282AC ; # euro
10+
11+
95 E280A2 ; # bullet
12+
13+
9A C2A0 ; # &nbsp;
14+
15+
9E C2B7 ; # &middot;
16+
17+
A3 D191 ; # small yo
18+
A4 D194 ; # small Ukrainian ye
19+
20+
A6 D196 ; # small Ukrainian i
21+
A7 D197 ; # small Ukrainian yi
22+
23+
AD D291 ; # small Ukrainian soft g
24+
AE D19E ; # small Byelorussian short u
25+
26+
B0 C2B0 ; # &deg;
27+
28+
B3 D081 ; # capital YO
29+
B4 D084 ; # capital Ukrainian YE
30+
31+
B6 D086 ; # capital Ukrainian I
32+
B7 D087 ; # capital Ukrainian YI
33+
34+
B9 E28496 ; # numero sign
35+
36+
BD D290 ; # capital Ukrainian soft G
37+
BE D18E ; # capital Byelorussian short U
38+
39+
BF C2A9 ; # (C)
40+
41+
C0 D18E ; # small yu
42+
C1 D0B0 ; # small a
43+
C2 D0B1 ; # small b
44+
C3 D186 ; # small ts
45+
C4 D0B4 ; # small d
46+
C5 D0B5 ; # small ye
47+
C6 D184 ; # small f
48+
C7 D0B3 ; # small g
49+
C8 D185 ; # small kh
50+
C9 D0B8 ; # small i
51+
CA D0B9 ; # small j
52+
CB D0BA ; # small k
53+
CC D0BB ; # small l
54+
CD D0BC ; # small m
55+
CE D0BD ; # small n
56+
CF D0BE ; # small o
57+
58+
D0 D0BF ; # small p
59+
D1 D18F ; # small ya
60+
D2 D180 ; # small r
61+
D3 D181 ; # small s
62+
D4 D182 ; # small t
63+
D5 D183 ; # small u
64+
D6 D0B6 ; # small zh
65+
D7 D0B2 ; # small v
66+
D8 D18C ; # small soft sign
67+
D9 D18B ; # small y
68+
DA D0B7 ; # small z
69+
DB D188 ; # small sh
70+
DC D18D ; # small e
71+
DD D189 ; # small shch
72+
DE D187 ; # small ch
73+
DF D18A ; # small hard sign
74+
75+
E0 D0AE ; # capital YU
76+
E1 D090 ; # capital A
77+
E2 D091 ; # capital B
78+
E3 D0A6 ; # capital TS
79+
E4 D094 ; # capital D
80+
E5 D095 ; # capital YE
81+
E6 D0A4 ; # capital F
82+
E7 D093 ; # capital G
83+
E8 D0A5 ; # capital KH
84+
E9 D098 ; # capital I
85+
EA D099 ; # capital J
86+
EB D09A ; # capital K
87+
EC D09B ; # capital L
88+
ED D09C ; # capital M
89+
EE D09D ; # capital N
90+
EF D09E ; # capital O
91+
92+
F0 D09F ; # capital P
93+
F1 D0AF ; # capital YA
94+
F2 D0A0 ; # capital R
95+
F3 D0A1 ; # capital S
96+
F4 D0A2 ; # capital T
97+
F5 D0A3 ; # capital U
98+
F6 D096 ; # capital ZH
99+
F7 D092 ; # capital V
100+
F8 D0AC ; # capital soft sign
101+
F9 D0AB ; # capital Y
102+
FA D097 ; # capital Z
103+
FB D0A8 ; # capital SH
104+
FC D0AD ; # capital E
105+
FD D0A9 ; # capital SHCH
106+
FE D0A7 ; # capital CH
107+
FF D0AA ; # capital hard sign
108+
}

0 commit comments

Comments
 (0)