diff --git a/.github/workflows/publish-7.2-fpm.yml b/.github/workflows/publish-7.2-fpm.yml new file mode 100644 index 0000000000..ce7eed79b4 --- /dev/null +++ b/.github/workflows/publish-7.2-fpm.yml @@ -0,0 +1,38 @@ +name: Publish 7.2 FPM-Alpine Image +on: + push: + paths: + - 'php7.2/fpm-alpine/**' + - '.github/workflows/publish-7.2-fpm.yml' + repository_dispatch: + types: [build_7.2_fpm] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build Image + run: ./publish-image.sh + working-directory: ./php7.2/fpm-alpine/ + - 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 }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Publish 7.2 FPM Alpine Docker Hub + run: ./publish-image.sh -p + shell: bash + working-directory: ./php7.2/fpm-alpine/ + - uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + - name: Publish 7.2 Git Package Repository + run: ./publish-image.sh -g + shell: bash + working-directory: ./php7.2/fpm-alpine/ diff --git a/.gitignore b/.gitignore index 0df9a505c3..695574a740 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ wordpress/ +default.run.config \ No newline at end of file diff --git a/README.md b/README.md index 3fb36a4bdf..0bfc1bb1d0 100644 --- a/README.md +++ b/README.md @@ -214,35 +214,3 @@ For more information contact [support@polyverse.io](mailto:support@polyverse.io) - - - -# Polyscripted WordPress is built from https://github.com/docker-library/wordpress - -## Maintained by: [the Docker Community](https://github.com/docker-library/wordpress) - -This is the Git repo of the [Docker "Official Image"](https://github.com/docker-library/official-images#what-are-official-images) for [`wordpress`](https://hub.docker.com/_/wordpress/) (not to be confused with any official `wordpress` image provided by `wordpress` upstream). See [the Docker Hub page](https://hub.docker.com/_/wordpress/) for the full readme on how to use this Docker image and for information regarding contributing and issues. - -The [full image description on Docker Hub](https://hub.docker.com/_/wordpress/) is generated/maintained over in [the docker-library/docs repository](https://github.com/docker-library/docs), specifically in [the `wordpress` directory](https://github.com/docker-library/docs/tree/master/wordpress). - -## See a change merged here that doesn't show up on Docker Hub yet? - -For more information about the full official images change lifecycle, see [the "An image's source changed in Git, now what?" FAQ entry](https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what). - -For outstanding `wordpress` image PRs, check [PRs with the "library/wordpress" label on the official-images repository](https://github.com/docker-library/official-images/labels/library%2Fwordpress). For the current "source of truth" for [`wordpress`](https://hub.docker.com/_/wordpress/), see [the `library/wordpress` file in the official-images repository](https://github.com/docker-library/official-images/blob/master/library/wordpress). - ---- -<<<<<<< HEAD -======= - -- [![build status badge](https://img.shields.io/travis/docker-library/wordpress/master.svg?label=Travis%20CI)](https://travis-ci.org/docker-library/wordpress/branches) -- [![build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/update.sh/job/wordpress.svg?label=Automated%20update.sh)](https://doi-janky.infosiftr.net/job/update.sh/job/wordpress) - -| Build | Status | Badges | (per-arch) | -|:-:|:-:|:-:|:-:| -| [![amd64 build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/amd64/job/wordpress.svg?label=amd64)](https://doi-janky.infosiftr.net/job/multiarch/job/amd64/job/wordpress) | [![arm32v5 build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/arm32v5/job/wordpress.svg?label=arm32v5)](https://doi-janky.infosiftr.net/job/multiarch/job/arm32v5/job/wordpress) | [![arm32v6 build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/arm32v6/job/wordpress.svg?label=arm32v6)](https://doi-janky.infosiftr.net/job/multiarch/job/arm32v6/job/wordpress) | [![arm32v7 build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/arm32v7/job/wordpress.svg?label=arm32v7)](https://doi-janky.infosiftr.net/job/multiarch/job/arm32v7/job/wordpress) | -| [![arm64v8 build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/arm64v8/job/wordpress.svg?label=arm64v8)](https://doi-janky.infosiftr.net/job/multiarch/job/arm64v8/job/wordpress) | [![i386 build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/i386/job/wordpress.svg?label=i386)](https://doi-janky.infosiftr.net/job/multiarch/job/i386/job/wordpress) | [![ppc64le build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/ppc64le/job/wordpress.svg?label=ppc64le)](https://doi-janky.infosiftr.net/job/multiarch/job/ppc64le/job/wordpress) | [![s390x build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/s390x/job/wordpress.svg?label=s390x)](https://doi-janky.infosiftr.net/job/multiarch/job/s390x/job/wordpress) | -| [![put-shared build status badge](https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/put-shared/job/light/job/wordpress.svg?label=put-shared)](https://doi-janky.infosiftr.net/job/put-shared/job/light/job/wordpress) | - - ->>>>>>> f6146861a38e5099a28af1c4b18c47114a918311 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 new file mode 100755 index 0000000000..ebcc46d082 --- /dev/null +++ b/php7.2/fpm-alpine/publish-image.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e +image="polyverse/polyscripted-wordpress" +echo "$(date) Obtaining current git sha for tagging the docker image" +headsha=$(git rev-parse --verify HEAD) + +echo "Copying scripts into current directory for docker build context..." +cp -Rp ../../scripts . + +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 +fi +#Github Container Repository +if [[ "$1" == "-g" ]]; then + echo "Pushing to Github Container Repository" + docker tag $image:alpine-7.2-$headsha ghcr.io/$image:alpine-7.2-$headsha + docker push ghcr.io/$image:alpine-7.2-$headsha +fi + +echo "Removing temporary scripts" +rm -rf ./scripts diff --git a/php7.4/apache/Dockerfile b/php7.4/apache/Dockerfile index 21cd9a4ccb..6ba38ccca0 100644 --- a/php7.4/apache/Dockerfile +++ b/php7.4/apache/Dockerfile @@ -1,5 +1,4 @@ FROM ghcr.io/polyverse/ps-php7.4-buster-apache:latest - ENV PHP_EXEC=/usr/local/bin # persistent dependencies @@ -18,13 +17,16 @@ RUN set -ex; \ \ apt-get update; \ apt-get install -y --no-install-recommends \ - libfreetype6-dev \ - libjpeg-dev \ - ncat \ - vim \ - libmagickwand-dev \ - libpng-dev \ - libzip-dev \ + libfreetype6-dev \ + libjpeg-dev \ + ncat \ + cron \ + incron \ + vim \ + git \ + libmagickwand-dev \ + libpng-dev \ + libzip-dev \ ; \ \ php -i; \ @@ -117,6 +119,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 80e04078db..fbe930f42f 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 0c2ff068c8..79059de4e8 100755 --- a/php7.4/apache/run.sh +++ b/php7.4/apache/run.sh @@ -1,9 +1,27 @@ #!/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 @@ -87,7 +105,7 @@ else 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 "" @@ -95,18 +113,18 @@ if [[ "$WORDPRESSDIR" == "" ]]; then echo " A new installation will be created if one does not already exist." echo "" while true; do - read -p "Do you wish to use this wordpress directory?" yn - case $yn in - [Yy]*) - export WORDPRESSDIR=$PWD/wordpress - break - ;; - [Nn]*) exit ;; - *) echo "Please answer yes or no." ;; - esac + read -p "Do you wish to use this wordpress directory?" yn + case $yn in + [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--------------------------------" @@ -158,61 +176,27 @@ 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 - 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 + if [[ $(docker ps -aq -f status=exited -f name=$CONTAINER_NAME) ]]; then + 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." + else + eval $wpcmd; + fi } echo "About to run this command (you may copy/store it to run directly):" diff --git a/php8.0/apache/Dockerfile b/php8.0/apache/Dockerfile index 81153150c5..c40841539c 100644 --- a/php8.0/apache/Dockerfile +++ b/php8.0/apache/Dockerfile @@ -2,6 +2,8 @@ FROM ghcr.io/polyverse/ps-php8.0-buster-apache:latest ENV PHP_EXEC=/usr/local/bin +ENV PHP_EXEC=/usr/local/bin + # persistent dependencies RUN set -eux; \ apt-get update; \ diff --git a/php8.0/apache/run-self-contained.sh b/php8.0/apache/run-self-contained.sh index 97b51abd7b..cbd5ab9df0 100755 --- a/php8.0/apache/run-self-contained.sh +++ b/php8.0/apache/run-self-contained.sh @@ -5,7 +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 arch_name="$(uname -m)" @@ -20,4 +20,4 @@ else fi docker run $platform --name mysql-host -e MYSQL_ROOT_PASSWORD=qwerty -d mysql:5.7 -docker run $platform --rm -e MODE=$MODE --name wordpress -v $PWD/wordpress:/wordpress --link mysql-host:mysql -p 8000:80 ${image}:apache-8.0-${headsha} +docker run $platform --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 5fe1b4e638..d1ecbe0e59 100755 --- a/php8.0/apache/run.sh +++ b/php8.0/apache/run.sh @@ -3,18 +3,23 @@ # 80-character wide dashes for intermittent use # echo "--------------------------------------------------------------------------------" -CONTAINER_NAME=wordpress - -arch_name="$(uname -m)" - -if [ "${arch_name}" = "x86_64" ]; then - echo "Running on x86_64." -elif [ "${arch_name}" = "arm64" ]; then - echo "Running on ARM. Adding platform to docker command." - platform="--platform linux/amd64" -else - echo "Unknown architecture: ${arch_name}" - exit 1 +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 { @@ -61,7 +66,7 @@ function startsql() { elif [[ $(docker ps -q -f status=running -f name=$MYSQL_HOST_NAME) ]]; then echo "Container already running." else - docker run $platform --name $MYSQL_HOST_NAME --health-cmd=' mysqladmin ping --silent' -e MYSQL_ROOT_PASSWORD=qwerty -v $WORDPRESS_SQL_DATADIR:/var/lib/mysql -d mysql:5.7 + docker run --name $MYSQL_HOST_NAME --health-cmd=' mysqladmin ping --silent' -e MYSQL_ROOT_PASSWORD=qwerty -v $WORDPRESS_SQL_DATADIR:/var/lib/mysql -d mysql:5.7 fi export dblink="--link $MYSQL_HOST_NAME:mysql" if [[ ! $(getContainerHealth $MYSQL_HOST_NAME) == "healthy" ]]; then @@ -99,7 +104,7 @@ else 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 "" @@ -107,18 +112,18 @@ if [[ "$WORDPRESSDIR" == "" ]]; then echo " A new installation will be created if one does not already exist." echo "" while true; do - read -p "Do you wish to use this wordpress directory?" yn - case $yn in - [Yy]*) - export WORDPRESSDIR=$PWD/wordpress - break - ;; - [Nn]*) exit ;; - *) echo "Please answer yes or no." ;; - esac + read -p "Do you wish to use this wordpress directory?" yn + case $yn in + [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--------------------------------" @@ -170,61 +175,27 @@ 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 $platform -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 - 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 + if [[ $(docker ps -aq -f status=exited -f name=$CONTAINER_NAME) ]]; then + 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." + else + eval $wpcmd; + fi } echo "About to run this command (you may copy/store it to run directly):" diff --git a/scripts/build-scrambled.sh b/scripts/build-scrambled.sh deleted file mode 100755 index c09755bc7e..0000000000 --- a/scripts/build-scrambled.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# Copyright (c) 2020 Polyverse Corporation -set -e - -if [ ! -f "${PHP_EXEC}/s_php" ]; then - echo "Backing up original php executable to s_php..." - cp -np $PHP_EXEC/php $PHP_EXEC/s_php -fi - -if [ ! -d "${POLYSCRIPT_PATH}/vanilla-php" ]; then - echo "Backing up to Vanilla PHP directory before scrambling..." - cp -nra $PHP_SRC_PATH $POLYSCRIPT_PATH/vanilla-php -else - echo "Restoring from vanilla php before scrambling..." - rm -rf $PHP_SRC_PATH - cp -nra $POLYSCRIPT_PATH/vanilla-php $PHP_SRC_PATH -fi - -echo "Creating a new PHP scramble..." -$POLYSCRIPT_PATH/php-scrambler - -cp -np $PHP_SRC_PATH/ext/phar/phar.php . -$PHP_EXEC/s_php tok-php-transformer.php -d scrambled.json -p $POLYSCRIPT_PATH/phar.php --replace -mv $POLYSCRIPT_PATH/phar.php $PHP_SRC_PATH/ext/phar/phar.php - -echo "Compiling and installing new scramble..." -cd $PHP_SRC_PATH -# Ingore errors in building PHP -make -o ext/phar/phar.php install -k || true -cd $POLYSCRIPT_PATH diff --git a/scripts/dispatch.sh b/scripts/dispatch.sh old mode 100755 new mode 100644 index 7231518f0a..61cec0cff2 --- a/scripts/dispatch.sh +++ b/scripts/dispatch.sh @@ -6,40 +6,84 @@ test -n "$1" || { 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 - /usr/local/bin/polyscripting/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; } diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index dafebe63bb..f92bd93859 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -17,7 +17,7 @@ file_env() { if [ "${!var:-}" ]; then val="${!var}" elif [ "${!fileVar:-}" ]; then - val="$(<"${!fileVar}")" + val="$(< "${!fileVar}")" fi export "$var"="$val" unset "$fileVar" @@ -26,19 +26,19 @@ file_env() { if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then if [ "$(id -u)" = '0' ]; then case "$1" in - apache2*) - user="${APACHE_RUN_USER:-www-data}" - group="${APACHE_RUN_GROUP:-www-data}" + apache2*) + user="${APACHE_RUN_USER:-www-data}" + group="${APACHE_RUN_GROUP:-www-data}" - # strip off any '#' symbol ('#1000' is valid syntax for Apache) - pound='#' - user="${user#$pound}" - group="${group#$pound}" - ;; - *) # php-fpm - user='www-data' - group='www-data' - ;; + # strip off any '#' symbol ('#1000' is valid syntax for Apache) + pound='#' + user="${user#$pound}" + group="${group#$pound}" + ;; + *) # php-fpm + user='www-data' + group='www-data' + ;; esac else user="$(id -u)" @@ -75,13 +75,13 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then ) if [ "$user" != '0' ]; then # avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted" - targetTarArgs+=(--no-overwrite-dir) + targetTarArgs+=( --no-overwrite-dir ) fi tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}" echo >&2 "Complete! WordPress has been successfully copied to $PWD" if [ ! -e .htaccess ]; then # NOTE: The "Indexes" option is disabled in the php:apache base image - cat >.htaccess <<-'EOF' + cat > .htaccess <<-'EOF' # BEGIN WordPress RewriteEngine On @@ -97,6 +97,10 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then 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") uniqueEnvs=( @@ -167,16 +171,15 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then } } { print } - ' wp-config-sample.php >wp-config.php <<'EOPHP' + ' wp-config-sample.php > wp-config.php <<'EOPHP' // If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact // see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { $_SERVER['HTTPS'] = 'on'; } - EOPHP chown "$user:$group" wp-config.php - elif [ -e wp-config.php ] && [ -n "$WORDPRESS_CONFIG_EXTRA" ] && [[ "$(&2 echo >&2 'WARNING: environment variable "WORDPRESS_CONFIG_EXTRA" is set, but "wp-config.php" already exists' @@ -240,12 +243,10 @@ EOPHP set_config 'WP_DEBUG' 1 boolean fi - if ! TERM=dumb php -- <<'EOPHP'; then + if ! TERM=dumb php -- <<'EOPHP' connect_error); - if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($dbName) . '`')) { fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n"); $mysql->close(); exit(1); } - $mysql->close(); EOPHP - + then echo >&2 echo >&2 "WARNING: unable to establish a database connection to '$WORDPRESS_DB_HOST'" echo >&2 ' continuing anyways (which might have unexpected results)' @@ -294,9 +292,25 @@ EOPHP unset "$e" done - if [ -e $POLYSCRIPT_PATH/scramble.sh ]; then - echo "Scrambler script found. Calling it..." - $POLYSCRIPT_PATH/scramble.sh "FIRST_CALL" + + 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 @@ -306,9 +320,9 @@ fi mkfifo /usr/local/bin/polyscripting/to_main_process echo "Forking off dispatcher and running $@..." -/usr/local/bin/polyscripting/dispatch.sh 2323 >&/usr/local/bin/polyscripting/to_main_process & -/usr/local/bin/tini -s -- "$@" >&/usr/local/bin/polyscripting/to_main_process & +/usr/local/bin/polyscripting/dispatch.sh 2323 >& /usr/local/bin/polyscripting/to_main_process & +/usr/local/bin/tini -s -- "$@" >& /usr/local/bin/polyscripting/to_main_process & # Infinite wait and print to stdout echo "Capturing dispatcher and apache output to stdout..." -while true; do cat /usr/local/bin/polyscripting/to_main_process; done +while true; do cat /usr/local/bin/polyscripting/to_main_process; done \ No newline at end of file diff --git a/scripts/scramble.sh b/scripts/scramble.sh index 9cc741635f..30591e1fac 100755 --- a/scripts/scramble.sh +++ b/scripts/scramble.sh @@ -2,16 +2,46 @@ set -e -if [ "$1" == "FIRST_CALL" ] && [ "$(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 argument --overwrite to enable overwriting /var/www/html directory." exit 1 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 echo "===================== POLYSCRIPTING ENABLED ==========================" @@ -29,7 +59,10 @@ if [[ "$MODE" == "polyscripted" || -f /polyscripted ]]; then sed -i "/#mod_allow/a \define( 'DISALLOW_FILE_MODS', true );" /var/www/html/wp-config.php fi - ./build-scrambled.sh + if ! [[ "$merge" == 'true' && -f scrambled.json ]] ; then + echo "Build flag found." + ./build-scrambled.sh + fi # Set transformer memory limit if [[ $TRANSFORMER_MEMORY_LIMIT != "" ]]; then @@ -91,4 +124,4 @@ else fi fi -fi +fi \ No newline at end of file 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