diff --git a/.github/workflows/publish-7.2-fpm.yml b/.github/workflows/publish-7.2-fpm.yml index ead443b78e..ba59e6ebea 100644 --- a/.github/workflows/publish-7.2-fpm.yml +++ b/.github/workflows/publish-7.2-fpm.yml @@ -18,6 +18,7 @@ jobs: - name: Test 7.2 WordPress Image run: ./workflow-test.sh ./php7.2/fpm-alpine/docker-compose.yml shell: bash + working-directory: ./ - uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} diff --git a/scripts/build-scrambled.sh b/build-scrambled.sh similarity index 72% rename from scripts/build-scrambled.sh rename to build-scrambled.sh index 020777e800..660b836537 100755 --- a/scripts/build-scrambled.sh +++ b/build-scrambled.sh @@ -1,14 +1,6 @@ #!/bin/bash # Copyright (c) 2020 Polyverse Corporation -if [ ! -v PHP_EXEC ]; then - PHP_EXEC=/usr/local/bin -fi - -if [ ! -f "${PHP_EXEC}/s_php" ]; then - cp -p $PHP_EXEC/php $PHP_EXEC/s_php -fi - if [ ! -d "${POLYSCRIPT_PATH}/vanilla-save" ]; then mkdir $POLYSCRIPT_PATH/vanilla-save cp -p $PHP_SRC_PATH/Zend/zend_language_scanner.l /usr/local/bin/polyscripting/vanilla-save/zend_language_scanner.l @@ -16,15 +8,16 @@ if [ ! -d "${POLYSCRIPT_PATH}/vanilla-save" ]; then cp -p $PHP_SRC_PATH/ext/phar/phar.php /usr/local/bin/polyscripting/vanilla-save/phar.php fi -$POLYSCRIPT_PATH//php-scrambler +$POLYSCRIPT_PATH/php-scrambler cp -p $PHP_SRC_PATH/ext/phar/phar.php . -$PHP_EXEC/s_php tok-php-transformer.php -p $POLYSCRIPT_PATH//phar.php --replace -mv $POLYSCRIPT_PATH//phar.php $PHP_SRC_PATH/ext/phar/phar.php +$POLYSCRIPT_PATH/s_php tok-php-transformer.php -p $POLYSCRIPT_PATH/phar.php --replace +mv $POLYSCRIPT_PATH/phar.php $PHP_SRC_PATH/ext/phar/phar.php cd $PHP_SRC_PATH; make -o ext/phar/phar.php install -k; cd $POLYSCRIPT_PATH; +touch /usr/local/bin/polyscripting/vanilla-save/* cp -p /usr/local/bin/polyscripting/vanilla-save/zend_language_scanner.l $PHP_SRC_PATH/Zend/zend_language_scanner.l cp -p /usr/local/bin/polyscripting/vanilla-save/zend_language_parser.y $PHP_SRC_PATH/Zend/zend_language_parser.y -cp -p /usr/local/bin/polyscripting/vanilla-save/phar.php $PHP_SRC_PATH/ext/phar/phar.php +cp -p /usr/local/bin/polyscripting/vanilla-save/phar.php $PHP_SRC_PATH/ext/phar/phar.php \ No newline at end of file diff --git a/default.run.config b/default.run.config new file mode 100644 index 0000000000..e5f46d4c3d --- /dev/null +++ b/default.run.config @@ -0,0 +1,11 @@ +#-------------------------CONTAINER CONFIGURATION-------------------------------- +export CONTAINER_NAME=wordpress +export CONTAINER_PORT=80 +export HOST_PORT=8000 +export CONTAINER_ADDRESS="http://localhost:$CONTAINER_PORT" + + +export WORDPRESS_DIR=$PWD/wordpress +export MODE=unpolyscripted + + diff --git a/php7.2/fpm-alpine/publish-image.sh b/php7.2/fpm-alpine/publish-image.sh index 66de4a8a31..ebcc46d082 100755 --- a/php7.2/fpm-alpine/publish-image.sh +++ b/php7.2/fpm-alpine/publish-image.sh @@ -1,4 +1,5 @@ #!/bin/bash + set -e image="polyverse/polyscripted-wordpress" echo "$(date) Obtaining current git sha for tagging the docker image" @@ -7,16 +8,18 @@ headsha=$(git rev-parse --verify HEAD) echo "Copying scripts into current directory for docker build context..." cp -Rp ../../scripts . -#Build and Tage +echo "Building and Tagging" +#Build and Tag docker build -t $image:alpine-7.2-$headsha . docker tag $image:alpine-7.2-$headsha $image:alpine-7.2 +docker tag $image:alpine-7.2-$headsha $image:alpine-7.2-latest docker tag $image:alpine-7.2-$headsha $image:latest #Dockerhub Respository if [[ "$1" == "-p" ]]; then + echo "Pushing to Docker Hub" docker push $image:alpine-7.2-$headsha docker push $image:alpine-7.2-latest - docker push $image:latest fi #Github Container Repository if [[ "$1" == "-g" ]]; then diff --git a/php7.4/apache/Dockerfile b/php7.4/apache/Dockerfile index 0ae550abec..6f3a1d1495 100644 --- a/php7.4/apache/Dockerfile +++ b/php7.4/apache/Dockerfile @@ -1,4 +1,4 @@ -FROM polyverse/ps-php7.4-apache:latest +FROM polyverse/ps-php7.4-buster-apache:latest # persistent dependencies RUN set -eux; \ @@ -19,7 +19,10 @@ RUN set -ex; \ libfreetype6-dev \ libjpeg-dev \ ncat \ + cron \ + incron \ vim \ + git \ libmagickwand-dev \ libpng-dev \ libzip-dev \ @@ -115,6 +118,7 @@ RUN curl -L -o /usr/local/bin/tini https://github.com/krallin/tini/releases/late WORKDIR $POLYSCRIPT_PATH COPY scripts/* $POLYSCRIPT_PATH/ +RUN mv scramble.sh /usr/local/bin # apache2-foreground comes from inherited container's CMD, which we chain ENTRYPOINT ["/usr/local/bin/tini", "-g", "--", "bash", "-c"] diff --git a/php7.4/apache/default.run.config b/php7.4/apache/default.run.config deleted file mode 100644 index 22a10301fb..0000000000 --- a/php7.4/apache/default.run.config +++ /dev/null @@ -1,5 +0,0 @@ -export WORDPRESSDIR=$PWD/wordpress -export WORDPRESS_DB_HOST=mysql-host -export MODE=unpolyscripted -export WORDPRESS_SQL_DATADIR="$PWD/mysql-data" - diff --git a/php7.4/apache/run-self-contained.sh b/php7.4/apache/run-self-contained.sh index dca4e34101..385950f928 100755 --- a/php7.4/apache/run-self-contained.sh +++ b/php7.4/apache/run-self-contained.sh @@ -5,6 +5,7 @@ echo "Running under mode: $MODE" image="polyverse/polyscripted-wordpress" echo "$(date) Obtaining current git sha for tagging the docker image" headsha=$(git rev-parse --verify HEAD) +php_version=apache-7.4 docker run --name mysql-host -e MYSQL_ROOT_PASSWORD=qwerty -d mysql:5.7 -docker run --rm -e MODE=$MODE --name wordpress -v $PWD/wordpress:/wordpress --link mysql-host:mysql -p 8000:80 $image:apache-7.4-$headsha +docker run --rm -e MODE=$MODE -e CONTAINER_ADDRESS="http://localhost:80" --name wordpress -v $PWD/wordpress:/wordpress --link mysql-host:mysql -p 8000:80 $image:$php_version-$headsha diff --git a/php7.4/apache/run.sh b/php7.4/apache/run.sh index ad0cd8610b..0404aa0038 100755 --- a/php7.4/apache/run.sh +++ b/php7.4/apache/run.sh @@ -1,11 +1,25 @@ #!/bin/bash - - - # 80-character wide dashes for intermittent use # echo "--------------------------------------------------------------------------------" -CONTAINER_NAME=wordpress +php_version=apache-7.4 + +if [[ "$CONTAINER_NAME" == "" ]]; then + echo "No container name env variable found, defaulting to wordpress." + CONTAINER_NAME=wordpress +fi +if [[ "$CONTAINER_PORT" == "" ]]; then + echo "No override container port found, using default exposed port 80." + CONTAINER_PORT=80 +fi +if [[ "$HOST_PORT" == "" ]]; then + echo "No host port env variable found, defaulting to port 8000." + HOST_PORT=8000 +fi +if [[ "$CONTAINER_ADDRESS" == "" ]]; then + echo "Defaulting to localhost for cron." + CONTAINER_ADDRESS="http://localhost:$CONTAINER_PORT" +fi function getContainerHealth { docker inspect --format "{{.State.Health.Status}}" $1 @@ -81,7 +95,7 @@ fi echo "---------------------------WORDPRESS DIRECTORY---------------------------------" -if [[ "$WORDPRESSDIR" == "" ]]; then +if [[ "$WORDPRESS_DIR" == "" ]]; then echo " A Wordpress directory was not specified. Using a default directory" echo " under the current path: $PWD/wordpress." echo "" @@ -91,13 +105,13 @@ if [[ "$WORDPRESSDIR" == "" ]]; then while true; do read -p "Do you wish to use this wordpress directory?" yn case $yn in - [Yy]* ) export WORDPRESSDIR=$PWD/wordpress; break;; + [Yy]* ) export WORDPRESS_DIR=$PWD/wordpress; break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done else - echo "Using wordpress installation from directory: $WORDPRESSDIR" + echo "Using wordpress installation from directory: $WORDPRESS_DIR" fi echo "-------------------------WORDPRESS CONFIGURATION--------------------------------" @@ -143,54 +157,26 @@ else echo "Found existing database configuration." fi +echo "-------------------------SYSTEM CRON ----------------------------------------" +echo "For optimization a system cron is utilized for the plugin." +echo "Set CONTAINER_ADDRESS to configure this cron." +echo "To disable cron jobs set WP_DISABLE_CRON and WP_DISABLE_INCRON to true." +echo "" + echo "-------------------------WORDPRESS STARTUP--------------------------------------" echo "$(date) Obtaining current git sha for tagging the docker image" headsha=$(git rev-parse --verify HEAD) -if [[ "$CONTAINERPORT" == "" ]]; then - echo "No override container port found, using default exposed port 80." - CONTAINERPORT=80 -fi -if [[ "$HOSTPORT" == "" ]]; then - echo "No host port env variable found, defaulting to port 8000." - HOSTPORT=8000 -fi -wpcmd="docker run -t -d -e MODE=$MODE --name $CONTAINER_NAME -v $WORDPRESSDIR:/wordpress -p $HOSTPORT:$CONTAINERPORT $wpvarparams $dblink polyverse/polyscripted-wordpress:apache-7.4-$headsha bash" -if [[ "$*" == "-f" ]] -then - echo "YES" -else - echo "NO" -fi -function startBackgroundTasks() { -if [[ $PLUGIN != "true" ]]; then - while true; do - read -p "Do you want to start dispatcher for the polyscripting plugin to allow scrambling from the wordpress plugin?" - case $yn in - [Yy]* ) docker exec -d $CONTAINER_NAME ./dispatch.sh 2323; echo "Set PLUGIN to true to skip this prompt."; break;; - [Nn]* ) echo "To enable dispatcher in the future run: docker exec -d $CONTAINER_NAME ./dispatch.sh 2323; break;;"; break;; - * ) echo "Please answer yes or no.";; - esac - done -else - docker exec -d $CONTAINER_NAME ./dispatch.sh 2323; -fi - echo "Starting apache server inside $CONTAINER_NAME" - docker exec -e MODE=$MODE --workdir /usr/local/bin $CONTAINER_NAME ./docker-entrypoint.sh apache2-foreground; -} +wpcmd="docker run -t -e MODE=$MODE -e CONTAINER_ADDRESS=$CONTAINER_ADDRESS --name $CONTAINER_NAME -v $WORDPRESS_DIR:/wordpress -p $HOST_PORT:$CONTAINER_PORT $wpvarparams $dblink polyverse/polyscripted-wordpress:$php_version-$headsha" function startContainer() { if [[ $(docker ps -aq -f status=exited -f name=$CONTAINER_NAME) ]]; then - echo "Existing container found, but it is stopped. Starting now." - docker start $CONTAINER_NAME - startBackgroundTasks + echo "Existing container found, but it is stopped." + echo "Restart, rename, or delete existing container." elif [[ $(docker ps -q -f status=running -f name=$CONTAINER_NAME) ]]; then echo "Container already running." - echo "To start dispatcher run: 'docker exec -d $CONTAINER_NAME ./dispatch.sh 2323'" - echo "To start apache run: 'docker exec -e MODE=$MODE --workdir /usr/local/bin $CONTAINER_NAME ./docker-entrypoint.sh apache2-foreground;'" else eval $wpcmd; - startBackgroundTasks fi } diff --git a/php8.0/apache/Dockerfile b/php8.0/apache/Dockerfile index 0e65974678..f7764360ec 100644 --- a/php8.0/apache/Dockerfile +++ b/php8.0/apache/Dockerfile @@ -1,11 +1,13 @@ FROM polyverse/ps-php8.0-buster-apache:latest +ENV PHP_EXEC=/usr/local/bin + # persistent dependencies RUN set -eux; \ apt-get update; \ apt-get install -y --no-install-recommends \ -# Ghostscript is required for rendering PDF previews - ghostscript \ + # Ghostscript is required for rendering PDF previews + ghostscript \ ; \ rm -rf /var/lib/apt/lists/* @@ -16,26 +18,26 @@ RUN set -ex; \ \ apt-get update; \ apt-get install -y --no-install-recommends \ - libfreetype6-dev \ - libjpeg-dev \ - ncat \ - vim \ - git \ - libmagickwand-dev \ - libpng-dev \ - libzip-dev \ + libfreetype6-dev \ + libjpeg-dev \ + ncat \ + vim \ + git \ + libmagickwand-dev \ + libpng-dev \ + libzip-dev \ ; \ \ php -i; \ docker-php-ext-configure gd --with-freetype --with-jpeg; \ docker-php-ext-install -j "$(nproc)" \ - bcmath \ - exif \ - sockets \ - gd \ - mysqli \ - opcache \ - zip \ + bcmath \ + exif \ + sockets \ + gd \ + mysqli \ + opcache \ + zip \ ; \ # Thanks to: https://github.com/Imagick/imagick/issues/331#issuecomment-743271207 # Enable the line below once it's on PECL @@ -49,73 +51,73 @@ RUN set -ex; \ make install; \ docker-php-ext-enable imagick; \ \ -# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies + # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies apt-mark auto '.*' > /dev/null; \ apt-mark manual $savedAptMark; \ ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \ - | awk '/=>/ { print $3 }' \ - | sort -u \ - | xargs -r dpkg-query -S \ - | cut -d: -f1 \ - | sort -u \ - | xargs -rt apt-mark manual; \ + | awk '/=>/ { print $3 }' \ + | sort -u \ + | xargs -r dpkg-query -S \ + | cut -d: -f1 \ + | sort -u \ + | xargs -rt apt-mark manual; \ \ rm -rf /var/lib/apt/lists/* # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php RUN { \ - echo 'opcache.memory_consumption=128'; \ - echo 'opcache.interned_strings_buffer=8'; \ - echo 'opcache.max_accelerated_files=4000'; \ - echo 'opcache.revalidate_freq=2'; \ - echo 'opcache.fast_shutdown=1'; \ + echo 'opcache.memory_consumption=128'; \ + echo 'opcache.interned_strings_buffer=8'; \ + echo 'opcache.max_accelerated_files=4000'; \ + echo 'opcache.revalidate_freq=2'; \ + echo 'opcache.fast_shutdown=1'; \ } > /usr/local/etc/php/conf.d/opcache-recommended.ini # https://wordpress.org/support/article/editing-wp-config-php/#configure-error-logging RUN { \ -# https://www.php.net/manual/en/errorfunc.constants.php -# https://github.com/docker-library/wordpress/issues/420#issuecomment-517839670 - echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \ - echo 'display_errors = Off'; \ - echo 'display_startup_errors = Off'; \ - echo 'log_errors = On'; \ - echo 'error_log = /dev/stderr'; \ - echo 'log_errors_max_len = 1024'; \ - echo 'ignore_repeated_errors = On'; \ - echo 'ignore_repeated_source = Off'; \ - echo 'html_errors = Off'; \ + # https://www.php.net/manual/en/errorfunc.constants.php + # https://github.com/docker-library/wordpress/issues/420#issuecomment-517839670 + echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \ + echo 'display_errors = Off'; \ + echo 'display_startup_errors = Off'; \ + echo 'log_errors = On'; \ + echo 'error_log = /dev/stderr'; \ + echo 'log_errors_max_len = 1024'; \ + echo 'ignore_repeated_errors = On'; \ + echo 'ignore_repeated_source = Off'; \ + echo 'html_errors = Off'; \ } > /usr/local/etc/php/conf.d/error-logging.ini RUN set -eux; \ a2enmod rewrite expires; \ \ -# https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html + # https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html a2enmod remoteip; \ { \ - echo 'RemoteIPHeader X-Forwarded-For'; \ -# these IP ranges are reserved for "private" use and should thus *usually* be safe inside Docker - echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \ - echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \ - echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \ - echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \ - echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \ + echo 'RemoteIPHeader X-Forwarded-For'; \ + # these IP ranges are reserved for "private" use and should thus *usually* be safe inside Docker + echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \ + echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \ + echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \ + echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \ + echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \ } > /etc/apache2/conf-available/remoteip.conf; \ a2enconf remoteip; \ -# https://github.com/docker-library/wordpress/issues/383#issuecomment-507886512 -# (replace all instances of "%h" with "%a" in LogFormat) + # https://github.com/docker-library/wordpress/issues/383#issuecomment-507886512 + # (replace all instances of "%h" with "%a" in LogFormat) find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' + # Keep compiled layer up top so it is reused when scripts are modified. WORKDIR $PHP_SRC_PATH RUN make install -ENV WORDPRESS_VERSION 5.6 -ENV WORDPRESS_SHA1 db8b75bfc9de27490434b365c12fd805ca6784ce +ENV WORDPRESS_VERSION 5.7.2 +ENV WORDPRESS_SHA1 c97c037d942e974eb8524213a505268033aff6c8 RUN set -ex; \ curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \ echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \ -# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress + # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress tar -xzf wordpress.tar.gz -C /usr/src/; \ rm wordpress.tar.gz; \ chown -R www-data:www-data /usr/src/wordpress diff --git a/php8.0/apache/run-self-contained.sh b/php8.0/apache/run-self-contained.sh index 612b3b652d..385950f928 100755 --- a/php8.0/apache/run-self-contained.sh +++ b/php8.0/apache/run-self-contained.sh @@ -5,6 +5,7 @@ echo "Running under mode: $MODE" image="polyverse/polyscripted-wordpress" echo "$(date) Obtaining current git sha for tagging the docker image" headsha=$(git rev-parse --verify HEAD) +php_version=apache-7.4 docker run --name mysql-host -e MYSQL_ROOT_PASSWORD=qwerty -d mysql:5.7 -docker run --rm -e MODE=$MODE --name wordpress -v $PWD/wordpress:/wordpress --link mysql-host:mysql -p 8000:80 $image:apache-8.0-$headsha +docker run --rm -e MODE=$MODE -e CONTAINER_ADDRESS="http://localhost:80" --name wordpress -v $PWD/wordpress:/wordpress --link mysql-host:mysql -p 8000:80 $image:$php_version-$headsha diff --git a/php8.0/apache/run.sh b/php8.0/apache/run.sh index 2743a9f6d4..086f4ea686 100755 --- a/php8.0/apache/run.sh +++ b/php8.0/apache/run.sh @@ -1,11 +1,25 @@ #!/bin/bash - - - # 80-character wide dashes for intermittent use # echo "--------------------------------------------------------------------------------" -CONTAINER_NAME=wordpress +php_version=apache-8.0 + +if [[ "$CONTAINER_NAME" == "" ]]; then + echo "No container name env variable found, defaulting to wordpress." + CONTAINER_NAME=wordpress +fi +if [[ "$CONTAINER_PORT" == "" ]]; then + echo "No override container port found, using default exposed port 80." + CONTAINER_PORT=80 +fi +if [[ "$HOST_PORT" == "" ]]; then + echo "No host port env variable found, defaulting to port 8000." + HOST_PORT=8000 +fi +if [[ "$CONTAINER_ADDRESS" == "" ]]; then + echo "Defaulting to localhost for cron." + CONTAINER_ADDRESS="http://localhost:$CONTAINER_PORT" +fi function getContainerHealth { docker inspect --format "{{.State.Health.Status}}" $1 @@ -81,7 +95,7 @@ fi echo "---------------------------WORDPRESS DIRECTORY---------------------------------" -if [[ "$WORDPRESSDIR" == "" ]]; then +if [[ "$WORDPRESS_DIR" == "" ]]; then echo " A Wordpress directory was not specified. Using a default directory" echo " under the current path: $PWD/wordpress." echo "" @@ -91,13 +105,13 @@ if [[ "$WORDPRESSDIR" == "" ]]; then while true; do read -p "Do you wish to use this wordpress directory?" yn case $yn in - [Yy]* ) export WORDPRESSDIR=$PWD/wordpress; break;; + [Yy]* ) export WORDPRESS_DIR=$PWD/wordpress; break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done else - echo "Using wordpress installation from directory: $WORDPRESSDIR" + echo "Using wordpress installation from directory: $WORDPRESS_DIR" fi echo "-------------------------WORDPRESS CONFIGURATION--------------------------------" @@ -143,54 +157,26 @@ else echo "Found existing database configuration." fi +echo "-------------------------SYSTEM CRON ----------------------------------------" +echo "For optimization a system cron is utilized for the plugin." +echo "Set CONTAINER_ADDRESS to configure this cron." +echo "To disable cron jobs set WP_DISABLE_CRON and WP_DISABLE_INCRON to true." +echo "" + echo "-------------------------WORDPRESS STARTUP--------------------------------------" echo "$(date) Obtaining current git sha for tagging the docker image" headsha=$(git rev-parse --verify HEAD) -if [[ "$CONTAINERPORT" == "" ]]; then - echo "No override container port found, using default exposed port 80." - CONTAINERPORT=80 -fi -if [[ "$HOSTPORT" == "" ]]; then - echo "No host port env variable found, defaulting to port 8000." - HOSTPORT=8000 -fi -wpcmd="docker run -t -d -e MODE=$MODE --name $CONTAINER_NAME -v $WORDPRESSDIR:/wordpress -p $HOSTPORT:$CONTAINERPORT $wpvarparams $dblink polyverse/polyscripted-wordpress:apache-8.0-$headsha bash" -if [[ "$*" == "-f" ]] -then - echo "YES" -else - echo "NO" -fi -function startBackgroundTasks() { -if [[ $PLUGIN != "true" ]]; then - while true; do - read -p "Do you want to start dispatcher for the polyscripting plugin to allow scrambling from the wordpress plugin?" - case $yn in - [Yy]* ) docker exec -d $CONTAINER_NAME ./dispatch.sh 2323; echo "Set PLUGIN to true to skip this prompt."; break;; - [Nn]* ) echo "To enable dispatcher in the future run: docker exec -d $CONTAINER_NAME ./dispatch.sh 2323; break;;"; break;; - * ) echo "Please answer yes or no.";; - esac - done -else - docker exec -d $CONTAINER_NAME ./dispatch.sh 2323; -fi - echo "Starting apache server inside $CONTAINER_NAME" - docker exec -e MODE=$MODE --workdir /usr/local/bin $CONTAINER_NAME ./docker-entrypoint.sh apache2-foreground; -} +wpcmd="docker run -t -e MODE=$MODE -e CONTAINER_ADDRESS=$CONTAINER_ADDRESS --name $CONTAINER_NAME -v $WORDPRESS_DIR:/wordpress -p $HOST_PORT:$CONTAINER_PORT $wpvarparams $dblink polyverse/polyscripted-wordpress:$php_version-$headsha" function startContainer() { if [[ $(docker ps -aq -f status=exited -f name=$CONTAINER_NAME) ]]; then - echo "Existing container found, but it is stopped. Starting now." - docker start $CONTAINER_NAME - startBackgroundTasks + echo "Existing container found, but it is stopped." + echo "Restart, rename, or delete existing container." elif [[ $(docker ps -q -f status=running -f name=$CONTAINER_NAME) ]]; then echo "Container already running." - echo "To start dispatcher run: 'docker exec -d $CONTAINER_NAME ./dispatch.sh 2323'" - echo "To start apache run: 'docker exec -e MODE=$MODE --workdir /usr/local/bin $CONTAINER_NAME ./docker-entrypoint.sh apache2-foreground;'" else eval $wpcmd; - startBackgroundTasks fi } diff --git a/scripts/dispatch.sh b/scripts/dispatch.sh index 9c6586e4a2..23904fc803 100755 --- a/scripts/dispatch.sh +++ b/scripts/dispatch.sh @@ -3,38 +3,78 @@ test -n "$1" || { echo "$0 "; exit 1; } port=$1 +volume="/wordpress" + +LOGFILE="/var/log/dispatcher-in.logs" + +#Cron job to curl wp-crons -- updated health of container every hour. +if [[ '$WP_DISABLE_CRON' != 'true' ]]; then + (crontab -l 2>/dev/null | grep -v '^[a-zA-Z]'; echo "*/15 * * * * curl $CONTAINER_ADDRESS/wp-cron.php >> /var/log/wp-cron.log 2>&1") | sort - | uniq - | crontab - + echo "Starting Cron job for Polyscripting Plugin" + /etc/init.d/cron start +fi + +#Cron job to watch for mounted volume changes. +if [[ '$WP_DISABLE_INCRON' != 'true' ]]; then + (incrontab -l 2>/dev/null | grep -v '^[a-zA-Z]'; echo "$volume IN_MODIFY,loopable=true /usr/local/bin/polyscripting/wp-incron.sh $port >> /var/log/wp-incron.log 2>&1") | sort - | uniq - | incrontab - + echo "Starting incron job for Polyscripting Plugin" + /etc/init.d/incron start +fi + function poly-dispatcher () { while true ; do read -d ' ' msg + now=$(date +"%T") case $msg in 1 ) - echo "1" >> dispatcher-in.logs + echo "Recieved code 1, scrambling. $now" >> $LOGFILE export MODE=polyscripted ;; 2 ) - echo "2" >> dispatcher-in.logs + echo "Recieved code 2, rescrambling. $now" >> $LOGFILE export MODE=polyscripted ;; 3 ) - echo "3" >> dispatcher-in.logs + echo "Recieved code 3, disabling. $now" + >> $LOGFILE export MODE=off ;; + 4 ) + echo "Recieved code 4, merging. $now" + >> $LOGFILE + if [ "$MODE" == "polyscripted" ]; then + echo "Polyscripting enabled, merging changes from mounted directory." + export MODE=merge + merge='true' + else + echo "Polyscripting not enabled, merge not necessary." + no_action='true' + fi + ;; * ) - err='true' - echo "err" >> dispatcher-in.logs - echo "Commands: 1, scramble; 2, rescramble; 3, reset;" + no_action='true' + echo "err $now" >> $LOGFILE + echo "Commands: 1, scramble; 2, rescramble; 3, merge 4, reset;" echo " ctrl-c to exit" esac - if ! [[ $err = 'true' ]]; then - scramble.sh >& /usr/local/bin/polyscripting/to_main_process - service apache2 stop >& /usr/local/bin/polyscripting/to_main_process - /usr/local/bin/tini -s -- "apache2-foreground" >& /usr/local/bin/polyscripting/to_main_process & - err='false' + if ! [[ $no_action == 'true' ]]; then + echo "Calling scramble script" + scramble.sh -o >& /usr/local/bin/polyscripting/to_main_process + if ! [[ $merge == 'true' ]]; then + echo "Restarting services" + service apache2 stop >& /usr/local/bin/polyscripting/to_main_process + /usr/local/bin/tini -s -- "apache2-foreground" >& /usr/local/bin/polyscripting/to_main_process & + else + echo "Merge complete. Not restarting services." + export MODE=polyscripted + export merge='false' + fi + no_action='false' fi - echo "done" >> dispatcher-in.logs + no_action='false' + echo "Message read complete. Waiting for next." >> $LOGFILE echo -n "> " done - echo "complete" >> dispatcher-in.logs + echo "complete dispatcher process ending." >> $LOGFILE } coproc proc_dispatcher { poly-dispatcher; } nc -v -l -p $port -k <&${proc_dispatcher[0]} >&${proc_dispatcher[1]} + diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index ca26520981..c0ca65028f 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -96,6 +96,10 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then chown "$user:$group" .htaccess fi fi + + if [ ! -e wp-content/plugins/polyscripting-plugin ]; then + mkdir wp-content/plugins/polyscripting-plugin && curl -sL https://github.com/polyverse/polyscripting-plugin/archive/refs/tags/2.0.tar.gz | tar xvfz - -C wp-content/plugins/polyscripting-plugin --strip-components=1 + fi # allow any of these "Authentication Unique Keys and Salts." to be specified via # environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY") @@ -294,14 +298,26 @@ EOPHP unset "$e" done - if [ -e $POLYSCRIPT_PATH/scramble.sh ]; then - echo "Scrambler script found. Calling it..." - $POLYSCRIPT_PATH/scramble.sh - fi -fi -if [ -f "/usr/local/bin/s_php" ]; then - rm -rf /usr/local/bin/s_php + if [ "$(ls -A /var/www/html)" ]; then + echo "The directory /var/www/html is non-empty. This is unexpected and dangerous for this container." + echo "This container expects Wordpress (or the PHP app) at location '/wordpress' which will then be" + echo "properly provided at /var/www/html either directly or polyscripted." + echo "" + echo "To avoid destroying your code, aboring this container." + + exit 1 + else + rm -rf /var/www/html + fi + echo root >> /etc/incron.allow + scramble.sh + if [ $? -eq 0 ]; then + echo "Scrambler script found & called." + else + echo "Scramble script not found. Failed" + exit 0 + fi fi # Get all child processes to send data to us such that we can diff --git a/scripts/scramble.sh b/scripts/scramble.sh index fc11ac5459..9c7861c5cb 100755 --- a/scripts/scramble.sh +++ b/scripts/scramble.sh @@ -1,15 +1,43 @@ #!/bin/bash -if [ "$(ls -A /var/www/html)" ]; then - echo "The directory /var/www/html is non-empty. This is unexpected and dangerous for this container." - echo "This container expects Wordpress (or the PHP app) at location '/wordpress' which will then be" - echo "properly provided at /var/www/html either directly or polyscripted." - echo "" - echo "To avoid destroying your code, aboring this container." +### LOCK TO ENSURE MULTIPLE SCRAMBLES ARE NOT CALLED SIMULTANEOUSLY ### +exec 100>/var/tmp/scramble.lock || exit 1 +flock -n 100 || exit 1 +trap 'rm -f /var/tmp/scramble.lock' EXIT +### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### + + +for i in "$@" +do +case $i in + --overwrite|-o) + OW=1 + shift # past argument with no value + ;; + *) + ;; +esac +done +if [[ $(ls -A /var/www/html) && $OW -ne 1 ]]; then + echo "The directory /var/www/html is non-empty. This is unexpected and dangerous for this container." + echo "To run this script, pass arugment --overwrite to enable overwriting /var/www/html directory." exit 1 -else - rm -rf /var/www/html +fi + +if [ ! -v PHP_EXEC ]; then + PHP_EXEC=/usr/local/bin +fi + +if [ ! -f "${PHP_EXEC}/s_php" ]; then + $POLYSCRIPT_PATH/reset.sh + cp -p $PHP_EXEC/php $POLYSCRIPT_PATH/s_php +fi + +if [[ "$MODE" == "merge" ]]; then + echo "Merging files only." + export MODE=polyscripted + merge=true fi if [[ "$MODE" == "polyscripted" || -f /polyscripted ]]; then @@ -24,10 +52,15 @@ if [[ "$MODE" == "polyscripted" || -f /polyscripted ]]; then echo "Starting polyscripted WordPress" cd $POLYSCRIPT_PATH - sed -i "/#mod_allow/a \define( 'DISALLOW_FILE_MODS', true );" /var/www/html/wp-config.php - ./build-scrambled.sh - if [ -f scrambled.json ] && s_php tok-php-transformer.php -p /var/www/temp --replace; then - rm -rf /var/www/html + sed -i "/#mod_allow/a \define( 'DISALLOW_FILE_MODS', true );" /var/www/temp/wp-config.php + + if ! [[ "$merge" == 'true' && -f scrambled.json ]] ; then + echo "Build flag found." + ./build-scrambled.sh + fi + + if [ -f scrambled.json ] && ./s_php tok-php-transformer.php -p /var/www/temp --replace; then + rm -rf /var/www/html mv /var/www/temp /var/www/html echo "Polyscripting enabled." echo "done" @@ -46,11 +79,8 @@ else echo " 1. Set the environment variable: MODE=polyscripted" echo " 2. OR create a file at path: /polyscripted" - if [ -d $POLYSCRIPT_PATH/vanilla-save ]; then - $POLYSCRIPT_PATH/reset.sh - fi - # Symlink the mount so it's editable + rm -rf /var/www/html ln -s /wordpress /var/www/html fi @@ -76,4 +106,9 @@ else fi fi -fi \ No newline at end of file +fi + +if [ -f "${POLYSCRIPT_PATH}/s_php" ]; then + rm $POLYSCRIPT_PATH/s_php +fi + diff --git a/scripts/wp-incron.sh b/scripts/wp-incron.sh new file mode 100755 index 0000000000..4619457f20 --- /dev/null +++ b/scripts/wp-incron.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e +port=$1 +host='localhost' + + +### LOCK CRON JOB ### +scriptname=$(basename $0) +lock="/var/run/${scriptname}" +exec 201>lock +flock -n 201 || exit 1 +pid=$$ +echo $pid 1>&201 +### LOCK CRON JOB ### + +echo "Modification to wordpress directory caught at: $(date +"%T")" +sleep 30m +echo "Sending merge request at: $(date +"%T")" +echo "4 " | nc $host $port diff --git a/workflow-test.sh b/workflow-test.sh index d379fe3da6..686beb1995 100755 --- a/workflow-test.sh +++ b/workflow-test.sh @@ -46,7 +46,6 @@ function start { docker run --rm --name mysql-host -e MYSQL_ROOT_PASSWORD=qwerty -d mysql:5.7 docker run --rm -e MODE=$MODE --name $container -v $PWD/wordpress:/wordpress --link mysql-host:mysql -p 8000:80 $image else - echo "alpine" docker tag $image $image:alpine-7.2-test MODE=$MODE headsha="test" docker-compose -f $compose up fi @@ -54,7 +53,7 @@ function start { echo "testing vanilla wordpress" start & -sleep 20 +sleep 45 if [ "$( docker container inspect -f '{{.State.Running}}' $container )" == "false" ]; then fail "Vanilla container failed to start -- check container errors." fi