diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a55dc..f81f7ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,14 @@ PHP Docker Boilerplate Changelog ================================== 5.1.0 - UPCOMING ----------------- +----------------- + +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.1 - 2016-03-08 ------------------ diff --git a/Makefile b/Makefile index 9bf4177..928e961 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 @@ -70,18 +66,20 @@ build: clean: test -d app/typo3temp && { rm -rf app/typo3temp/*; } -bash: - docker-compose run --rm app bash +bash: shell + +shell: + docker exec -it -u application $$(docker-compose ps -q app) /bin/bash root: - docker-compose run --rm app root + docker exec -it -u root $$(docker-compose ps -q app) /bin/bash ############################# # TYPO3 ############################# scheduler: - docker-compose run --rm app typo3/cli_dispatch.phpsh scheduler $(ARGS) + docker exec -it $$(docker-compose ps -q app) typo3/cli_dispatch.phpsh scheduler $(ARGS) ############################# # Argument fix workaround diff --git a/README.md b/README.md index 8d5dac6..660d33a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Dockerized TYPO3 project boilerplate -[![latest v5.0.1](https://img.shields.io/badge/latest-v5.0.1-green.svg?style=flat)](https://github.com/webdevops/TYPO3-docker-boilerplate/releases/tag/5.0.1) +[![latest v5.0.2](https://img.shields.io/badge/latest-v5.0.2-green.svg?style=flat)](https://github.com/webdevops/TYPO3-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/webdevops/typo3-docker-boilerplate.svg)](http://isitmaintained.com/project/webdevops/typo3-docker-boilerplate "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/webdevops/typo3-docker-boilerplate.svg)](http://isitmaintained.com/project/webdevops/typo3-docker-boilerplate "Percentage of issues still open") diff --git a/app/web/index.php b/app/web/index.php new file mode 100644 index 0000000..c4837a3 --- /dev/null +++ b/app/web/index.php @@ -0,0 +1 @@ + /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..30fc9f6 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -19,27 +19,38 @@ 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}" + 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" + else + echo " * Skipping mysql backup, no such container" fi - - logMsg "Starting MySQL backup..." - mysqldump --opt --single-transaction --events --all-databases --routines --comments | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" - logMsg "Finished" ;; ################################### ## 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 " * 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/create-project.sh b/bin/create-project.sh index 7362cf3..2eb788f 100755 --- a/bin/create-project.sh +++ b/bin/create-project.sh @@ -12,10 +12,9 @@ if [ "$#" -lt 1 ]; then exit 1 fi -mkdir -p -- "$CODE_DIR/" -chmod 777 "$CODE_DIR/" -rm -f -- "$CODE_DIR/.gitkeep" +rm -rf -- "$CODE_DIR" +mkdir -p "$CODE_DIR" case "$1" in ################################### diff --git a/bin/restore.sh b/bin/restore.sh index 71de559..66a08da 100755 --- a/bin/restore.sh +++ b/bin/restore.sh @@ -19,13 +19,18 @@ case "$1" in ## MySQL ################################### "mysql") - if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then - logMsg "Starting MySQL restore..." - bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | 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 + echo "FLUSH PRIVILEGES;" | 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 ;; @@ -33,15 +38,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 " * Skipping solr restore, no such container" fi ;; esac 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/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 "$@" 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"