Skip to content

Commit f4e0049

Browse files
committed
added envsubst command
1 parent d3e19ba commit f4e0049

File tree

5 files changed

+398
-33
lines changed

5 files changed

+398
-33
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 Apache2 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.apache.org/" target="_blank" rel="noreferrer"> <img src="https://avatars.githubusercontent.com/u/47359?s=200&v=4" alt="apache2" 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.
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:
@@ -99,6 +102,7 @@ services:
99102
- backend
100103
- frontend
101104
volumes:
105+
- 'phpmyadmin:${WEBSERVER_DOC_ROOT}/sql'
102106
- type: bind
103107
source: ./phpmyadmin/apache2/sites-available/default-ssl.conf
104108
target: '${APACHE_CONFDIR_PREFIX}/sites-available/default-ssl.conf'
@@ -119,10 +123,10 @@ services:
119123
restart: unless-stopped
120124
ports:
121125
- '9090:443'
122-
#links:
123-
# - database
126+
links:
127+
- database
124128
environment:
125-
#PMA_HOST: database
129+
PMA_HOST: 'database'
126130
PMA_PMADB: 'phpmyadmin'
127131
PMA_CONTROLUSER: '${PMA_CONTROLUSER}'
128132
PMA_CONTROLPASS: '${PMA_CONTROLPASS}'
@@ -131,7 +135,7 @@ services:
131135
MEMORY_LIMIT: '${PMA_MEMORY_LIMIT}'
132136
TZ: '${LOCAL_TIMEZONE}'
133137
command: >
134-
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
138+
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
135139
&& printf 'AuthType Digest\\nAuthName \"phpmyadmin\"\\nAuthDigestProvider file\\nAuthUserFile ${PMA_CONF_FOLDER}/.htpasswd\\nRequire valid-user\\n' > ${WEBSERVER_DOC_ROOT}/.htaccess && a2enmod auth_digest;
136140
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;
137141
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;
@@ -144,9 +148,11 @@ services:
144148
- backend
145149
volumes:
146150
- 'db:/var/lib/mysql'
151+
- 'db-backup-data:/tmp/backup'
147152
- type: bind
148153
source: ./database/conf.d/z-mysql.cnf
149154
target: '${MYSQL_CONF_PREFIX}/z-mysql.cnf'
155+
- 'phpmyadmin:/docker-entrypoint-initdb.d'
150156
hostname: database
151157
restart: unless-stopped
152158
ports:
@@ -161,6 +167,8 @@ services:
161167
TZ: '${LOCAL_TIMEZONE}'
162168
labels:
163169
- "docker-volume-backup.stop-during-backup=true"
170+
- "docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump -uroot -p${MYSQL_ROOT_PASSWORD} --all-databases > /tmp/backup/db_backup_data.sql'"
171+
- "docker-volume-backup.exec-label=database"
164172
command: "--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password"
165173

166174
redis:
@@ -185,24 +193,26 @@ services:
185193
command: "redis-server ${REDIS_CONF_PREFIX}/redis/redis.conf"
186194

187195
backup:
188-
image: 'futurice/docker-volume-backup'
196+
image: offen/docker-volume-backup:latest
189197
container_name: backup
190198
networks:
191199
- backend
192200
volumes:
193-
- '/var/run/docker.sock:/var/run/docker.sock:ro'
194201
- 'html:/backup/html:ro'
195202
- 'db:/backup/db:ro'
203+
- 'db-backup-data:/backup/db-backup-data:ro'
204+
- '/var/run/docker.sock:/var/run/docker.sock:ro'
196205
- type: bind
197206
source: ./backups
198207
target: /archive
199208
hostname: backup
200209
restart: unless-stopped
201210
environment:
202-
BACKUP_WAIT_SECONDS: 120
203211
BACKUP_CRON_EXPRESSION: '20 01 * * *'
204212
BACKUP_FILENAME: 'backup-%Y-%m-%dT%H-%M-%S.tar.gz'
205-
TZ: '${LOCAL_TIMEZONE}'
213+
BACKUP_RETENTION_DAYS: '7'
214+
EXEC_LABEL: 'database'
215+
#BACKUP_EXCLUDE_REGEXP: 'folder|folder|file|\\.log$$'
206216

207217
networks:
208218
backend: null
@@ -225,6 +235,15 @@ volumes:
225235
o: bind
226236
db:
227237
name: ${DATABASE_CONT_NAME}-data
238+
db-backup-data:
239+
name: ${DATABASE_CONT_NAME}-backup-data
240+
phpmyadmin:
241+
name: phpmyadmin-sql
242+
driver: local
243+
driver_opts:
244+
type: none
245+
device: ${DIRECTORY_PATH}/phpmyadmin/sql
246+
o: bind
228247
dtredis:
229248
name: redis-data
230249
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)