Skip to content

Commit

Permalink
updating docker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mngi-arogers committed Nov 17, 2018
1 parent e0f7738 commit 9a84400
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 54 deletions.
4 changes: 4 additions & 0 deletions .env
@@ -0,0 +1,4 @@
# Docker image settings to be shared by various Docker tasks. These values can be overridden with shell values.
MYSQL_DOCKER_IMAGE=mariadb:10.2.18-bionic
WP_VERSION=4.9.8
PHP_VERSION=7.2
22 changes: 17 additions & 5 deletions Dockerfile
Expand Up @@ -4,14 +4,16 @@ ARG DESIRED_PHP_VERSION
ARG BASE_DOCKER_IMAGE="wordpress:${DESIRED_WP_VERSION}-php${DESIRED_PHP_VERSION}-apache"

# -------------------- STAGE ---------------
FROM php:${DESIRED_PHP_VERSION} as php-composer-files
# This contains PHP Composer executable
FROM ${BASE_DOCKER_IMAGE} as php-composer-files

# Install composer
RUN curl -Ls 'https://raw.githubusercontent.com/composer/getcomposer.org/4d2ef40109bfbec0f9b8b39f12f260fb6e80befa/web/installer' | php -- --quiet \
&& chmod +x composer.phar \
&& mv composer.phar /usr/local/bin/composer

# -------------------- STAGE ---------------
# This contains project files after "composer install" has been run.
FROM ${BASE_DOCKER_IMAGE} as project-files

# Add PHP Composer
Expand Down Expand Up @@ -39,7 +41,8 @@ RUN rm -rf /tmp/project/composer.* /tmp/project/vendor \
RUN chown -R 'www-data:www-data' /project

# -------------------- STAGE ---------------
FROM ${BASE_DOCKER_IMAGE} as wordpress-sut-environment
# This is for a container that acts as a Wordpress "system under test" (SUT) instance that has Code Coverage support
FROM ${BASE_DOCKER_IMAGE} as wordpress-sut-code-coverage

COPY --chown='www-data:www-data' --from='project-files' /project/ /usr/src/wordpress/wp-content/plugins/wp-graphql/

Expand All @@ -48,7 +51,8 @@ RUN if echo "${PHP_VERSION}" | grep '^7.'; then pecl install xdebug; docker-php-
&& curl -L 'https://raw.github.com/Codeception/c3/2.0/c3.php' > /usr/src/wordpress/wp-content/plugins/wp-graphql/c3.php

# -------------------- STAGE ---------------
FROM ${BASE_DOCKER_IMAGE} as base-tester-environment
# This is a base image for test-related images
FROM ${BASE_DOCKER_IMAGE} as base-tester

