From 52635d6e1dcda70be5d794a37e95255c9866801c Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Fri, 18 Mar 2016 18:37:00 +0100 Subject: [PATCH 01/10] Fix solr/storage support --- docker-compose.cloud.yml | 2 +- docker-compose.development.yml | 2 +- docker-compose.production.yml | 2 +- docker/solr/Dockerfile | 10 +++++----- docker/storage/Dockerfile | 7 ++++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docker-compose.cloud.yml b/docker-compose.cloud.yml index dd05fb1..ea71f45 100644 --- a/docker-compose.cloud.yml +++ b/docker-compose.cloud.yml @@ -133,4 +133,4 @@ mysql: storage: build: docker/storage/ volumes: - - /data + - /storage diff --git a/docker-compose.development.yml b/docker-compose.development.yml index 8fc0258..6c01368 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -147,4 +147,4 @@ mysql: storage: build: docker/storage/ volumes: - - /data + - /storage diff --git a/docker-compose.production.yml b/docker-compose.production.yml index abd229f..89398a7 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -139,4 +139,4 @@ mysql: storage: build: docker/storage/ volumes: - - /data + - /storage diff --git a/docker/solr/Dockerfile b/docker/solr/Dockerfile index 516dd5c..5c399e3 100644 --- a/docker/solr/Dockerfile +++ b/docker/solr/Dockerfile @@ -20,13 +20,13 @@ COPY ./conf/ /opt/solr-conf/ 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 # Init directories -RUN cp -a /opt/solr-conf/* /opt/solr/example/solr/ -RUN mkdir -p /opt/solr/example/solr/typo3cores/data -RUN mkdir -p /opt/solr/example/solr/typo3lib +RUN cp -a /opt/solr-conf/* /opt/solr/example/solr/ \ + && mkdir -p /opt/solr/example/solr/typo3cores/data \ + && mkdir -p /opt/solr/example/solr/typo3lib # Add plugins -RUN mv /tmp/solr-typo3-plugin.jar /opt/solr/example/solr/typo3lib/ -RUN ln -s /opt/solr/contrib /opt/solr/example/solr/contrib +RUN mv /tmp/solr-typo3-plugin.jar /opt/solr/example/solr/typo3lib/ \ + && ln -s /opt/solr/contrib /opt/solr/example/solr/contrib # Fix rights RUN chown solr:solr -R /opt/solr/example/solr/ diff --git a/docker/storage/Dockerfile b/docker/storage/Dockerfile index fafb2b2..b8ef05a 100644 --- a/docker/storage/Dockerfile +++ b/docker/storage/Dockerfile @@ -2,4 +2,9 @@ # Storage Docker container #++++++++++++++++++++++++++++++++++++++ -FROM webdevops/storage +FROM busybox + +RUN mkdir /storage \ + && chmod 1777 /storage + +VOLUME "/storage" From d40742a8fbd499538794f316bfc95e2f532b9025 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Fri, 18 Mar 2016 18:46:09 +0100 Subject: [PATCH 02/10] Refactoring backup/restore and Makefile --- Makefile | 16 ++++++---------- bin/.config.sh | 19 +++++++++++++++++++ bin/backup.sh | 23 +++++++++++++++-------- bin/restore.sh | 28 +++++++++++++++++++--------- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 1847647..738bf40 100644 --- a/Makefile +++ b/Makefile @@ -38,24 +38,20 @@ rebuild: ############################# mysql-backup: - docker-compose run --rm --no-deps app root bash /docker/bin/backup.sh mysql + bash ./bin/backup.sh mysql mysql-restore: - docker-compose run --rm --no-deps app root bash /docker/bin/restore.sh mysql + bash ./bin/restore.sh mysql ############################# # Solr ############################# solr-backup: - docker-compose stop solr - docker-compose run --rm --no-deps app root bash /docker/bin/backup.sh solr - docker-compose start solr + bash ./bin/backup.sh solr solr-restore: - docker-compose stop solr - docker-compose run --rm --no-deps app root bash /docker/bin/restore.sh solr - docker-compose start solr + bash ./bin/restore.sh solr ############################# # General @@ -68,10 +64,10 @@ build: bash bin/build.sh bash: - docker-compose run --rm app bash + docker exec -ti "`docker-compose ps -q app`" 'bash' root: - docker-compose run --rm app root + docker exec -ti "`docker-compose ps -q app`" 'root' ############################# # Argument fix workaround diff --git a/bin/.config.sh b/bin/.config.sh index 4b4cbcf..778961d 100755 --- a/bin/.config.sh +++ b/bin/.config.sh @@ -52,3 +52,22 @@ execInDir() { sh -c "cd \"$1\" && $2" } + +dockerContainerId() { + echo "$(docker-compose ps -q "$1" 2> /dev/null || echo "")" +} + +dockerExec() { + docker exec -i "$(docker-compose ps -q app)" $@ +} + +dockerCopyFrom() { + PATH_DOCKER="$1" + PATH_HOST="$2" + docker cp "$(docker-compose ps -q app):${PATH_DOCKER}" "${PATH_HOST}" +} +dockerCopyTo() { + PATH_HOST="$1" + PATH_DOCKER="$2" + docker cp "${PATH_HOST}" "$(docker-compose ps -q app):${PATH_DOCKER}" +} diff --git a/bin/backup.sh b/bin/backup.sh index 9d5c3c0..3afb2b8 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -25,7 +25,7 @@ case "$1" in fi logMsg "Starting MySQL backup..." - mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" + dockerExec mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" logMsg "Finished" ;; @@ -33,13 +33,20 @@ case "$1" in ## Solr ################################### "solr") - if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then - logMsg "Removing old backup file..." - rm -f -- "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" + if [[ -n "$(dockerContainerId solr)" ]]; then + logMsg "Starting Solr backup..." + docker-compose stop solr + + if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then + logMsg "Removing old backup file..." + rm -f -- "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" + fi + dockerExec tar -cP --to-stdout /storage/solr/ | bzip2 > "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" + + docker-compose start solr + logMsg "Finished" + else + echo "[WARNING] Skipping solr backup, no such container" fi - - logMsg "Starting Solr backup..." - tar jcPf "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" /storage/solr/ - logMsg "Finished" ;; esac diff --git a/bin/restore.sh b/bin/restore.sh index 71de559..f9a9764 100755 --- a/bin/restore.sh +++ b/bin/restore.sh @@ -21,7 +21,7 @@ case "$1" in "mysql") if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then logMsg "Starting MySQL restore..." - bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | mysql + bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | dockerExec mysql logMsg "Finished" else errorMsg "MySQL backup file not found" @@ -33,15 +33,25 @@ case "$1" in ## Solr ################################### "solr") - if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then - logMsg "Starting Solr restore..." - rm -rf /storage/solr/* && mkdir -p /storage/solr/ - chmod 777 /storage/solr/ - tar jxPf "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" -C / - logMsg "Finished" + if [[ -n "$(dockerContainerId solr)" ]]; then + if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then + logMsg "Starting Solr restore..." + docker-compose stop solr + + dockerExec rm -rf /storage/solr/ + dockerExec mkdir -p /storage/solr/ + dockerExec chmod 777 /storage/solr/ + dockerCopyTo "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" "/tmp/solr-restore.tbz2" + dockerExec tar -jxPf "/tmp/solr-restore.tbz2" -C / + + docker-compose start solr + logMsg "Finished" + else + errorMsg "Solr backup file not found" + exit 1 + fi else - errorMsg "Solr backup file not found" - exit 1 + echo "[WARNING] Skipping solr restore, no such container" fi ;; esac From 80c4f57041db9d39ba96efbf2e185b8517111e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Ho=CC=88chtl?= Date: Fri, 11 Mar 2016 22:45:09 +0100 Subject: [PATCH 03/10] Switch to docker exec in Makefile # Conflicts: # Makefile # Conflicts: # Makefile --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 738bf40..c52d118 100644 --- a/Makefile +++ b/Makefile @@ -63,11 +63,13 @@ restore: mysql-restore solr-restore build: bash bin/build.sh -bash: - docker exec -ti "`docker-compose ps -q app`" 'bash' +bash: shell + +shell: + docker exec -it -u application $$(docker-compose ps -q app) /bin/bash root: - docker exec -ti "`docker-compose ps -q app`" 'root' + docker exec -it -u root $$(docker-compose ps -q app) /bin/bash ############################# # Argument fix workaround From 4132c8033eaaace3eedd14a49e6ec0cfbcb0bb3f Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Mon, 21 Mar 2016 23:30:17 +0100 Subject: [PATCH 04/10] Add mysql backup only if mysql is available --- bin/backup.sh | 20 ++++++++++++-------- bin/restore.sh | 18 +++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bin/backup.sh b/bin/backup.sh index 3afb2b8..30fc9f6 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -19,14 +19,18 @@ case "$1" in ## MySQL ################################### "mysql") - if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then - logMsg "Removing old backup file..." - rm -f -- "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" - fi + if [[ -n "$(dockerContainerId mysql)" ]]; then + if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then + logMsg "Removing old backup file..." + rm -f -- "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" + fi - logMsg "Starting MySQL backup..." - dockerExec mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" - logMsg "Finished" + logMsg "Starting MySQL backup..." + dockerExec mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" + logMsg "Finished" + else + echo " * Skipping mysql backup, no such container" + fi ;; ################################### @@ -46,7 +50,7 @@ case "$1" in docker-compose start solr logMsg "Finished" else - echo "[WARNING] Skipping solr backup, no such container" + echo " * Skipping solr backup, no such container" fi ;; esac diff --git a/bin/restore.sh b/bin/restore.sh index f9a9764..de0bc6b 100755 --- a/bin/restore.sh +++ b/bin/restore.sh @@ -19,13 +19,17 @@ case "$1" in ## MySQL ################################### "mysql") - if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then - logMsg "Starting MySQL restore..." - bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | dockerExec mysql - logMsg "Finished" + if [[ -n "$(dockerContainerId mysql)" ]]; then + if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then + logMsg "Starting MySQL restore..." + bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | dockerExec mysql + logMsg "Finished" + else + errorMsg "MySQL backup file not found" + exit 1 + fi else - errorMsg "MySQL backup file not found" - exit 1 + echo " * Skipping mysql restore, no such container" fi ;; @@ -51,7 +55,7 @@ case "$1" in exit 1 fi else - echo "[WARNING] Skipping solr restore, no such container" + echo " * Skipping solr restore, no such container" fi ;; esac From 74ff48617028c22b41fe45cfc74e602fd0247ed6 Mon Sep 17 00:00:00 2001 From: Marc Henklein Date: Mon, 28 Mar 2016 21:00:18 +0200 Subject: [PATCH 05/10] enable phpXdebug by default for dev environment the php development.ini has xdebug enabled by default, so xdebug should also be installed. alternative: update the docs, that you have to enable phpXdebug first. --- etc/application.development.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/application.development.yml b/etc/application.development.yml index fe2c56b..6457b5a 100644 --- a/etc/application.development.yml +++ b/etc/application.development.yml @@ -5,7 +5,7 @@ PROVISION: install: phpBlackfire: false - phpXdebug: false + phpXdebug: true apacheModPagespeed: false service: From d1746000551099bad9e6ea2a4c4fe3079b0a5a8a Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Wed, 6 Apr 2016 21:12:39 +0200 Subject: [PATCH 06/10] Add exit on error in solr entrypoint Fixed #30 --- docker/solr/entrypoint.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docker/solr/entrypoint.sh b/docker/solr/entrypoint.sh index 2fbaa14..4f3ec51 100755 --- a/docker/solr/entrypoint.sh +++ b/docker/solr/entrypoint.sh @@ -1,5 +1,9 @@ #!/bin/bash +set -o pipefail # trace ERR through pipes +set -o errtrace # trace ERR through 'time command' and other functions +set -o nounset ## set -u : exit the script if you try to use an uninitialised variable +set -o errexit ## set -e : exit the script if any statement returns a non-true return value ################### # Move storage to storage container @@ -27,4 +31,4 @@ if [ "$1" = 'solr' ]; then exec java -jar start.jar fi -exec "$@" \ No newline at end of file +exec "$@" From a50ee194e0d23520f018bb8f1e30a51882d932a1 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Wed, 6 Apr 2016 21:14:48 +0200 Subject: [PATCH 07/10] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6204bc1..03ef08d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ PHP Docker Boilerplate Changelog 5.1.0 - UPCOMING ---------------- +- Enabled xdebug by default +- Added exit if solr entrypoint is failing inside 5.0.0 - 2016-03-07 ------------------ From 0926461b77d5a9bd04ef0d1a85c55447302bb6cc Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Wed, 6 Apr 2016 21:18:34 +0200 Subject: [PATCH 08/10] Add flush privileges for mysql on restore Fixed #10 --- bin/restore.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/restore.sh b/bin/restore.sh index de0bc6b..66a08da 100755 --- a/bin/restore.sh +++ b/bin/restore.sh @@ -23,6 +23,7 @@ case "$1" in if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then logMsg "Starting MySQL restore..." bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | dockerExec mysql + echo "FLUSH PRIVILEGES;" | dockerExec mysql logMsg "Finished" else errorMsg "MySQL backup file not found" From 30b376887c786a2c46b36951c76e48e2d1c08e4d Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Mon, 9 May 2016 21:33:23 +0200 Subject: [PATCH 09/10] Revert "enable phpXdebug by default for dev environment" This reverts commit 74ff48617028c22b41fe45cfc74e602fd0247ed6. Will not work with next Dockerimage files --- etc/application.development.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/application.development.yml b/etc/application.development.yml index 6457b5a..fe2c56b 100644 --- a/etc/application.development.yml +++ b/etc/application.development.yml @@ -5,7 +5,7 @@ PROVISION: install: phpBlackfire: false - phpXdebug: true + phpXdebug: false apacheModPagespeed: false service: From aa8f1ec197931262f1e36a44b1ae36544b5b279e Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Mon, 9 May 2016 21:39:36 +0200 Subject: [PATCH 10/10] Version bump --- CHANGELOG.md | 11 ++++++++--- README.md | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03ef08d..c6e23b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,14 @@ PHP Docker Boilerplate Changelog ================================== 5.1.0 - UPCOMING ----------------- -- Enabled xdebug by default -- Added exit if solr entrypoint is failing inside +----------------- + +5.0.2 - 2016-05-09 +------------------ +- Added exit if solr entrypoint is failing inside +- Fix solr storage +- Add `make shell` and `make root` (Makefile targets) +- Refactored backup and restore (solr and mysql, see Makefile) 5.0.0 - 2016-03-07 ------------------ diff --git a/README.md b/README.md index b8a54d4..59e98a4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Dockerized PHP web project boilerplate -[![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) +[![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) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat) [![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") [![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")