Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
- update docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbahl committed Jul 19, 2021
1 parent e11c5a8 commit 2fb3c32
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 111 deletions.
1 change: 0 additions & 1 deletion bin/install-test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ install_acf_pro() {
wp plugin activate advanced-custom-fields-pro
}


setup_plugin() {
# Add this repo as a plugin to the repo
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-acf ]; then
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
local:

app_db:
image: mysql:5.7
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
Expand Down
22 changes: 14 additions & 8 deletions docker/app.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
###############################################################################
# Pre-configured WordPress Installation w/ WPGraphQL, WPGraphQL for ACF, ACF Pro #
# Pre-configured WordPress Installation w/ WPGraphQL, WPGatsby #
# For testing only, use in production not recommended. #
###############################################################################

# Use build args to get the right wordpress + php image
ARG WP_VERSION
ARG PHP_VERSION

FROM wordpress:${WP_VERSION}-php${PHP_VERSION}-apache

# Needed to specify the build args again after the FROM command.
ARG WP_VERSION
ARG PHP_VERSION

# Save the build args for use by the runtime environment
ENV WP_VERSION=${WP_VERSION}
ENV PHP_VERSION=${PHP_VERSION}

Expand Down Expand Up @@ -39,13 +46,9 @@ RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli

# Set project environmental variables
ENV WP_ROOT_FOLDER="/var/www/html"
ENV WORDPRESS_DB_HOST=${DB_HOST}
ENV WORDPRESS_DB_USER=${DB_USER}
ENV WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
ENV WORDPRESS_DB_NAME=${DB_NAME}
ENV PLUGINS_DIR="${WP_ROOT_FOLDER}/wp-content/plugins"
ENV PROJECT_DIR="${PLUGINS_DIR}/wp-graphql-acf"
ENV WPGRAPHQL_VERSION="${WPGRAPHQL_VERSION}"
ENV PROJECT_DIR="${PLUGINS_DIR}/wp-graphql"
ENV DATA_DUMP_DIR="${PROJECT_DIR}/tests/_data"

# Remove exec statement from base entrypoint script.
RUN sed -i '$d' /usr/local/bin/docker-entrypoint.sh
Expand All @@ -66,13 +69,16 @@ RUN echo "Installing XDebug 3 (in disabled state)" \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
&& echo "xdebug.max_nesting_level=512" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \
;

# Set xdebug configuration off by default. See the entrypoint.sh.
ENV USING_XDEBUG=${USING_XDEBUG}
ENV USING_XDEBUG=0

# Set up entrypoint
WORKDIR /var/www/html
COPY docker/app.setup.sh /usr/local/bin/app-setup.sh
COPY docker/app.post-setup.sh /usr/local/bin/app-post-setup.sh
COPY docker/app.entrypoint.sh /usr/local/bin/app-entrypoint.sh
RUN chmod 755 /usr/local/bin/app-entrypoint.sh
ENTRYPOINT ["app-entrypoint.sh"]
Expand Down
85 changes: 3 additions & 82 deletions docker/app.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,7 @@
#!/bin/bash

if [ "$USING_XDEBUG" == "1" ]; then
echo "Enabling XDebug 3"
mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/
fi

# Run WordPress docker entrypoint.
. docker-entrypoint.sh 'apache2'

set +u

# Ensure mysql is loaded
dockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m

# Config WordPress
if [ ! -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
wp config create \
--path="${WP_ROOT_FOLDER}" \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASSWORD}" \
--dbhost="${DB_HOST}" \
--dbprefix="${WP_TABLE_PREFIX}" \
--skip-check \
--quiet \
--allow-root
fi

# Install WP if not yet installed
if ! $( wp core is-installed --allow-root ); then
wp core install \
--path="${WP_ROOT_FOLDER}" \
--url="${WP_URL}" \
--title='Test' \
--admin_user="${ADMIN_USERNAME}" \
--admin_password="${ADMIN_PASSWORD}" \
--admin_email="${ADMIN_EMAIL}" \
--allow-root
fi

# Install and activate WPGraphQL

