Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Provide a Docker image #321

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ php:

services:
- mysql
- docker

addons:
apt:
Expand All @@ -31,6 +32,7 @@ script:
- composer test # Run linters for the wp-dev-lib files.
- composer install --working-dir="tests/composer" # Test Composer integration setup.
- composer test --working-dir="tests/composer" # Test Composer integration pre-commit hook.
- docker-compose --file=docker/wp-dev-lib/docker-compose.test.yml run sut # Test the Docker image.
- cd tests/composer && export DEV_LIB_PATH=vendor/xwp/wp-dev-lib/scripts # We need Bash shell which might not be available in Composer scripts.
- source "$DEV_LIB_PATH/travis.install.sh"
- source "$DEV_LIB_PATH/travis.script.sh"
Expand Down
32 changes: 32 additions & 0 deletions docker/wp-dev-lib/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG WP_PHP_VERSION=7.4
FROM wordpress:php${WP_PHP_VERSION}-fpm

ENV DEBIAN_FRONTEND noninteractive

# Development tooling dependencies.
RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
bash less subversion default-mysql-server default-mysql-client libxml2-utils rsync git zip unzip \
nodejs npm curl \
&& npm install --global npm@latest \
&& rm -rf /var/lib/apt/lists/

# Setup xdebug.
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

# Install Composer.
RUN curl -s https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer

# Keep a copy of our default test config.
COPY config/wp-tests-config.php /tmp/wp-dev-lib/wp-tests-config.php

# Setup a custom entrypoint that bootstraps the environment.
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

VOLUME /tmp/wordpress

ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["php-fpm"]
25 changes: 25 additions & 0 deletions docker/wp-dev-lib/config/wp-tests-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// Ensure this is run only once.
if ( defined( 'ABSPATH' ) ) {
return;
}

define( 'DB_NAME', 'wordpress_test' );
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', 'root' );
define( 'DB_HOST', '127.0.0.1' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

$table_prefix = 'wptests_';

define( 'WP_TESTS_DOMAIN', 'example.org' );
define( 'WP_TESTS_EMAIL', '[email protected]' );
define( 'WP_TESTS_TITLE', 'Test Blog' );

define( 'WP_DEBUG', true );
define( 'WP_PHP_BINARY', 'php' );
define( 'WPLANG', '' );

define( 'ABSPATH', __DIR__ . '/src/' );
16 changes: 16 additions & 0 deletions docker/wp-dev-lib/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Used by Travis and Docker Hub to test the image.
# See https://docs.docker.com/docker-hub/builds/automated-testing/

version: '3.6'

services:

sut:
build: .
working_dir: /var/www/html/tests/composer
volumes:
- ../..:/var/www/html
command: bash -c "composer install && composer test"
environment:
CHECK_SCOPE: all
EMAIL: [email protected]
34 changes: 34 additions & 0 deletions docker/wp-dev-lib/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -ex

export WP_CORE_DIR="${WP_CORE_DIR:-/tmp/wordpress}"
export WP_TESTS_DIR="${WP_TESTS_DIR:-$WP_CORE_DIR/tests/phpunit}"
export WP_SVN_URL="${WP_SVN_URL:-https://develop.svn.wordpress.org/trunk/}"

# Start the MySQL server.
service mysql start

# Ensure we have a password and a fresh database.
# TODO Figure out the ERROR 1045 (28000) error because of the password change.
# TODO Allow custom test DB content.
mysql --user=root --password=root << END
DROP DATABASE IF EXISTS wordpress_test;
CREATE DATABASE wordpress_test;
SET PASSWORD = PASSWORD('root');
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
END

# Ensure we have the WP core files.
if [ ! -d /tmp/wordpress/tests ]; then
svn export --force "$WP_SVN_URL" /tmp/wordpress
fi

# Ensure we have a config file to work with.
if [ ! -f /tmp/wordpress/wp-tests-config.php ]; then
cp /tmp/wp-dev-lib/wp-tests-config.php /tmp/wordpress/wp-tests-config.php
fi

# Run the command passed to this container.
exec "$@"
3 changes: 3 additions & 0 deletions docker/wp-dev-lib/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# xwpco/wp-dev-lib

This is a self-contained Docker image for running [`wp-dev-lib`](https://github.com/xwp/wp-dev-lib) tasks with all the required services and software dependencies.