Skip to content

Commit 679b487

Browse files
committed
added envsubst command
1 parent bce0146 commit 679b487

File tree

6 files changed

+398
-37
lines changed

6 files changed

+398
-37
lines changed

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If You want to build a website with CakePHP "basic" at short time;
44

55
#### Full stack Nginx CakePHP "basic":
66
<p align="left"> <a href="https://www.cakephp.com/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/23666?s=200&v=4" alt="cakephp" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.docker.com/" target="_blank" rel="noreferrer"> <img src="https://raw.githubusercontent.com/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/docker/docker.png" alt="docker" width="40" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://mariadb.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/5877084?s=200&v=4" alt="mariadb" height="50" width="50"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.nginx.com" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1412239?s=200&v=4" alt="nginx" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.php.net" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/25158?s=200&v=4" alt="php" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://redis.io" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1529926?s=200&v=4" alt="redis" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="#" target="_blank" rel="noreferrer"> <img src="https://raw.githubusercontent.com/github/explore/80688e429a7d4ef2fca1e82350fe8e3517d3494d/topics/bash/bash.png" alt="Bash" height="50" width="50" /> </a>&nbsp;&nbsp;&nbsp;
7-
<a href="https://www.phpmyadmin.net/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1351977?s=200&v=4" alt="phpmyadmin" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://letsencrypt.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/17889013?s=200&v=4" alt="letsencrypt" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.portainer.io/?hsLang=en" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/22225832?s=200&v=4" alt="portainer" height="40" width="40"/> </a> </p>
7+
<a href="https://www.phpmyadmin.net/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/1351977?s=200&v=4" alt="phpmyadmin" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://letsencrypt.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/17889013?s=200&v=4" alt="letsencrypt" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.portainer.io/?hsLang=en" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/22225832?s=200&v=4" alt="portainer" height="40" width="40"/> </a>&nbsp;&nbsp;&nbsp; <a href="https://www.offen.dev/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/47735043?s=200&v=4" alt="backup" height="35" width="35"/> </a> </p>
88

99
Plus, manage docker containers with Portainer.
1010

