Skip to content

Commit

Permalink
Docker/Codeception CI configuration updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Jan 22, 2021
1 parent f55db50 commit b8d913e
Show file tree
Hide file tree
Showing 23 changed files with 217 additions and 234 deletions.
20 changes: 10 additions & 10 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
ADMIN_PATH=/wp-admin

# WordPress local configurations
WP_CORE_DIR=local/public
PLUGINS_DIR=local/public/wp-content/plugins
MUPLUGINS_DIR=local/public/wp-content/mu-plugins
THEMES_DIR=local/public/wp-content/themes
# WordPress location configurations
WP_CORE_DIR=
PLUGINS_DIR=
MUPLUGINS_DIR=
THEMES_DIR=

# WordPress database configurations
DB_NAME=wordpress
Expand All @@ -18,10 +18,10 @@ DB_USER=wordpress
DB_PASSWORD=password
ROOT_PASSWORD=password
WP_TABLE_PREFIX=wp_
SKIP_DB_CREATE=false
SKIP_DB_CREATE=true
SKIP_WP_SETUP=true

# Extra variables/constants.
# Extra environmental variables/constants.
GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123
STRIPE_API_PUBLISHABLE_KEY=""
STRIPE_API_SECRET_KEY=""
PHPUNIT_VERSION=":<=9.4.4"
STRIPE_API_PUBLISHABLE_KEY=
STRIPE_API_SECRET_KEY=
25 changes: 10 additions & 15 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@ on:
- '!docs/**'

jobs:
continuous_integration:
Automated-Testing:
env:
STRIPE_API_PUBLISHABLE_KEY: ${{ secrets.STRIPE_API_PUBLISHABLE_KEY }}
STRIPE_API_SECRET_KEY: ${{ secrets.STRIPE_API_SECRET_KEY }}
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3']
php: ['7.1', '7.2', '7.3', '7.4']
wordpress: ['5.3', '5.0']
debug: ['--ext DotReporter']
include:
- php: '7.1'
use_xdebug: 1
- php: '7.1'
wordpress: '5.0'
coverage: '--coverage --coverage-xml'
- php: '7.3'
wordpress: '5.0'
debug: '--debug'
- php: '7.1'
- lowest: 1
- php: '7.2'
- lowest: 1

fail-fast: false
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
Expand All @@ -53,15 +48,15 @@ jobs:

- name: Install dependencies
run: |
composer require --dev johnpbloch/wordpress:~${{ matrix.wordpress }}
composer install
- name: Build "testing" Docker Image
run: composer docker-build -- --build-arg PHP_VERSION=${{ matrix.php }} run_tests
cp .env.dist .env
SKIP_DB_CREATE=true SKIP_WP_SETUP=true composer require --dev johnpbloch/wordpress:~${{ matrix.wordpress }}
composer installTestEnv
- name: Run Tests w/ Docker.
run: FILTER="${{ matrix.coverage }} ${{ matrix.debug }}" composer docker-run-test-standalone
env:
WP_VERSION: ${{ matrix.wordpress }}
PHP_VERSION: ${{ matrix.php }}
run: FILTER="${{ matrix.coverage }} ${{ matrix.debug }}" composer dRunTestStandalone

