Skip to content

Commit e2ca94d

Browse files
committed
Merge branch 'release/5.0.2'
2 parents c2a6cd0 + aa8f1ec commit e2ca94d

12 files changed

+110
-51
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ PHP Docker Boilerplate Changelog
22
==================================
33

44
5.1.0 - UPCOMING
5-
----------------
5+
-----------------
6+
7+
5.0.2 - 2016-05-09
8+
------------------
9+
- Added exit if solr entrypoint is failing inside
10+
- Fix solr storage
11+
- Add `make shell` and `make root` (Makefile targets)
12+
- Refactored backup and restore (solr and mysql, see Makefile)
613

714
5.0.0 - 2016-03-07
815
------------------

Makefile

+9-11
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,20 @@ rebuild:
3838
#############################
3939

4040
mysql-backup:
41-
docker-compose run --rm --no-deps app root bash /docker/bin/backup.sh mysql
41+
bash ./bin/backup.sh mysql
4242

4343
mysql-restore:
44-
docker-compose run --rm --no-deps app root bash /docker/bin/restore.sh mysql
44+
bash ./bin/restore.sh mysql
4545

4646
#############################
4747
# Solr
4848
#############################
4949

5050
solr-backup:
51-
docker-compose stop solr
52-
docker-compose run --rm --no-deps app root bash /docker/bin/backup.sh solr
53-
docker-compose start solr
51+
bash ./bin/backup.sh solr
5452

5553
solr-restore:
56-
docker-compose stop solr
57-
docker-compose run --rm --no-deps app root bash /docker/bin/restore.sh solr
58-
docker-compose start solr
54+
bash ./bin/restore.sh solr
5955

6056
#############################
6157
# General
@@ -67,11 +63,13 @@ restore: mysql-restore solr-restore
6763
build:
6864
bash bin/build.sh
6965

70-
bash:
71-
docker-compose run --rm app bash
66+
bash: shell
67+
68+
shell:
69+
docker exec -it -u application $$(docker-compose ps -q app) /bin/bash
7270

7371
root:
74-
docker-compose run --rm app root
72+
docker exec -it -u root $$(docker-compose ps -q app) /bin/bash
7573

7674
#############################
7775
# Argument fix workaround

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dockerized PHP web project boilerplate
22

3-
[![latest v5.0.0](https://img.shields.io/badge/latest-v5.0.0-green.svg?style=flat)](https://github.com/webdevops/php-docker-boilerplate/releases/tag/5.0.0)
3+
[![latest v5.0.2](https://img.shields.io/badge/latest-v5.0.2-green.svg?style=flat)](https://github.com/webdevops/php-docker-boilerplate/releases/tag/5.0.2)
44
![License MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)
55
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/mblaschke/php-docker-boilerplate.svg)](http://isitmaintained.com/project/mblaschke/php-docker-boilerplate "Average time to resolve an issue")
66
[![Percentage of issues still open](http://isitmaintained.com/badge/open/mblaschke/php-docker-boilerplate.svg)](http://isitmaintained.com/project/mblaschke/php-docker-boilerplate "Percentage of issues still open")

bin/.config.sh

+19
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,22 @@ execInDir() {
5252

5353
sh -c "cd \"$1\" && $2"
5454
}
55+
56+
dockerContainerId() {
57+
echo "$(docker-compose ps -q "$1" 2> /dev/null || echo "")"
58+
}
59+
60+
dockerExec() {
61+
docker exec -i "$(docker-compose ps -q app)" $@
62+
}
63+
64+
dockerCopyFrom() {
65+
PATH_DOCKER="$1"
66+
PATH_HOST="$2"
67+
docker cp "$(docker-compose ps -q app):${PATH_DOCKER}" "${PATH_HOST}"
68+
}
69+
dockerCopyTo() {
70+
PATH_HOST="$1"
71+
PATH_DOCKER="$2"
72+
docker cp "${PATH_HOST}" "$(docker-compose ps -q app):${PATH_DOCKER}"
73+
}

bin/backup.sh

+25-14
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,38 @@ case "$1" in
1919
## MySQL
2020
###################################
2121
"mysql")
22-
if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then
23-
logMsg "Removing old backup file..."
24-
rm -f -- "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}"
22+
if [[ -n "$(dockerContainerId mysql)" ]]; then
23+
if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then
24+
logMsg "Removing old backup file..."
25+
rm -f -- "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}"
26+
fi
27+
28+
logMsg "Starting MySQL backup..."
29+
dockerExec mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}"
30+
logMsg "Finished"
31+
else
32+
echo " * Skipping mysql backup, no such container"
2533
fi
26-
27-
logMsg "Starting MySQL backup..."
28-
mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}"
29-
logMsg "Finished"
3034
;;
3135

3236
###################################
3337
## Solr
3438
###################################
3539
"solr")
36-
if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then
37-
logMsg "Removing old backup file..."
38-
rm -f -- "${BACKUP_DIR}/${BACKUP_SOLR_FILE}"
40+
if [[ -n "$(dockerContainerId solr)" ]]; then
41+
logMsg "Starting Solr backup..."
42+
docker-compose stop solr
43+
44+
if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then
45+
logMsg "Removing old backup file..."
46+
rm -f -- "${BACKUP_DIR}/${BACKUP_SOLR_FILE}"
47+
fi
48+
dockerExec tar -cP --to-stdout /storage/solr/ | bzip2 > "${BACKUP_DIR}/${BACKUP_SOLR_FILE}"
49+
50+
docker-compose start solr
51+
logMsg "Finished"
52+
else
53+
echo " * Skipping solr backup, no such container"
3954
fi
40-
41-
logMsg "Starting Solr backup..."
42-
tar jcPf "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" /storage/solr/
43-
logMsg "Finished"
4455
;;
4556
esac

bin/restore.sh

+29-14
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,44 @@ case "$1" in
1919
## MySQL
2020
###################################
2121
"mysql")
22-
if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then
23-
logMsg "Starting MySQL restore..."
24-
bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | mysql
25-
logMsg "Finished"
22+
if [[ -n "$(dockerContainerId mysql)" ]]; then
23+
if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then
24+
logMsg "Starting MySQL restore..."
25+
bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | dockerExec mysql
26+
echo "FLUSH PRIVILEGES;" | dockerExec mysql
27+
logMsg "Finished"
28+
else
29+
errorMsg "MySQL backup file not found"
30+
exit 1
31+
fi
2632
else
27-
errorMsg "MySQL backup file not found"
28-
exit 1
33+
echo " * Skipping mysql restore, no such container"
2934
fi
3035
;;
3136