echo "wpgraphql version... ${WPGRAPHQL_VERSION}"
echo "${PLUGINS_DIR}"

if [ ! -f "${PLUGINS_DIR}/wp-graphql/wp-graphql.php" ]; then
# WPGRAPHQL_VERSION in format like v1.2.3
echo ${WPGRAPHQL_VERSION}
if [[ -z ${WPGRAPHQL_VERSION} ]]; then
echo "installing latest WPGraphQL from WordPress.org"
wp plugin install wp-graphql --activate --allow-root
else
echo "Installing WPGraphQL from Github"
git clone https://github.com/wp-graphql/wp-graphql.git "${PLUGINS_DIR}/wp-graphql"
cd "${PLUGINS_DIR}/wp-graphql"
echo "checking out WPGraphQL tag/${WPGRAPHQL_VERSION}"
git checkout tags/${WPGRAPHQL_VERSION} -b master
composer install --no-dev
cd ${WP_ROOT_FOLDER}
echo "activating WPGraphQL"
wp plugin activate wp-graphql --allow-root
wp plugin list --allow-root
fi
else
wp plugin activate wp-graphql --allow-root
fi

# Install and activate ACF Pro
if [ ! -f "${PLUGINS_DIR}/advanced-custom-fields-pro/acf.php" ]; then
wp plugin install \
https://github.com/wp-premium/advanced-custom-fields-pro/archive/master.zip \
--activate --allow-root
else
wp plugin activate advanced-custom-fields-pro --allow-root
fi

# Install and activate WPGatsby
wp plugin activate wp-graphql-acf --allow-root

# Set pretty permalinks.
wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root

wp db export "${PROJECT_DIR}/tests/_data/dump.sql" --allow-root
# Run app setup script.
. app-setup.sh
. app-post-setup.sh

exec "$@"
15 changes: 15 additions & 0 deletions docker/app.post-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Activate wp-graphql
wp plugin activate wp-graphql --allow-root

# Set pretty permalinks.
wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root

wp db export "${DATA_DUMP_DIR}/dump.sql" --allow-root

# If maintenance mode is active, de-activate it
if $( wp maintenance-mode is-active --allow-root ); then
echo "Deactivating maintenance mode"
wp maintenance-mode deactivate --allow-root
fi
42 changes: 42 additions & 0 deletions docker/app.setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

if [ "$USING_XDEBUG" == "1" ]; then
echo "Enabling XDebug 3"
mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/
fi

# Run WordPress docker entrypoint.
. docker-entrypoint.sh 'apache2'

set +u

# Ensure mysql is loaded
dockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m