- name: Push Codecoverage to Coveralls.io
if: ${{ matrix.coverage == 1 && env.STRIPE_API_PUBLISHABLE_KEY != 0 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- '!docs/**'

jobs:
lint_code:
Coding-Standards:
runs-on: ubuntu-latest
name: "Lint code with PHPCS"
steps:
Expand Down
14 changes: 6 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG PHP_VERSION=7.4

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

ARG XDEBUG_VERSION=2.9.6
Expand All @@ -18,8 +17,7 @@ RUN pecl install "xdebug-${XDEBUG_VERSION}"; \
docker-php-ext-enable xdebug; \
echo "xdebug.default_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_autostart = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_handler = dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_connect_back = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_connect_back = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_port = 9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_log = /var/www/html/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;
Expand All @@ -38,9 +36,7 @@ RUN curl -sS https://getcomposer.org/installer | php -- \
ENV PATH "$PATH:~/.composer/vendor/bin"

# Set PHPUnit version.
ARG PHPUNIT_VERSION
ENV PHPUNIT_VERSION=${PHPUNIT_VERSION:-''}

ARG PHPUNIT_VERSION=9.4.4
# Install wp-browser globally
RUN composer global require --optimize-autoloader \
wp-cli/wp-cli-bundle \
Expand All @@ -55,7 +51,8 @@ RUN composer global require --optimize-autoloader \
codeception/util-universalframework \
league/factory-muffin \
league/factory-muffin-faker \
phpunit/phpunit${PHPUNIT_VERSION}
stripe/stripe-php \
"phpunit/phpunit:<=${PHPUNIT_VERSION}"

# Remove exec statement from base entrypoint script.
RUN sed -i '$d' /usr/local/bin/docker-entrypoint.sh
Expand All @@ -73,6 +70,7 @@ 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-woocommerce"
ENV WOOGRAPHQL_TESTS_DIR="/var/www/html/tests"

# Set up Apache
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<a href="https://woographql.com/" target="_blank">Docs</a> • <a href="https://www.axistaylor.com" target="_blank">AxisTaylor</a> • <a href="https://wpgql-slack.herokuapp.com/" target="_blank">Join Slack</a>

[![Automated-Testing](https://github.com/wp-graphql/wp-graphql-woocommerce/workflows/continuous_integration/badge.svg)](https://github.com/wp-graphql/wp-graphql-woocommerce/actions?query=workflow%3A%22Automated-Testing%22) [![Coding-Standards](https://github.com/wp-graphql/wp-graphql-woocommerce/workflows/lint_code/badge.svg)](https://github.com/wp-graphql/wp-graphql-woocommerce/actions?query=workflow%3A%22Coding-Standards%22) [![Coverage Status](https://coveralls.io/repos/github/wp-graphql/wp-graphql-woocommerce/badge.svg?branch=develop)](https://coveralls.io/github/wp-graphql/wp-graphql-woocommerce?branch=develop) [![Financial Contributors on Open Collective](https://opencollective.com/woographql/all/badge.svg?label=financial+contributors)](https://opencollective.com/woographql)
[![Automated Testing](https://github.com/wp-graphql/wp-graphql-woocommerce/workflows/continuous_integration/badge.svg)](https://github.com/wp-graphql/wp-graphql-woocommerce/actions?query=workflow%3A%22Automated-Testing%22) [![Coding Standards](https://github.com/wp-graphql/wp-graphql-woocommerce/workflows/lint_code/badge.svg)](https://github.com/wp-graphql/wp-graphql-woocommerce/actions?query=workflow%3A%22Coding-Standards%22) [![Coverage Status](https://coveralls.io/repos/github/wp-graphql/wp-graphql-woocommerce/badge.svg?branch=develop)](https://coveralls.io/github/wp-graphql/wp-graphql-woocommerce?branch=develop) [![Financial Contributors on Open Collective](https://opencollective.com/woographql/all/badge.svg?label=financial+contributors)](https://opencollective.com/woographql)

## Quick Install

Expand Down
48 changes: 41 additions & 7 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
set +u

# Ensure mysql is loaded
wait-for-it ${DB_HOST}:${DB_PORT} --timeout=300 -- echo "Application database is operationally..."
wait-for-it -s -t 300 ${DB_HOST}:${DB_PORT} -- echo "Application database is operationally..."

# Setup tester scripts.
cp $PROJECT_DIR/bin/setup-database.sh setup-database.sh
chmod 755 /var/www/html/setup-database.sh
if [ ! -f $WP_ROOT_FOLDER/setup-database.sh ]; then
ln -s $PROJECT_DIR/bin/setup-database.sh $WP_ROOT_FOLDER/setup-database.sh
chmod +x $WP_ROOT_FOLDER/setup-database.sh
fi

# Update our domain to just be the docker container's IP address
export WORDPRESS_DOMAIN=$( hostname -i )
export WORDPRESS_DOMAIN=${WORDPRESS_DOMAIN-$( hostname -i )}
export WORDPRESS_URL="http://$WORDPRESS_DOMAIN"
echo "WORDPRESS_DOMAIN=$WORDPRESS_DOMAIN" >> .env
echo "WORDPRESS_URL=$WORDPRESS_URL" >> .env
echo $WORDPRESS_URL

# Config WordPress
if [ -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
Expand Down Expand Up @@ -56,6 +59,30 @@ wp-graphql wp-graphql-jwt-authentication \
wp-graphql-woocommerce \
--allow-root

# Download c3 for testing.
if [ ! -f "$PROJECT_DIR/c3.php" ]; then
echo "Downloading Codeception's c3.php..."
curl -L 'https://raw.github.com/Codeception/c3/2.0/c3.php' > "$PROJECT_DIR/c3.php"
fi

if ! wp config has GRAPHQL_JWT_AUTH_SECRET_KEY --allow-root; then
echo "Adding WPGraphQL-JWT-Authentication salt..."
wp config set GRAPHQL_JWT_AUTH_SECRET_KEY 'test' --allow-root
fi

if ! wp config has GRAPHQL_WOOCOMMERCE_SECRET_KEY --allow-root; then
echo "Adding WooGraphQL JWT Session Handler salt..."
wp config set GRAPHQL_WOOCOMMERCE_SECRET_KEY 'test' --allow-root
fi

if wp config has GRAPHQL_DEBUG --allow-root; then
echo "Setting GRAPHQL_DEBUG flag"
wp config delete GRAPHQL_DEBUG --allow-root
fi
if [[ -n "$GRAPHQL_DEBUG" ]]; then
wp config set GRAPHQL_DEBUG $GRAPHQL_DEBUG --allow-root
fi

if [[ -n "$IMPORT_WC_PRODUCTS" ]]; then
echo "Installing & Activating WordPress Importer..."
wp plugin install wordpress-importer --activate --allow-root
Expand Down Expand Up @@ -84,10 +111,17 @@ wp db export "${PROJECT_DIR}/local/db/app_db.sql" \
--skip-themes \
--allow-root

# Create the "uploads" directory and set public permissions.
if [ ! -d "wp-content/uploads" ]; then
mkdir wp-content/uploads
fi
chmod 777 -R wp-content/uploads

if [ -n "$RUNNING_TEST_STANDALONE" ]; then
service apache2 start
fi

echo "Setup complete!!!"
echo "WordPress app located at $WORDPRESS_URL";

# Make the "uploads" directory unrestricted.
chmod 777 -R wp-content/uploads

exec "$@"
26 changes: 21 additions & 5 deletions bin/install-test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ DB_HOST=${DB_HOST-localhost}
DB_PASS=${DB_PASSWORD-""}
WP_VERSION=${WP_VERSION-latest}
PROJECT_ROOT_DIR=$(pwd)
WP_CORE_DIR=${WP_CORE_DIR-local/public}
PLUGINS_DIR=${PLUGINS_DIR-"$WP_CORE_DIR/wp-content/plugins"}
MUPLUGINS_DIR=${MUPLUGINS_DIR-"$WP_CORE_DIR/wp-content/mu-plugins"}
THEMES_DIR=${THEMES_DIR-"$WP_CORE_DIR/wp-content/themes"}
WP_CORE_DIR=${WP_CORE_DIR:-local/public}
PLUGINS_DIR=${PLUGINS_DIR:-"$WP_CORE_DIR/wp-content/plugins"}
MUPLUGINS_DIR=${MUPLUGINS_DIR:-"$WP_CORE_DIR/wp-content/mu-plugins"}
THEMES_DIR=${THEMES_DIR:-"$WP_CORE_DIR/wp-content/themes"}
SKIP_DB_CREATE=${SKIP_DB_CREATE-false}

install_wordpress_and_codeception() {
if [ -d $WP_CORE_DIR ]; then
echo "Wordpress already installed."
return;
fi

Expand All @@ -49,6 +50,7 @@ install_wordpress_and_codeception() {

install_db() {
if [ ${SKIP_DB_CREATE} = "true" ]; then
echo "Skipping database creation..."
return 0
fi

Expand Down Expand Up @@ -77,18 +79,31 @@ install_db() {


configure_wordpress() {
if [ ${SKIP_WP_SETUP} = "true" ]; then
echo "Skipping WordPress setup..."
return 0
fi

cd $WP_CORE_DIR

echo "Setting up WordPress..."
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true
wp core install --url=wp.test --title="WooGraphQL Tests" --admin_user=admin --admin_password=password --admin_email=admin@woographql.local
wp rewrite structure '/%year%/%monthnum%/%postname%/'
}

setup_plugin() {
if [ ${SKIP_WP_SETUP} = "true" ]; then
echo "Skipping WooGraphQL installation..."
return 0
fi

# Move to project root directory
cd $PROJECT_ROOT_DIR

# Add this repo as a plugin to the repo
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce ]; then
echo "Installing WooGraphQL..."
ln -s $PROJECT_ROOT_DIR $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce
fi

Expand All @@ -106,7 +121,8 @@ setup_plugin() {
mkdir ${PROJECT_ROOT_DIR}/local/db
fi
if [ -f "$PROJECT_ROOT_DIR/local/db/app_db.sql" ]; then
rm ${PROJECT_ROOT_DIR}/local/db/app_db.sql
echo "Deleting old DB dump..."
rm -rf ${PROJECT_ROOT_DIR}/local/db/app_db.sql
fi

wp db export ${PROJECT_ROOT_DIR}/local/db/app_db.sql
Expand Down
85 changes: 0 additions & 85 deletions bin/run-docker.sh

This file was deleted.

Loading

0 comments on commit b8d913e

Please sign in to comment.