@@ -16,7 +16,7 @@ Plus, manage docker containers with Portainer.
1616
- [phpMyAdmin](https://hub.docker.com/r/phpmyadmin/phpmyadmin/)
1717
- [database](https://hub.docker.com/_/mariadb)
1818
- [redis](https://hub.docker.com/_/redis)
19-
- [backup](https://hub.docker.com/r/futurice/docker-volume-backup)
19+
- [backup](https://hub.docker.com/r/offen/docker-volume-backup)
2020

2121
#### For certbot (letsencrypt) certificate:
2222

@@ -257,20 +257,8 @@ The first authorize screen(htpasswd;username or password) and phpmyadmin login s
257257

258258
### backup
259259

260-
This will back up the all files and folders, once per day, and write it to ./backups with a filename like backup-2022-02-07T16-51-56.tar.gz
260+
This will back up the all files and folders in database/dump sql and html volumes, once per day, and write it to ./backups with a filename like backup-2023-01-01T10-18-00.tar.gz
261261

262-
#### example for crontab file on the host machine
262+
#### can run on a custom cron schedule
263263

264-
##### # old docker backup folder remove
265-
266-
```
267-
50 23 * * * find ${DIRECTORY_PATH}/backups/backup* -type f -mtime +1 | xargs rm
268-
```
269-
270-
##### # backup exclude cakephp, backups folders in ${DIRECTORY_PATH}
271-
272-
```
273-
00 01 * * * tar -czvf ${DIRECTORY_PATH}/backups/'backup-example.com-'$(date +"\%Y-\%m-\%dT\%H-\%M-\%S")'.tar.gz' --exclude='cakephp/app' --exclude='backups' ${DIRECTORY_PATH}
274-
```
275-
276-
[CronHowto](https://help.ubuntu.com/community/CronHowto)
264+
```BACKUP_CRON_EXPRESSION: '20 01 * * *'``` the UTC timezone.

cakephp/html/app_local.php renamed to cakephp/html/app_local.php.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* You should treat it as extremely sensitive data.
2626
*/
2727
'Security' => [
28-
'salt' => env('SECURITY_SALT', '__SALT__'),
28+
'salt' => env('SECURITY_SALT', '$RANDOM_VALUE'),
2929
],
3030

3131
/*
@@ -61,10 +61,10 @@
6161
*/
6262
//'port' => 'non_standard_port_number',
6363

64-
'username' => 'DB_USER',
65-
'password' => 'DB_PASSWORD',
64+
'username' => '${DB_USER}',
65+
'password' => '${DB_PASSWORD}',
6666

67-
'database' => 'DB_NAME',
67+
'database' => '${DB_NAME}',
6868
/*
6969
* If not using the default 'public' schema with the PostgreSQL driver
7070
* set it here.

docker-compose.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ services:
3232
retries: 6
3333
start_period: 60s
3434
environment:
35+
DB_USER: '${DB_USER}'
36+
DB_PASSWORD: '${DB_PASSWORD}'
37+
DB_NAME: '${DB_NAME}'
3538
TZ: '${LOCAL_TIMEZONE}'
3639
labels:
3740
- 'docker-volume-backup.stop-during-backup=true'
3841
command: >
39-
bash -c "apt-get -y update && apt-get install -y zip unzip libicu-dev && docker-php-ext-install pdo_mysql intl && if pecl install -p -- redis; then pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis; fi; curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
40-
&& if [ -f \"/app/basic/config/app_local.php\" ]; then composer update --prefer-dist cakephp/cakephp:~4.0 --working-dir=/app/basic --no-interaction --ignore-platform-req=ext-intl; else composer create-project --prefer-dist cakephp/app:~4.0 basic --working-dir=/app --no-interaction --ignore-platform-req=ext-intl; fi
41-
&& sed \"s/DB_USER/${DB_USER}/;s/DB_PASSWORD/${DB_PASSWORD}/;s/DB_NAME/${DB_NAME}/;s/__SALT__/$$(tr -dc '[:alnum:]' </dev/urandom | head -c 32)/\" ${WEBSERVER_DOC_ROOT}/app_local.php > /app/basic/config/app_local.php;
42+
bash -c "apt-get -y update && apt-get install -y zip unzip libicu-dev gettext-base && docker-php-ext-install pdo_mysql intl && if pecl install -p -- redis; then pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis; fi; curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer &&
43+
if [ -f \"/app/basic/config/app_local.php\" ]; then composer update --prefer-dist cakephp/cakephp:~4.0 --working-dir=/app/basic --no-interaction --ignore-platform-req=ext-intl; else composer create-project --prefer-dist cakephp/app:~4.0 basic --working-dir=/app --no-interaction --ignore-platform-req=ext-intl; fi &&
44+
export RANDOM_VALUE=$(tr -dc '[:alnum:]' </dev/urandom | head -c 32) && envsubst '$${DB_USER},$${DB_PASSWORD},$${DB_NAME},$$RANDOM_VALUE' < ${WEBSERVER_DOC_ROOT}/app_local.php.template > /app/basic/config/app_local.php &&
4245
grep -qe 'date.timezone = ${LOCAL_TIMEZONE}' ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini || echo 'date.timezone = ${LOCAL_TIMEZONE}' >> ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini; php-fpm"
4346
4447
webserver:
@@ -104,6 +107,7 @@ services:
104107
- backend
105108
- frontend
106109
volumes:
110+
- 'phpmyadmin:${WEBSERVER_DOC_ROOT}/sql'
107111
- type: bind
108112
source: ./phpmyadmin/apache2/sites-available/default-ssl.conf
109113
target: '${APACHE_CONFDIR_PREFIX}/sites-available/default-ssl.conf'
@@ -124,10 +128,10 @@ services:
124128
restart: unless-stopped
125129
ports:
126130
- '9090:443'
127-
#links:
128-
# - database
131+
links:
132+
- database
129133
environment:
130-
#PMA_HOST: database
134+
PMA_HOST: 'database'
131135
PMA_PMADB: 'phpmyadmin'
132136
PMA_CONTROLUSER: '${PMA_CONTROLUSER}'
133137
PMA_CONTROLPASS: '${PMA_CONTROLPASS}'
@@ -136,7 +140,7 @@ services:
136140
MEMORY_LIMIT: '${PMA_MEMORY_LIMIT}'
137141
TZ: '${LOCAL_TIMEZONE}'
138142
command: >
139-
bash -c "echo ${PMA_HTPASSWD_USERNAME}:phpmyadmin:$$( printf \"%s:%s:%s\" \"${PMA_HTPASSWD_USERNAME}\" \"phpmyadmin\" \"${PMA_HTPASSWD_PASSWORD}\" | md5sum | awk '{print $$1}' ) > ${PMA_CONF_FOLDER}/.htpasswd
143+
bash -c "apt-get -y update && apt-get install -y gettext-base && envsubst < ${WEBSERVER_DOC_ROOT}/sql/create_tables.sql.template > ${WEBSERVER_DOC_ROOT}/sql/create_tables.sql && echo ${PMA_HTPASSWD_USERNAME}:phpmyadmin:$$( printf \"%s:%s:%s\" \"${PMA_HTPASSWD_USERNAME}\" \"phpmyadmin\" \"${PMA_HTPASSWD_PASSWORD}\" | md5sum | awk '{print $$1}' ) > ${PMA_CONF_FOLDER}/.htpasswd
140144
&& printf 'AuthType Digest\\nAuthName \"phpmyadmin\"\\nAuthDigestProvider file\\nAuthUserFile ${PMA_CONF_FOLDER}/.htpasswd\\nRequire valid-user\\n' > ${WEBSERVER_DOC_ROOT}/.htaccess && a2enmod auth_digest;
141145
mkdir -p ${WEBSERVER_DOC_ROOT}/../upload && chown www-data:www-data ${WEBSERVER_DOC_ROOT}/../upload && chmod a+w ${WEBSERVER_DOC_ROOT}/../upload; mkdir -p ${WEBSERVER_DOC_ROOT}/../save && chown www-data:www-data ${WEBSERVER_DOC_ROOT}/../save && chmod a+w ${WEBSERVER_DOC_ROOT}/../save;
142146
grep -qxF 'ServerName 127.0.0.1' ${APACHE_CONFDIR_PREFIX}/apache2.conf || echo -e '\\nServerName 127.0.0.1' >> ${APACHE_CONFDIR_PREFIX}/apache2.conf; grep -qe 'date.timezone = ${LOCAL_TIMEZONE}' ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini || echo 'date.timezone = ${LOCAL_TIMEZONE}' >> ${PHP_INI_DIR_PREFIX}/php/conf.d/security.ini;
@@ -149,9 +153,11 @@ services:
149153
- backend
150154
volumes:
151155
- 'db:/var/lib/mysql'
156+
- 'db-backup-data:/tmp/backup'
152157
- type: bind
153158
source: ./database/conf.d/z-mysql.cnf
154159
target: '${MYSQL_CONF_PREFIX}/z-mysql.cnf'
160+
- 'phpmyadmin:/docker-entrypoint-initdb.d'
155161
hostname: database
156162
restart: unless-stopped
157163
ports:
@@ -166,6 +172,8 @@ services:
166172
TZ: '${LOCAL_TIMEZONE}'
167173
labels:
168174
- "docker-volume-backup.stop-during-backup=true"
175+
- "docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump -uroot -p${MYSQL_ROOT_PASSWORD} --all-databases > /tmp/backup/db_backup_data.sql'"
176+
- "docker-volume-backup.exec-label=database"
169177
command: "--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password"
170178

171179
redis:
@@ -190,24 +198,26 @@ services:
190198
command: "redis-server ${REDIS_CONF_PREFIX}/redis/redis.conf"
191199

192200
backup:
193-
image: 'futurice/docker-volume-backup'
201+
image: offen/docker-volume-backup:latest
194202
container_name: backup
195203
networks:
196204
- backend
197205
volumes:
198-
- '/var/run/docker.sock:/var/run/docker.sock:ro'
199206
- 'html:/backup/html:ro'
200207
- 'db:/backup/db:ro'
208+
- 'db-backup-data:/backup/db-backup-data:ro'
209+
- '/var/run/docker.sock:/var/run/docker.sock:ro'
201210
- type: bind
202211
source: ./backups
203212
target: /archive
204213
hostname: backup
205214
restart: unless-stopped
206215
environment:
207-
BACKUP_WAIT_SECONDS: 120
208216
BACKUP_CRON_EXPRESSION: '20 01 * * *'
209217
BACKUP_FILENAME: 'backup-%Y-%m-%dT%H-%M-%S.tar.gz'
210-
TZ: '${LOCAL_TIMEZONE}'
218+
BACKUP_RETENTION_DAYS: '7'
219+
EXEC_LABEL: 'database'
220+
#BACKUP_EXCLUDE_REGEXP: 'folder|folder|file|\\.log$$'
211221

212222
networks:
213223
backend: null
@@ -230,6 +240,15 @@ volumes:
230240
o: bind
231241
db:
232242
name: ${DATABASE_CONT_NAME}-data
243+
db-backup-data:
244+
name: ${DATABASE_CONT_NAME}-backup-data
245+
phpmyadmin:
246+
name: phpmyadmin-sql
247+
driver: local
248+
driver_opts:
249+
type: none
250+
device: ${DIRECTORY_PATH}/phpmyadmin/sql
251+
o: bind
233252
dtredis:
234253
name: redis-data
235254
certbot-etc:

phpmyadmin/config.user.inc.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99

1010
$cfg['CheckConfigurationPermissions'] = false;
1111
$cfg['ShowPhpInfo'] = true;
12-
$cfg['Servers'][1]['host'] = 'database';

0 commit comments

Comments
 (0)