From c85d5d82900e0257a836003668d78015ea6a0feb Mon Sep 17 00:00:00 2001 From: Megan Starr Date: Mon, 27 Dec 2021 02:53:53 -0600 Subject: [PATCH 1/2] add an optional flag that preserves existing mybb files when archive is extracted --- README.md | 21 +++++++++++++++++++++ docker-entrypoint.sh | 13 +++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 739b9b3..5e67ff6 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,27 @@ Note, you'll also need a virtual host configuration file for the provided `nginx You should note that static content such as images and JavaScript or CSS files must be cross-mounted between the `mybb` and `nginx` containers - as PHP-FPM is not capable of serving those natively. +# Preserving existing files + +If you wish to run this image and preserve any updated `lang` or `config` files, you can add the following flag: + +``` +docker run $PWD --skip-old-files +``` + +or, within your compose file, specify the following command argument: + +```yaml +services: + mybb: + image: mybb/mybb:latest + command: --skip-old-files + volumes: + - ${PWD}/mybb:/var/www/html:rw + + ... +``` + # How to build this image You must provide four build-time arguments when building this Docker image; `BUILD_AUTHORS`, `BUILD_DATE`, `BUILD_SHA1SUM` and `BUILD_VERSION`. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 390446a..d984a85 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -3,11 +3,16 @@ set -euo pipefail if ! [ -e index.php -a -e inc/class_core.php ]; then echo >&2 "MyBB not found in $PWD - copying now..." - if [ "$(ls -A)" ]; then - echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" - ( set -x; ls -A; sleep 10 ) + if [[ $* == *--skip-old-files* ]] then + echo >&2 "Preserving existing directory files..." + tar cf - --one-file-system -C /usr/src/mybb-mybb_${MYBB_VERSION} . | tar xf - --skip-old-files + else + if [ "$(ls -A)" ]; then + echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" + ( set -x; ls -A; sleep 10 ) + fi + tar cf - --one-file-system -C /usr/src/mybb-mybb_${MYBB_VERSION} . | tar xf - fi - tar cf - --one-file-system -C /usr/src/mybb-mybb_${MYBB_VERSION} . | tar xf - echo >&2 "Complete! MyBB ${MYBB_VERSION} has been successfully copied to $PWD" fi From 147203ffd5733f306676d29510449efc0abbc8c3 Mon Sep 17 00:00:00 2001 From: Megan Starr Date: Mon, 27 Dec 2021 05:13:23 -0600 Subject: [PATCH 2/2] preserve command line arguments while keeping skip flag --- README.md | 4 ++-- docker-entrypoint.sh | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e67ff6..f4ca4e1 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ You should note that static content such as images and JavaScript or CSS files m If you wish to run this image and preserve any updated `lang` or `config` files, you can add the following flag: ``` -docker run $PWD --skip-old-files +docker run mybb/mybb --skip-old-files php-fpm ``` or, within your compose file, specify the following command argument: @@ -74,7 +74,7 @@ or, within your compose file, specify the following command argument: services: mybb: image: mybb/mybb:latest - command: --skip-old-files + command: --skip-old-files php-fpm volumes: - ${PWD}/mybb:/var/www/html:rw diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d984a85..8887d55 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,9 +1,24 @@ #!/usr/bin/env sh set -euo pipefail +SKIP_OLD_FILES=false + +# Loop through arguments and process them +for arg in "$@"; do + case $arg in + --skip-old-files) + SKIP_OLD_FILES=true + shift # Remove --skip-verification from `$@` + ;; + *) + break + ;; + esac +done + if ! [ -e index.php -a -e inc/class_core.php ]; then echo >&2 "MyBB not found in $PWD - copying now..." - if [[ $* == *--skip-old-files* ]] then + if [[ $SKIP_OLD_FILES == true ]]; then echo >&2 "Preserving existing directory files..." tar cf - --one-file-system -C /usr/src/mybb-mybb_${MYBB_VERSION} . | tar xf - --skip-old-files else