ENV PRISTINE_WP_DIR=/usr/src/wordpress/ \
WP_TEST_CORE_DIR=/tmp/wordpress/ \
Expand Down Expand Up @@ -80,7 +84,8 @@ COPY docker-entrypoints/*.sh /usr/local/bin/
USER www-data

# -------------------- STAGE ---------------
FROM base-tester-environment as tester-environment
# This is for the container that initiates the tests.
FROM base-tester as tester

RUN mkdir "${WP_TEST_CORE_DIR}/wp-content/plugins/wp-graphql"

Expand All @@ -89,8 +94,11 @@ WORKDIR "${WP_TEST_CORE_DIR}/wp-content/plugins/wp-graphql"
# Add plugin code to the WordPress test framework
COPY --chown='www-data:www-data' --from='project-files' /project/ "${WP_TEST_CORE_DIR}/wp-content/plugins/wp-graphql"

ENTRYPOINT [ "docker-entrypoint.tests.sh" ]

# -------------------- STAGE ---------------
FROM base-tester-environment as tester-shell-environment
# This allows developers to log into a fully provisioned container to run tests.
FROM base-tester as tester-shell

# Add PHP Composer
COPY --from='php-composer-files' /usr/local/bin/composer /usr/local/bin/composer
Expand All @@ -101,3 +109,7 @@ RUN ln -s /project "${WP_TEST_CORE_DIR}/wp-content/plugins/wp-graphql" \
&& echo 'composer install && initialize-wp-test-environment.sh' >> /root/.bashrc

WORKDIR /project

# Doing this to prevent the container exiting prematurely. This service needs to hang around for someone to access
# its shell.
ENTRYPOINT [ "sleep", "9999d" ]
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -205,7 +205,6 @@ try these solutions:
```
env PHP_VERSION='7.1' ./run-docker-tests.sh wpunit
env PHP_VERSION='7.1' COVERAGE='true' ./run-docker-tests.sh functional
env PHP_VERSION='7.0' WP_VERSION='4.9.4' ./run-docker-tests.sh acceptance
```
If `COVERAGE='true'` is set, results will appear in `docker-output/`.

Expand Down
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

# The master copy of this file is here: https://github.com/dfmedia/docker-cookbook
# If this script requires changes please notify the maintainer(s) of the master copy.

set -e

show_usage() {
Expand Down Expand Up @@ -37,13 +40,6 @@ initialize_env_var() {

readonly DOCKER_COMPOSE_PROJECT_NAME="$(build_docker_name 'docker-compose')"
readonly CONTAINER_NAME="$(build_docker_name 'container')"

echo "Using Docker Compose file: ${DOCKER_COMPOSE_FILE}"
echo "Going to copy data from container path: ${CONTAINER_DATA_PATH}"
echo "Going to copy data to host dir: ${HOST_DATA_PATH}"
echo "Randomly generated project name for Docker Compose: ${DOCKER_COMPOSE_PROJECT_NAME}"
echo "Randomly generated container name for Docker Compose: ${CONTAINER_NAME}"
echo "Params to be passed to 'docker compose up' $@"
}


Expand Down Expand Up @@ -73,7 +69,6 @@ main() {

copy_data_from_docker_container_to_host

echo "Looks like docker compose is exiting with with code: ${exit_code}"
exit $((exit_code))
}

Expand Down
6 changes: 0 additions & 6 deletions docker-tasks/common/env-files/env.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docker-tasks/run-local-app/docker-compose.yml
Expand Up @@ -12,7 +12,7 @@ services:
WORDPRESS_DB_PASSWORD: 'testing'
volumes:
- "${PWD}:/var/www/html/wp-content/plugins/wp-graphql:ro"
- ./uploads.txt:/usr/local/etc/php/conf.d/uploads.ini
- './uploads.txt:/usr/local/etc/php/conf.d/uploads.ini:ro'

mysql_test:
image: "${MYSQL_DOCKER_IMAGE}"
Expand Down
8 changes: 2 additions & 6 deletions docker-tasks/run-test-environment/docker-compose.yml
Expand Up @@ -3,8 +3,8 @@ version: "3.4"
services:
main:
build:
context: '../../.'
target: 'tester-shell-environment'
context: '../..'
target: 'tester-shell'
args:
DESIRED_WP_VERSION: "${WP_VERSION}"
DESIRED_PHP_VERSION: "${PHP_VERSION}"
Expand All @@ -19,10 +19,6 @@ services:
# Using "delegated" option to improve disk performance for "Docker for Mac" users:
# https://docs.docker.com/docker-for-mac/osxfs-caching/#delegated
- "${PWD}:/project:delegated"
entrypoint:
# Doing this to prevent the container exiting prematurely. This service needs to hang around for someone to access
# its shell.
[ "sleep", "9999d" ]

wpgraphql.test:
image: "wordpress:${WP_VERSION}-php${PHP_VERSION}-apache"
Expand Down
10 changes: 4 additions & 6 deletions docker-tasks/run-tests/docker-compose.yml
Expand Up @@ -3,8 +3,8 @@ version: "3.4"
services:
main:
build:
context: '../../.'
target: 'tester-environment'
context: '../..'
target: 'tester'
args:
DESIRED_WP_VERSION: "${WP_VERSION}"
DESIRED_PHP_VERSION: "${PHP_VERSION}"
Expand All @@ -19,13 +19,11 @@ services:
WP_VERSION: "${WP_VERSION}"
TEST_TYPE: "${TEST_TYPE}"
COVERAGE: "${COVERAGE}"
entrypoint:
[ "docker-entrypoint.tests.sh" ]

wpgraphql.test:
build:
context: '../../.'
target: 'wordpress-sut-environment'
context: '../..'
target: 'wordpress-sut-code-coverage'
args:
DESIRED_WP_VERSION: "${WP_VERSION}"
DESIRED_PHP_VERSION: "${PHP_VERSION}"
Expand Down
7 changes: 1 addition & 6 deletions run-docker-local-app.sh
@@ -1,16 +1,11 @@
#!/usr/bin/env bash
set -e

source_docker_env() {
source docker-tasks/common/env-files/env.sh
}

run_app() {
env DOCKER_TASK='run-local-app' docker-tasks/run-docker-compose-up.sh --build
env DOCKER_TASK='run-local-app' docker-tasks/bin/run-docker-compose-up.sh --build
}

main() {
source_docker_env
run_app
}

Expand Down
2 changes: 1 addition & 1 deletion run-docker-shell.sh
Expand Up @@ -9,7 +9,7 @@ fi
readonly CONTAINER_ID="${1}"

main() {
sudo docker exec -it "${CONTAINER_ID}" /bin/bash
docker exec -it "${CONTAINER_ID}" /bin/bash
}

main
7 changes: 1 addition & 6 deletions run-docker-test-environment.sh
@@ -1,16 +1,11 @@
#!/usr/bin/env bash
set -e

source_docker_env() {
source docker-tasks/common/env-files/env.sh
}

run_app() {
env DOCKER_TASK='run-test-environment' docker-tasks/run-docker-compose-up.sh --build
env DOCKER_TASK='run-test-environment' docker-tasks/bin/run-docker-compose-up.sh --build
}

main() {
source_docker_env
run_app
}

Expand Down
9 changes: 1 addition & 8 deletions run-docker-tests.sh
Expand Up @@ -9,27 +9,20 @@ fi
readonly TEST_TYPE="${1}"
readonly TEST_RESULTS_DIR="./docker-output/${TEST_TYPE}"

source_docker_env() {
source docker-tasks/common/env-files/env.sh
}

initialize_test_results_dir() {
rm -rf "${TEST_RESULTS_DIR}"
mkdir -p "${TEST_RESULTS_DIR}"
}

run_tests() {
echo "Going to run with WP version: ${WP_VERSION} and PHP version: ${PHP_VERSION}"

env DOCKER_TASK='run-tests' \
CONTAINER_DATA_PATH=/tmp/wordpress/wp-content/plugins/wp-graphql/tests/_output/ \
HOST_DATA_PATH="${TEST_RESULTS_DIR}" \
TEST_TYPE="${TEST_TYPE}" \
docker-tasks/run-docker-compose-up.sh --build --exit-code-from 'main'
docker-tasks/bin/run-docker-compose-up.sh --build --exit-code-from 'main'
}

main() {
source_docker_env
initialize_test_results_dir
run_tests
}
Expand Down

0 comments on commit 9a84400

Please sign in to comment.