Skip to content

Commit

Permalink
Merge branch 'release/5.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mblaschke committed May 9, 2016
2 parents c2a6cd0 + aa8f1ec commit e2ca94d
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 51 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.0 - 2016-03-07
------------------
Expand Down
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,11 +63,13 @@ restore: mysql-restore solr-restore
build:
bash bin/build.sh

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

#############################
# Argument fix workaround
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
19 changes: 19 additions & 0 deletions bin/.config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
39 changes: 25 additions & 14 deletions bin/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 29 additions & 14 deletions bin/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,44 @@ 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
;;

###################################
## 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
2 changes: 1 addition & 1 deletion docker-compose.cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ mysql:
storage:
build: docker/storage/
volumes:
- /data
- /storage
2 changes: 1 addition & 1 deletion docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ mysql:
storage:
build: docker/storage/
volumes:
- /data
- /storage
2 changes: 1 addition & 1 deletion docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ mysql:
storage:
build: docker/storage/
volumes:
- /data
- /storage
10 changes: 5 additions & 5 deletions docker/solr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
6 changes: 5 additions & 1 deletion docker/solr/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,4 +31,4 @@ if [ "$1" = 'solr' ]; then
exec java -jar start.jar
fi

exec "$@"
exec "$@"
7 changes: 6 additions & 1 deletion docker/storage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
# Storage Docker container
#++++++++++++++++++++++++++++++++++++++

FROM webdevops/storage
FROM busybox

RUN mkdir /storage \
&& chmod 1777 /storage

VOLUME "/storage"

0 comments on commit e2ca94d

Please sign in to comment.