# Config WordPress
if [ ! -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
wp config create \
--path="${WP_ROOT_FOLDER}" \
--dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \
--dbpass="${DB_PASSWORD}" \
--dbhost="${DB_HOST}" \
--dbprefix="${WP_TABLE_PREFIX}" \
--skip-check \
--quiet \
--allow-root
fi

# Install WP if not yet installed
if ! $( wp core is-installed --allow-root ); then
wp core install \
--path="${WP_ROOT_FOLDER}" \
--url="${WP_URL}" \
--title='Test' \
--admin_user="${ADMIN_USERNAME}" \
--admin_password="${ADMIN_PASSWORD}" \
--admin_email="${ADMIN_EMAIL}" \
--allow-root
fi

echo "Running WordPress version: $(wp core version --allow-root) at $(wp option get home --allow-root)"
15 changes: 7 additions & 8 deletions docker/testing.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Container for running Codeception tests on a WPGraphQL Docker instance. #
############################################################################

# Using the 'DESIRED_' prefix to avoid confusion with environment variables of the same name.
FROM wpgraphql-acf-app:latest
ARG WP_VERSION
ARG PHP_VERSION

FROM wp-graphql:latest-wp${WP_VERSION}-php${PHP_VERSION}

LABEL author=jasonbahl
LABEL author_uri=https://github.com/jasonbahl
Expand All @@ -18,8 +20,8 @@ RUN docker-php-ext-install pdo_mysql
RUN apt-get install zip unzip -y \
&& pecl install pcov

ENV COVERAGE=0
ENV SUITES=${SUITES:-zz}
ENV COVERAGE=
ENV SUITES=${SUITES:-}

# Install composer
ENV COMPOSER_ALLOW_SUPERUSER=1
Expand All @@ -34,11 +36,8 @@ ENV PATH "$PATH:~/.composer/vendor/bin"
# Configure php
RUN echo "date.timezone = UTC" >> /usr/local/etc/php/php.ini

# Remove exec statement from base entrypoint script.
RUN sed -i '$d' /usr/local/bin/app-entrypoint.sh

# Set up entrypoint
WORKDIR /var/www/html/wp-content/plugins/wp-graphql-acf
WORKDIR /var/www/html
COPY docker/testing.entrypoint.sh /usr/local/bin/testing-entrypoint.sh
RUN chmod 755 /usr/local/bin/testing-entrypoint.sh
ENTRYPOINT ["testing-entrypoint.sh"]
38 changes: 27 additions & 11 deletions docker/testing.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

echo "WordPress: ${WP_VERSION} PHP: ${PHP_VERSION}"

# Processes parameters and runs Codeception.
run_tests() {
if [[ -n "$COVERAGE" ]]; then
Expand All @@ -15,10 +17,16 @@ run_tests() {
exit 1
fi

for suite in $suites ; do
echo "Running Test Suite $suite"
vendor/bin/codecept run -c codeception.dist.yml ${suite} ${coverage:-} ${debug:-} --no-exit
done
# If maintenance mode is active, de-activate it
if $( wp maintenance-mode is-active --allow-root ); then
echo "Deactivating maintenance mode"
wp maintenance-mode deactivate --allow-root
fi


# Suites is the comma separated list of suites/tests to run.
echo "Running Test Suite $suites"
vendor/bin/codecept run -c codeception.dist.yml "${suites}" ${coverage:-} ${debug:-} --no-exit
}

# Exits with a status of 0 (true) if provided version number is higher than proceeding numbers.
Expand All @@ -40,17 +48,25 @@ RewriteRule . /index.php [L]

# Move to WordPress root folder
workdir="$PWD"
echo "Moving to WordPress root directory."
echo "Moving to WordPress root directory ${WP_ROOT_FOLDER}."
cd ${WP_ROOT_FOLDER}

# Run app entrypoint script.
. app-entrypoint.sh
# Because we are starting apache independetly of the docker image,
# we set WORDPRESS environment variables so apache see them and used in the wp-config.php
echo "export WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST}" >> /etc/apache2/envvars
echo "export WORDPRESS_DB_USER=${WORDPRESS_DB_USER}" >> /etc/apache2/envvars
echo "export WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}" >> /etc/apache2/envvars
echo "export WORDPRESS_DB_NAME=${WORDPRESS_DB_NAME}" >> /etc/apache2/envvars

# Run app setup scripts.
. app-setup.sh
. app-post-setup.sh

write_htaccess

# Return to PWD.
echo "Moving back to project working directory."
cd ${workdir}
echo "Moving back to project working directory ${PROJECT_DIR}"
cd ${PROJECT_DIR}

# Ensure Apache is running
service apache2 start
Expand Down Expand Up @@ -78,8 +94,8 @@ if version_gt $PHP_VERSION 7.0 && [[ -n "$COVERAGE" ]] && [[ -z "$USING_XDEBUG"
echo "Using pcov/clobber for codecoverage"
docker-php-ext-enable pcov
echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
echo "pcov.directory = /var/www/html/wp-content/plugins/wp-graphql" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
COMPOSER_MEMORY_LIMIT=-1 composer require --dev pcov/clobber
echo "pcov.directory = ${PROJECT_DIR}" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
COMPOSER_MEMORY_LIMIT=-1 composer require pcov/clobber --dev
vendor/bin/pcov clobber
elif [[ -n "$COVERAGE" ]] && [[ -n "$USING_XDEBUG" ]]; then
echo "Using XDebug for codecoverage"
Expand Down

0 comments on commit 2fb3c32

Please sign in to comment.