3237
###################################
3338
## Solr
3439
###################################
3540
"solr")
36-
if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then
37-
logMsg "Starting Solr restore..."
38-
rm -rf /storage/solr/* && mkdir -p /storage/solr/
39-
chmod 777 /storage/solr/
40-
tar jxPf "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" -C /
41-
logMsg "Finished"
41+
if [[ -n "$(dockerContainerId solr)" ]]; then
42+
if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then
43+
logMsg "Starting Solr restore..."
44+
docker-compose stop solr
45+
46+
dockerExec rm -rf /storage/solr/
47+
dockerExec mkdir -p /storage/solr/
48+
dockerExec chmod 777 /storage/solr/
49+
dockerCopyTo "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" "/tmp/solr-restore.tbz2"
50+
dockerExec tar -jxPf "/tmp/solr-restore.tbz2" -C /
51+
52+
docker-compose start solr
53+
logMsg "Finished"
54+
else
55+
errorMsg "Solr backup file not found"
56+
exit 1
57+
fi
4258
else
43-
errorMsg "Solr backup file not found"
44-
exit 1
59+
echo " * Skipping solr restore, no such container"
4560
fi
4661
;;
4762
esac

docker-compose.cloud.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,4 @@ mysql:
133133
storage:
134134
build: docker/storage/
135135
volumes:
136-
- /data
136+
- /storage

docker-compose.development.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ mysql:
147147
storage:
148148
build: docker/storage/
149149
volumes:
150-
- /data
150+
- /storage

docker-compose.production.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ mysql:
139139
storage:
140140
build: docker/storage/
141141
volumes:
142-
- /data
142+
- /storage

docker/solr/Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ COPY ./conf/ /opt/solr-conf/
2020
RUN curl -sf -o /tmp/solr-typo3-plugin.jar -L http://www.typo3-solr.com/fileadmin/files/solr/solr-typo3-plugin-1.3.0.jar
2121

2222
# Init directories
23-
RUN cp -a /opt/solr-conf/* /opt/solr/example/solr/
24-
RUN mkdir -p /opt/solr/example/solr/typo3cores/data
25-
RUN mkdir -p /opt/solr/example/solr/typo3lib
23+
RUN cp -a /opt/solr-conf/* /opt/solr/example/solr/ \
24+
&& mkdir -p /opt/solr/example/solr/typo3cores/data \
25+
&& mkdir -p /opt/solr/example/solr/typo3lib
2626

2727
# Add plugins
28-
RUN mv /tmp/solr-typo3-plugin.jar /opt/solr/example/solr/typo3lib/
29-
RUN ln -s /opt/solr/contrib /opt/solr/example/solr/contrib
28+
RUN mv /tmp/solr-typo3-plugin.jar /opt/solr/example/solr/typo3lib/ \
29+
&& ln -s /opt/solr/contrib /opt/solr/example/solr/contrib
3030

3131
# Fix rights
3232
RUN chown solr:solr -R /opt/solr/example/solr/

docker/solr/entrypoint.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
set -o pipefail # trace ERR through pipes
4+
set -o errtrace # trace ERR through 'time command' and other functions
5+
set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
6+
set -o errexit ## set -e : exit the script if any statement returns a non-true return value
37

48
###################
59
# Move storage to storage container
@@ -27,4 +31,4 @@ if [ "$1" = 'solr' ]; then
2731
exec java -jar start.jar
2832
fi
2933

30-
exec "$@"
34+
exec "$@"

docker/storage/Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
# Storage Docker container
33
#++++++++++++++++++++++++++++++++++++++
44

5-
FROM webdevops/storage
5+
FROM busybox
6+
7+
RUN mkdir /storage \
8+
&& chmod 1777 /storage
9+
10+
VOLUME "/storage"

0 commit comments

Comments
 (0)