Skip to content

Commit e36ceff

Browse files
committed
Merge branch 'develop'
2 parents d53df71 + c1fe25a commit e36ceff

22 files changed

+271
-219
lines changed

Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ pma-up:
7070
pma-down:
7171
docker-compose -f docker-compose.phpmyadmin.yml down -v
7272

73-
# Init backups cron
74-
.PHONY: backup-init
75-
backup-init:
76-
sudo bash sh/backup/backup-init.sh
77-
7873
# Full docker cleanup
7974
.PHONY: docker-clean
8075
docker-clean:

README.MD

+6-11
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ It will up special file `docker-compose.prod.yml` with 80 and your port (most li
186186
- `make pause` - `docker-compose pause`
187187
- `make pma-up`
188188
- `make pma-down`
189-
- `make backup-init`
190189

191190
## Structure
192191
wp-content - docker mounted WordPress wp-content folder, it's your working directory. Add plugins and custom theme here.
@@ -198,7 +197,8 @@ db-data/ # Database docker mounted volume
198197
docker/ # Docker images (Dockerfiles) and additional scripts
199198
logs/ # System and wordpress logs
200199
sh/ # Bash scripts
201-
└── backup/ # Backup scripts (crontab, backup-init, start-backup)
200+
├── env/ # Operations with environment files
201+
└── utils/ # Additional bash utils
202202
wp-content/ # Docker mounted volume, WordPress wp-content folder
203203
├── mu-plugins/ # Must use plugins
204204
├── plugins/ # Plugins folder. Add your plugins here
@@ -268,18 +268,13 @@ The system has automatic backups. Launched by a cronjob. By default, daily and w
268268

269269
To activate backups:
270270

271-
1. Edit `./config/environment/.env.type.[environment_type]` file - enable `APP_WP_BACKUP_ENABLE` and check `APP_HOST_SYSTEM_CRON_DIR`
271+
1. Edit `./config/environment/.env.type.[environment_type]` file - enable `APP_WP_BACKUP_ENABLE`
272272

273273

274-
2. Check `./sh/backup/backup-crontab.template` - change cronjob time if it needs.
274+
2. Check crontab file in `./config/crontabs` - change cronjob time if it needs.
275275

276276

277-
3. Run backups init script<sup>[2](#footnote_backup)</sup>:
277+
3. If you have more than one database (maybe custom databases), check `mysqldump` command parameters in `./docker/cron/start-backup.sh`
278278

279-
```bash
280-
make backup-init
281-
```
282-
283-
Backups will appear in the `./backups` folder, logs in `./logs/cron/backup.log`
279+
Backups will appear in the `./backups` folder, logs in docker cron container logs
284280

285-
<a name="footnote_backup"></a>[2] Need sudo access

config/crontabs/root

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is crontab file. Here you can customize your cron-jobs.
2+
# Changes will apply after file save. Container restart not need
3+
#
4+
5+
# * * * * * - time options, see more https://crontab.guru/
6+
# flock - lock files are used to determine if a script or application is already running
7+
# >> - append, > renew log file
8+
# >> /var/log/cron.log 2>&1 - send output to log
9+
# > /dev/null 2>&1 - send output to black hole
10+
# 2>&1 redirects the output include both the Standard Error and Standard Out. Look details https://tldp.org/LDP/abs/html/io-redirection.html
11+
12+
# Example
13+
# * * * * * [flock -n <path-to-lck-file>] <some-command> >> <path-to-log-file> 2>&1
14+
# * * * * * [flock -n <path-to-lck-file>] <some-command> > /dev/null 2>&1
15+
16+
17+
18+
# Let's run!
19+
20+
# WordPress cron run by system cron
21+
*/10 * * * * docker exec ${APP_NAME}_wordpress flock -n /var/log/wordpress/wp-cron.lck php /var/www/html/wp-cron.php >> /var/log/cron.log 2>&1
22+
23+
24+
# Backup database and media
25+
15 3 * * * start-backup.sh daily >> /var/log/cron.log 2>&1
26+
15 4 * * 1 start-backup.sh weekly >> /var/log/cron.log 2>&1
27+
28+
# An empty line is required at the end of this file for a valid cron file

config/crontabs/www-data

-27
This file was deleted.

config/environment/.env.main

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
# App info
27-
APP_NAME=YourAppName
27+
APP_NAME=your_app_name
2828
APP_TYPE=wordpress
2929

3030

config/environment/.env.type.dev

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ WP_REDIS_MAXTTL=1
4040

4141

4242
# Backup database and media files cron job
43-
# Edit ./sh/backup/backup-crontab.template file to setup backup time. Changes will apply after backup init
43+
# Edit file in ./config/crontabs folder to setup backup time
4444
APP_WP_BACKUP_ENABLE=0
45-
# Change destination folder to your host crontab directory if it is different
46-
APP_HOST_SYSTEM_CRON_DIR=/etc/cron.d
4745

4846

4947
# wp-login.php Basic Auth protection

config/environment/.env.type.prod

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ WP_REDIS_MAXTTL=3600
4040

4141

4242
# Backup database and media files cron job
43-
# Edit ./sh/backup/backup-crontab.template file to setup backup time. Changes will apply after backup init
43+
# Edit file in ./config/crontabs folder to setup backup time
4444
APP_WP_BACKUP_ENABLE=1
45-
# Change destination folder to your host crontab directory if it is different
46-
APP_HOST_SYSTEM_CRON_DIR=/etc/cron.d
4745

4846

4947
# wp-login.php Basic Auth protection

config/environment/.env.type.stage

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ WP_REDIS_MAXTTL=3600
4040

4141

4242
# Backup database and media files cron job
43-
# Edit ./sh/backup/backup-crontab.template file to setup backup time. Changes will apply after backup init
43+
# Edit file in ./config/crontabs folder to setup backup time
4444
APP_WP_BACKUP_ENABLE=1
45-
# Change destination folder to your host crontab directory if it is different
46-
APP_HOST_SYSTEM_CRON_DIR=/etc/cron.d
4745

4846

4947
# wp-login.php Basic Auth protection

config/nginx/templates/partials/basic_auth_enable.conf.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Edit .template file to change settings
33

44
location ^~ /wp-login.php {
5-
auth_basic "Restricted Area: Look password in .env.secret";
5+
auth_basic "Restricted Area";
66
auth_basic_user_file /etc/nginx/auth/.wplogin;
77

88
include /etc/nginx/conf.d/partials/php.conf;

config/nginx/templates/partials/http.conf.template

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33

44
# Special config for HTTP
55

6+
# http://www > http://non-www redirect
7+
server {
8+
listen ${APP_PORT};
9+
listen [::]:${APP_PORT};
10+
server_name www.${APP_DOMAIN};
11+
12+
include /etc/nginx/conf.d/partials/logs.conf;
13+
14+
return 301 $scheme://${APP_DOMAIN}$request_uri;
15+
}
16+
617
server {
718
listen ${APP_PORT};
819
listen [::]:${APP_PORT};
9-
index index.php;
1020
server_name ${APP_DOMAIN};
1121

22+
root /var/www/html;
23+
index index.php;
24+
1225
include /etc/nginx/conf.d/partials/logs.conf;
1326

1427
# Check and include Basic Auth config (15-setup-basic-auth.sh)

config/nginx/templates/partials/https.conf.template

+25-11
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,41 @@
33

44
# Special config for HTTPS
55

6+
# http > https redirect. 80 port should be open
7+
# http://www > https://non-www redirect
68
server {
79
listen 80;
810
listen [::]:80;
9-
server_name ${APP_DOMAIN};
10-
return 301 https://${APP_DOMAIN};
11+
server_name ${APP_DOMAIN} www.${APP_DOMAIN};
12+
13+
include /etc/nginx/conf.d/partials/logs.conf;
14+
15+
return 301 https://${APP_DOMAIN}$request_uri;
1116
}
1217

18+
# https://www > https://non-www redirect
19+
server {
20+
listen ${APP_PORT} ssl http2;
21+
listen [::]:${APP_PORT} ssl http2;
22+
server_name www.${APP_DOMAIN};
23+
24+
include /etc/nginx/conf.d/partials/ssl.conf;
25+
26+
include /etc/nginx/conf.d/partials/logs.conf;
27+
28+
return 301 https://${APP_DOMAIN}$request_uri;
29+
}
30+
31+
# Main directive
1332
server {
1433
listen ${APP_PORT} ssl http2;
1534
listen [::]:${APP_PORT} ssl http2;
16-
index index.php;
1735
server_name ${APP_DOMAIN};
1836

19-
ssl_certificate /etc/nginx/ssl/${APP_DOMAIN}.crt;
20-
ssl_certificate_key /etc/nginx/ssl/${APP_DOMAIN}.key;
21-
ssl_protocols TLSv1.2 TLSv1.3;
37+
root /var/www/html;
38+
index index.php;
2239

23-
# Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
24-
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
25-
ssl_prefer_server_ciphers on;
26-
ssl_session_cache shared:SSL:10m;
40+
include /etc/nginx/conf.d/partials/ssl.conf;
2741

2842
include /etc/nginx/conf.d/partials/logs.conf;
2943

@@ -36,4 +50,4 @@ server {
3650

3751
include /etc/nginx/conf.d/partials/static.conf;
3852

39-
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Do not edit .conf file, it will override by script.
22
# Edit .template file to change settings
33

4-
root /var/www/html;
5-
64
error_log /var/log/nginx/error.log;
75
#access_log /var/log/nginx/access.log;
86
access_log off;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Do not edit .conf file, it will override by script.
2+
# Edit .template file to change settings
3+
4+
ssl_certificate /etc/nginx/ssl/${APP_DOMAIN}.crt;
5+
ssl_certificate_key /etc/nginx/ssl/${APP_DOMAIN}.key;
6+
7+
ssl_protocols TLSv1.2 TLSv1.3;
8+
9+
# Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
10+
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
11+
ssl_prefer_server_ciphers on;
12+
ssl_session_cache shared:SSL:10m;

docker-compose.yml

+14-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55

66
database:
77
image: mariadb:10.5
8+
container_name: "${APP_NAME}_database"
89
restart: unless-stopped
910
env_file: .env
1011
# Open port only for the host. Need for SSH tunnel to connect to database from SQL Manager like HeidiSQL
@@ -16,9 +17,8 @@ services:
1617

1718
wordpress:
1819
build: ./docker/wordpress
20+
container_name: "${APP_NAME}_wordpress"
1921
restart: unless-stopped
20-
links:
21-
- database
2222
depends_on:
2323
- database
2424
env_file: .env
@@ -28,15 +28,11 @@ services:
2828
- ./wp-content:/var/www/html/wp-content # all needed wp-content folders, uploads should be in .gitignore
2929
# Debug log
3030
- ./logs/wordpress:/var/log/wordpress
31-
# Cron
32-
- ./config/crontabs:/etc/crontabs
33-
- ./logs/cron:/var/log/cron
3431

3532
nginx:
3633
build: ./docker/nginx
34+
container_name: "${APP_NAME}_nginx"
3735
restart: unless-stopped
38-
links:
39-
- wordpress
4036
depends_on:
4137
- database
4238
- wordpress
@@ -51,7 +47,18 @@ services:
5147

5248
redis:
5349
image: redis:6.2-alpine
50+
container_name: "${APP_NAME}_redis"
51+
restart: unless-stopped
52+
53+
cron:
54+
build: ./docker/cron
55+
container_name: "${APP_NAME}_cron"
5456
restart: unless-stopped
57+
env_file: .env
58+
volumes:
59+
- /var/run/docker.sock:/var/run/docker.sock:ro
60+
- ./config/crontabs:/etc/crontabs
61+
- ./backups:/srv/wordpress/backups
5562

5663
#volumes:
5764
#wordpress_core:

docker/cron/Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Based on https://habr.com/ru/company/redmadrobot/blog/305364/
2+
# https://github.com/renskiy/cron-docker-image
3+
# Thanks to renskiy
4+
5+
FROM alpine:3.14
6+
7+
RUN set -ex \
8+
# Install bash
9+
&& apk add --no-cache \
10+
bash \
11+
# Install docker-cli only. We need just run `docker exec` command, we do not need 'Docker-in-Docker'
12+
# https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/
13+
docker-cli \
14+
# Add GNU tar
15+
tar \
16+
# WordPress backups dir
17+
&& mkdir -p /srv/wordpress/backups \
18+
# Cron log dir (ToDo 101 Systematize logs in one place.)
19+
&& mkdir -p /var/log/cron \
20+
# making logging pipe
21+
&& mkfifo -m 0666 /var/log/cron.log \
22+
&& ln -s /var/log/cron.log /var/log/crond.log
23+
24+
COPY start-cron.sh /usr/local/bin
25+
RUN chmod +x /usr/local/bin/start-cron.sh
26+
27+
COPY start-backup.sh /usr/local/bin
28+
RUN chmod +x /usr/local/bin/start-backup.sh
29+
30+
CMD ["start-cron.sh"]

0 commit comments

Comments
 (0)