diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 8e34420..588c58b 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -8,6 +8,7 @@ on: pull_request: branches: - master + - release/** # Also trigger on page_build, as well as release created events page_build: release: @@ -19,14 +20,13 @@ jobs: name: Build & Test # This job runs on Linux runs-on: ubuntu-latest - env: - distro: apache strategy: fail-fast: false matrix: os: [stretch, buster] php: [7.2, 7.3, 7.4] framework: [3, 4] + distro: [apache, fpm, cli] exclude: - os: stretch php: 7.4 @@ -39,20 +39,10 @@ jobs: uses: actions/checkout@v2 - name: Pull Docker images - run: docker-compose -f docker-compose.test.yml pull + run: docker-compose pull - - name: Docker Caching - uses: satackey/action-docker-layer-caching@v0.0.5 - with: - key: docker-cache-v2-${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }}-{hash} - restore-keys: | - docker-cache-v2-${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }}- - - - name: Build Images - env: - BUILD_DIR: ./src/${{ matrix.php }}/${{ env.distro }}/${{ matrix.os }} - IMAGE: brettt89/silverstripe-web:${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }} - run: docker-compose -f docker-compose.test.yml build + - name: Build Image + run: ./build/build-image.sh ${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }} - name: Get Composer Cache Directory id: composer-data @@ -71,19 +61,22 @@ jobs: env: FRAMEWORK: ${{ matrix.framework }} COMPOSER_HOME: ${{ steps.composer-data.outputs.dir }} - run: docker-compose -f docker-compose.test.yml run create-project + run: docker-compose run create-project - name: Install Silverstripe test project env: COMPOSER_HOME: ${{ steps.composer-data.outputs.dir }} - run: docker-compose -f docker-compose.test.yml run install-project + run: docker-compose run install-project - name: Run tests env: - BUILD_DIR: ./src/${{ matrix.php }}/${{ env.distro }}/${{ matrix.os }} - IMAGE: brettt89/silverstripe-web:${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }} - DISTRO: ${{ env.distro }} - run: docker-compose -f docker-compose.test.yml run sut + TAG: ${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }} + run: docker-compose run sut + + - name: The job has failed + if: ${{ failure() }} + run: | + docker-compose logs # Legacy PHP 5.6 and 7.1 tests build_legacy: @@ -91,13 +84,12 @@ jobs: name: Legacy Build & Test # This job runs on Linux runs-on: ubuntu-latest - env: - distro: apache strategy: matrix: os: [jessie, stretch, buster] php: [5.6, 7.1] framework: [3, 4] + distro: [apache, fpm, cli] exclude: - os: buster php: 5.6 @@ -108,20 +100,10 @@ jobs: uses: actions/checkout@v2 - name: Pull Docker images - run: docker-compose -f docker-compose.test.yml pull + run: docker-compose pull - - name: Docker Caching - uses: satackey/action-docker-layer-caching@v0.0.5 - with: - key: docker-cache-v2-${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }}-{hash} - restore-keys: | - docker-cache-v2-${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }}- - - - name: Build Images - env: - BUILD_DIR: ./src/${{ matrix.php }}/${{ env.distro }}/${{ matrix.os }} - IMAGE: brettt89/silverstripe-web:${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }} - run: docker-compose -f docker-compose.test.yml build + - name: Build Image + run: ./build/build-image.sh ${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }} - name: Get Composer Cache Directory id: composer-data @@ -134,22 +116,25 @@ jobs: path: ${{ steps.composer-data.outputs.dir }} key: ${{ runner.os }}-composer-${{ matrix.framework }}-${{ matrix.php }} restore-keys: | - ${{ runner.os }}-composer-${{ matrix.framework }} + ${{ runner.os }}-composer-${{ matrix.framework }}- - name: Create Silverstripe ${{ matrix.framework }} test project env: FRAMEWORK: ${{ matrix.framework }} COMPOSER_HOME: ${{ steps.composer-data.outputs.dir }} - run: docker-compose -f docker-compose.test.yml run create-project + run: docker-compose run create-project - name: Install Silverstripe test project env: COMPOSER_HOME: ${{ steps.composer-data.outputs.dir }} - run: docker-compose -f docker-compose.test.yml run install-project + run: docker-compose run install-project - name: Run tests env: - BUILD_DIR: ./src/${{ matrix.php }}/${{ env.distro }}/${{ matrix.os }} - IMAGE: brettt89/silverstripe-web:${{ matrix.php }}-${{ env.distro }}-${{ matrix.os }} - DISTRO: ${{ env.distro }} - run: docker-compose -f docker-compose.test.yml run sut \ No newline at end of file + TAG: ${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }} + run: docker-compose run sut + + - name: The job has failed + if: ${{ failure() }} + run: | + docker-compose logs diff --git a/.travis.yml.bak b/.travis.yml.bak deleted file mode 100644 index 5946195..0000000 --- a/.travis.yml.bak +++ /dev/null @@ -1,115 +0,0 @@ -language: php -dist: xenial -os: linux -services: - - docker - -env: - - FRAMEWORK=3 DISTRO=apache PHP=5.6 PLATFORM=jessie - - FRAMEWORK=3 DISTRO=apache PHP=5.6 PLATFORM=stretch - - - FRAMEWORK=3 DISTRO=fpm PHP=5.6 PLATFORM=jessie - - FRAMEWORK=3 DISTRO=fpm PHP=5.6 PLATFORM=stretch - - - FRAMEWORK=3 DISTRO=cli PHP=5.6 PLATFORM=jessie - - FRAMEWORK=3 DISTRO=cli PHP=5.6 PLATFORM=stretch - - - FRAMEWORK=3 DISTRO=apache PHP=7.1 PLATFORM=jessie - - FRAMEWORK=3 DISTRO=apache PHP=7.1 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=apache PHP=7.1 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=fpm PHP=7.1 PLATFORM=jessie - - FRAMEWORK=3 DISTRO=fpm PHP=7.1 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=fpm PHP=7.1 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=cli PHP=7.1 PLATFORM=jessie - - FRAMEWORK=3 DISTRO=cli PHP=7.1 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=cli PHP=7.1 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=apache PHP=7.1 PLATFORM=jessie - - FRAMEWORK=4 DISTRO=apache PHP=7.1 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=apache PHP=7.1 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=fpm PHP=7.1 PLATFORM=jessie - - FRAMEWORK=4 DISTRO=fpm PHP=7.1 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=fpm PHP=7.1 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=cli PHP=7.1 PLATFORM=jessie - - FRAMEWORK=4 DISTRO=cli PHP=7.1 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=cli PHP=7.1 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=apache PHP=7.2 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=apache PHP=7.2 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=fpm PHP=7.2 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=fpm PHP=7.2 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=cli PHP=7.2 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=cli PHP=7.2 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=apache PHP=7.2 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=apache PHP=7.2 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=fpm PHP=7.2 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=fpm PHP=7.2 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=cli PHP=7.2 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=cli PHP=7.2 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=apache PHP=7.3 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=apache PHP=7.3 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=fpm PHP=7.3 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=fpm PHP=7.3 PLATFORM=buster - - - FRAMEWORK=3 DISTRO=cli PHP=7.3 PLATFORM=stretch - - FRAMEWORK=3 DISTRO=cli PHP=7.3 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=apache PHP=7.3 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=apache PHP=7.3 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=fpm PHP=7.3 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=fpm PHP=7.3 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=cli PHP=7.3 PLATFORM=stretch - - FRAMEWORK=4 DISTRO=cli PHP=7.3 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=apache PHP=7.4 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=fpm PHP=7.4 PLATFORM=buster - - - FRAMEWORK=4 DISTRO=cli PHP=7.4 PLATFORM=buster - -cache: - directories: - - ~/docker_images - - $HOME/.composer/cache/files - -before_install: - - docker load -i ~/docker_images/images-${PHP}-${DISTRO}-${PLATFORM}.tar || true - -before_cache: - - docker save -o ~/docker_images/images-${PHP}-${DISTRO}-${PLATFORM}.tar $(docker images brettt89/silverstripe-web -q) - -install: - - docker run -d --name database --health-cmd='mysqladmin ping --silent' --env MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:5.7 - - composer create-project silverstripe/installer ~/site ^${FRAMEWORK} - - cp examples/_ss_environment.php ~/site/_ss_environment.php - - cp examples/.env ~/site/.env - -before_script: - - env | sort - - cd "src/${PHP}/${DISTRO}/${PLATFORM}" - - image="brettt89/silverstripe-web:${PHP}-${DISTRO}-${PLATFORM}" - -script: - - travis_retry docker build -t "$image" . - - docker run -d --name web -p 80:80 --link database "$image" - - docker cp ~/site/. web:/var/www/html - - docker exec web chown -R www-data:www-data /var/www/html - - while [ "$(docker inspect -f '{{.State.Health.Status}}' database)" != "healthy" ]; do sleep 1; done - - travis_retry wget "http://localhost/dev/build" - - docker logs web - -after_script: - - docker images diff --git a/LICENSE b/LICENSE index d9112c7..fde9b2e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017 Brett Tasker +Copyright (c) 2020 Brett Tasker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index acd3fe9..df65d6f 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,66 @@ export LOG_LEVEL := $(findstring s,$(word 1, $(MAKEFLAGS))) -ARG=$(filter-out $@,$(MAKECMDGOALS)) +ARG = $(filter-out $@,$(MAKECMDGOALS)) +TAG = $(if $(filter %,$(ARG)),$(ARG),7.4-apache-buster) -.PHONY: all build clean $(ARG) +ifndef FRAMEWORK +FRAMEWORK = 4 +endif + +.PHONY: all build build-image new-test create-project install-project test-build-image test clean $(ARG) all: - @echo "Silverstripe Web - Docker image" + @echo "Silverstripe Web - Docker image builder" @echo @echo "Basic Commands" - @echo " build Build and tag all images. Filter using on tag structure." - @echo " e.g. "7.4" for php7.4 builds, or "buster" for all buster builds." - @echo " clean Delete all image tags / cache using." + @echo " build Build and tag all images. Filter using on tag structure." + @echo " build-image Build and tag specific image." + @echo + @echo "Test Commands" + @echo " new-test Start a new test using , Default: 7.4-apache-buster." + @echo " test Execute tests, assumes project has been build." + @echo " clean Delete all test data." + @echo + @echo "Advanced Test Commands" + @echo " create-project Create new Silverstripe Project". + @echo " Environment variable FRAMEWORK=3 to change version" + @echo " install-project Install project dependancies" + @echo " test-build-image Test the image has been built locally" + @echo " build-test Build 'sut' test image, used for running tests" @echo + @echo "Parameters" + @echo " Regex for matching against tag. e.g. '7.4'" + @echo " Tag to build/test. e.g. '5.6-apache-jessie'" build: - @./build.sh $(filter-out $@,$(MAKECMDGOALS)) + ./build/build-regex.sh $(ARG) + +build-image: + ./build/build-image.sh $(TAG) + +new-test: + @echo "Running new test" + @echo " Tag: $(TAG)" + @echo + @$(MAKE) --quiet clean + @$(MAKE) --quiet build-image $(TAG) + @$(MAKE) --quiet test-build-image $(TAG) + @FRAMEWORK=$(FRAMEWORK) $(MAKE) --quiet create-project $(TAG) + @$(MAKE) --quiet install-project $(TAG) + @$(MAKE) --quiet test $(TAG) + +create-project: + TAG=$(TAG) FRAMEWORK=$(FRAMEWORK) docker-compose run create-project + +install-project: + TAG=$(TAG) docker-compose run install-project + +test-build-image: + TAG=${TAG} docker-compose build + +build-test: + TAG=$(TAG) docker-compose build sut + +test: + TAG=$(TAG) docker-compose run sut clean: - @docker rmi $(docker images | grep 'silversripe-web') $a \ No newline at end of file + docker-compose down --volume diff --git a/README.md b/README.md index ffec233..713d6b8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -[![Build Status](https://travis-ci.org/brettt89/silverstripe-web.svg?branch=master)](https://travis-ci.org/brettt89/silverstripe-web) - # Supported tags and respective `Dockerfile` links - [`7.4-apache-buster`, `7.4-apache`, `7.4`, `latest` (*7.4/apache/buster/Dockerfile*)](https://github.com/brettt89/silverstripe-web/blob/master/7.4/apache/buster/Dockerfile) - [`7.3-apache-buster`, `7.3-apache`, `7.3` (*7.3/apache/buster/Dockerfile*)](https://github.com/brettt89/silverstripe-web/blob/master/7.3/apache/buster/Dockerfile) @@ -53,42 +51,18 @@ This image comes pre-packaged with the following additional PHP Extensions # How to use this image. -## Start a `mysql` server instance - -We name our database `database` so we can link our web container to it. - -Start a `mysql` container for our web server to connect to. - -```bash -docker run -d -p 3306:3306 --name database --env MYSQL_ALLOW_EMPTY_PASSWORD=1 mysql -``` - -_If using for sensitive data, we recommend replacing `MYSQL_ALLOW_EMPTY_PASSWORD=1` with `MYSQL_ROOT_PASSWORD=my-secret-pw`, where `my-secret-pw` is the password to be set for `SS_DATABASE_PASSWORD` in your `_ss_environment.php` or `.env` file._ - -## Start a `brettt89/silverstripe-web` server instance +## Start a `brettt89/silverstripe-web` apache container Start a `brettt89/silverstripe-web` container mounting the folder of your SilverStripe installation (e.g. `/path/to/project`) to `/var/www/html` and linking the `database` container using `--link database`. ```bash -docker run -d -p 80:80 -v /path/to/project:/var/www/html --link database --name project1 brettt89/silverstripe-web +docker run -d -p 80:80 -v /path/to/project:/var/www/html --link database --name project1 brettt89/silverstripe-web:7.3-apache-buster ``` _You will require an `_ss_environment.php` or `.env` file to tell the environment which database to connect to. Examples have been provided in `./example` folder [example](./example/_ss_environment.php)_ _By linking the database via `--link database`, we can connect to it from the web server using `database` as the hostname (e.g. `SS_DATABASE_SERVER=database`)._ -## Build the database - -Run a dev buid via http://localhost/dev/build for via CLI by using `docker exec` - -```bash -docker exec project1 php ./vendor/silverstripe/framework/cli-script.php dev/build -``` - -## Access your website - -You should then be able to access your installation via http://localhost/. - # Installing additional dependancies If you are wanting to add additional PHP extensions or other changes, we recommend using a `Dockerfile` to extend this image and customize to suit. @@ -106,6 +80,8 @@ RUN yes | pecl install xdebug \ COPY php.ini /usr/local/etc/php/ # Copy current directory (website) directly to /var/www/html # This can sometimes provide a performance improvement over mounting with volumes. +# +# $DOCUMENT_ROOT by default = /var/www/html. You can change this ENV variable to change the mount on the image COPY . $DOCUMENT_ROOT ``` @@ -132,7 +108,3 @@ If you have any problems with or questions about this image, please contact us t You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can. Before you start to code, we recommend discussing your plans through a [GitHub issue](https://github.com/brettt89/silverstripe-web/issues), especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing. - -# Credits - - - Franco Springveldt - [https://github.com/fspringveldt](https://github.com/fspringveldt) diff --git a/build.sh b/build.sh deleted file mode 100755 index 19a668b..0000000 --- a/build.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash -set -euo pipefail - -LATEST_PHP_VERSION="7.4" -LATEST_DISTRO="apache" -LATEST_PLATFORM="buster" - -# Legacy support -LEGACY_PLATFORM="jessie" -LEGACY_VERSIONS=("5.6") -PLATFORM_TAGS=("5.6-platform" "7.1-platform") - -IMAGE="brettt89/silverstripe-web" -CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -ROOT_DIR="${CUR_DIR%/}/src" - -# Log Level -# s = Silent -# w = Warnings and Errors -# o = All logs (default) -LOG_LEVEL=${LOG_LEVEL:-o} - -REGEX=${1:-} - -error() { - echo "[Error] ${1:-}" -} - -warn() { - if [ "${LOG_LEVEL}" != "s" ]; then - echo "[Warning] ${1:-}" - fi -} - -info() { - if [ "${LOG_LEVEL}" != "s" ] && [ "${LOG_LEVEL}" != "w" ]; then - echo "[Info] ${1:-}" - fi -} - -elementIn () { - local e match="$1" - shift - for e; do [[ "$e" == "$match" ]] && return 0; done - return 1 -} - -## -# Buld image based on arguments -# -# Parameters -# 1 - PHP version (e.g. 7.4) (optional) -# 2 - Distro (e.g. apache) (optional) -# 3 - Platform (e.g. buster) (optional) -# -# Example -# build_image "7.4" "apache" "buster" # Builds tag "7.4-apache-buster" -build_image() { - ARG_VERSION=${1:-} - ARG_DISTRO=${2:-} - ARG_PLATFORM=${3:-} - - # Parse parameters (if provided) into tag string - TAG="${ARG_VERSION:-latest}-${ARG_DISTRO:-#}-${ARG_PLATFORM:-#}" - TAG=${TAG//-#/} - - if ! [ -z $REGEX ] && ! [[ $TAG =~ $REGEX ]]; then - return 0 - fi - - # Check build directory - BUILD_DIR="${ROOT_DIR%%/}/${ARG_VERSION:-${LATEST_PHP_VERSION}}/${ARG_DISTRO:-${LATEST_DISTRO}}/${ARG_PLATFORM:-${LATEST_PLATFORM}}" - if ! [ -d $BUILD_DIR ] && ! [ -z $ARG_PLATFORM ]; then - warn "Skipping '$BUILD_DIR' is not a valid directory" - return 0 - fi - - # echo 1 | sudo tee /proc/sys/vm/drop_caches > /dev/null - - # Legacy support added for 5.6 that doesn't have buster - elementIn "${ARG_VERSION}" "${LEGACY_VERSIONS[@]}" || true - if [ $? -eq 0 ] && [ ! -f "${BUILD_DIR%/}/Dockerfile" ]; then - BUILD_DIR="${ROOT_DIR%%/}/${ARG_VERSION:-${LATEST_PHP_VERSION}}/${ARG_DISTRO:-${LATEST_DISTRO}}/${ARG_PLATFORM:-${LEGACY_PLATFORM}}" - fi - - # Legacy support for platform builds - elementIn "${TAG}" "${PLATFORM_TAGS[@]}" || true - if [ $? -eq 0 ] && [ ! -f "${BUILD_DIR%/}/Dockerfile" ]; then - BUILD_DIR="${ROOT_DIR%%/}/${ARG_VERSION}/platform" - fi - - # Check directory for Dockerfile and build - if [ -f "${BUILD_DIR%/}/Dockerfile" ]; then - info "Building ${IMAGE}:${TAG}" - docker build -t "${IMAGE}:${TAG}" "${BUILD_DIR%/}" > "build.log" - return 0 - else - error "Unable to find dockerfile for '$TAG', Skipping build" - return 0 - fi -} - -# Check ROOT_DIR to make sure its pointing to a directory -if [ ! -d "$ROOT_DIR" ]; then - error "${ROOT_DIR} is not a directory" - return 1 -fi - -# Build "latest" -build_image - -# Main loop checking folder structure -# - Calls function 'build_image' -for VERSION in ${ROOT_DIR%/}/*/; do - VERSION=${VERSION%/} - if [ ! -d "$VERSION" ]; then continue; fi - build_image ${VERSION##*/} - for DISTRO in ${VERSION}/*/; do - DISTRO=${DISTRO%/} - if [ ! -d $DISTRO ]; then continue; fi - build_image ${VERSION##*/} ${DISTRO##*/} - for PLATFORM in ${DISTRO}/*/; do - PLATFORM=${PLATFORM%/} - if [ ! -d $PLATFORM ]; then continue; fi - build_image ${VERSION##*/} ${DISTRO##*/} ${PLATFORM##*/} - done - done -done - -# Cleanup -rm -f build.log || true - -info "Build completed succesfully" \ No newline at end of file diff --git a/build/build-image.sh b/build/build-image.sh new file mode 100755 index 0000000..44d40eb --- /dev/null +++ b/build/build-image.sh @@ -0,0 +1,58 @@ +#!/bin/bash +set -euo pipefail + +OUTPUT=${OUTPUT:-/dev/stdout} + +IMAGE=${IMAGE-localrepo/silverstripe-web} + +TAG=${1:-7.4-apache-buster} + +TMP_BUILD_DIR=$(mktemp -d) +TMP_DOCKERFILE="${TMP_BUILD_DIR%/}/Dockerfile" + +DOCKER_BUILD_ARGS="--build-arg TAG=${TAG}" + +function add_file() { + local FILE=$1 + local CONTENT="" + if [ -f "${FILE}" ] ; then + CONTENT=$(cat "${FILE}") + printf "%s\n" "${CONTENT}" >> "${TMP_DOCKERFILE}" + fi +} + +function cleanup() { + rm -rf "$TMP_BUILD_DIR" || true +} + +# Remove any old file +rm -f "${TMP_DOCKERFILE}" || true + +if [[ "${TAG}" =~ alpine ]] ; then + TEMPLATE_DIR="src/alpine" +else + TEMPLATE_DIR="src/debian" +fi + +# Add base template (override existing file) +add_file "src/Dockerfile" + +# Add PHP configurations +add_file "${TEMPLATE_DIR}/Dockerfile.php.tpl" + +if [[ "${TAG}" =~ apache ]] ; then + add_file "${TEMPLATE_DIR}/Dockerfile.apache.tpl" +fi + +if [[ "${TAG}" =~ 7.4 ]] ; then + DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS} --build-arg GD_BUILD_ARGS=" +fi + +echo "Building image: '${IMAGE}:${TAG}'" +cat "${TMP_DOCKERFILE}" > "${OUTPUT}" +docker build -t "${IMAGE}:${TAG}" ${DOCKER_BUILD_ARGS} "${TMP_BUILD_DIR%/}" > "${OUTPUT}" + +# If we got this far, then all good. remove log. +rm -f build.log || true + +trap cleanup EXIT \ No newline at end of file diff --git a/build/build-regex.sh b/build/build-regex.sh new file mode 100755 index 0000000..d43e0cb --- /dev/null +++ b/build/build-regex.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -euo pipefail + +REGEX="${1:-}" + +PHP_VERSION_ARRAY=("7.4" "7.3" "7.2") +VARIATION_ARRAY=("apache" "fpm" "cli") +DISTRO_ARRAY=("stretch" "buster") + +LEGACY_PHP_VERSION_ARRAY=("5.6" "7.1") +LEGACY_VARIATION_ARRAY=("apache" "fpm" "cli") +LEGACY_DISTRO_ARRAY=("jessie" "stretch" "buster") + +function build() { + local ARG_VERSION=${1:-} + local ARG_VARIATION=${2:-} + local ARG_DISTRO=${3:-} + + local TAG="${ARG_VERSION:-latest}-${ARG_VARIATION:-#}-${ARG_DISTRO:-#}" + TAG=${TAG%%-#} + + ## If regex is set, then compare this against tag format and skip if not matching + if [[ -n $REGEX ]] && ! [[ "${TAG//-#/}" =~ $REGEX ]]; then + return 0 + fi + + OUTPUT=${OUTPUT:-build.log} ./build/build-image.sh "$TAG" +} + +function loop() { + local -n ARG_VERSION_ARRAY=$1 + local -n ARG_VARIATION_ARRAY=$2 + local -n ARG_DISTRO_ARRAY=$3 + + for VERSION in "${ARG_VERSION_ARRAY[@]}"; do + for VARIATION in "${ARG_VARIATION_ARRAY[@]}"; do + for DISTRO in "${ARG_DISTRO_ARRAY[@]}"; do + ## Skip building 'stretch' with PHP 7.4 + if [ "$VERSION" == "7.4" ] && [ "$DISTRO" == "stretch" ]; then + continue + fi + + if [ "$VERSION" == "5.6" ] && [ "$DISTRO" == "buster" ]; then + continue + fi + + build "$VERSION" "$VARIATION" "$DISTRO" + done + done + done +} + +## Loop over and build images +loop PHP_VERSION_ARRAY VARIATION_ARRAY DISTRO_ARRAY + +## Loop over and build legacy images +loop LEGACY_PHP_VERSION_ARRAY LEGACY_VARIATION_ARRAY LEGACY_DISTRO_ARRAY diff --git a/docker-compose.test.yml b/docker-compose.yml similarity index 56% rename from docker-compose.test.yml rename to docker-compose.yml index 98a8a28..f0e488e 100644 --- a/docker-compose.test.yml +++ b/docker-compose.yml @@ -3,22 +3,38 @@ services: sut: build: context: ./tests - dockerfile: Dockerfile.test + dockerfile: Dockerfile.sut + command: -d depends_on: - silverstripe - database environment: - - DISTRO=${DISTRO:-apache} + - TAG=${TAG:-7.4-apache-buster} + - MOUNT_DIR=${MOUNT_DIR:-/var/www/html} volumes: - codebase:/src silverstripe: - build: ${BUILD_DIR:-./src/7.4/apache/buster} - image: ${IMAGE:-brettt89/silverstripe-web:7.4-apache-buster} + build: + context: ./tests + dockerfile: Dockerfile.test + args: + IMAGE: ${IMAGE:-localrepo/silverstripe-web} + TAG: ${TAG:-7.4-apache-buster} + image: ${IMAGE:-localrepo/silverstripe-web}:${TAG:-7.4-apache-buster} volumes: - codebase:${MOUNT_DIR:-/var/www/html} depends_on: - - database + - database + environment: + - SS_TRUSTED_PROXY_IPS=* + - SS_ENVIRONMENT_TYPE=dev + - SS_DATABASE_SERVER=database + - SS_DATABASE_NAME=SS_mysite + - SS_DATABASE_USERNAME=root + - SS_DATABASE_PASSWORD= + - SS_DEFAULT_ADMIN_USERNAME=admin + - SS_DEFAULT_ADMIN_PASSWORD=password create-project: image: composer diff --git a/examples/.env b/examples/.env deleted file mode 100755 index 48fd997..0000000 --- a/examples/.env +++ /dev/null @@ -1,10 +0,0 @@ -SS_TRUSTED_PROXY_IPS="*" -SS_ENVIRONMENT_TYPE="dev" - -SS_DATABASE_SERVER="database" -SS_DATABASE_NAME="SS_mysite" -SS_DATABASE_USERNAME="root" -SS_DATABASE_PASSWORD="" - -SS_DEFAULT_ADMIN_USERNAME="admin" -SS_DEFAULT_ADMIN_PASSWORD="password" \ No newline at end of file diff --git a/examples/_ss_environment.php b/examples/_ss_environment.php deleted file mode 100644 index da1d835..0000000 --- a/examples/_ss_environment.php +++ /dev/null @@ -1,19 +0,0 @@ - -# -# Description: This configuration is an example of how you can use this image -# -version: '3' -services: - web: - image: brettt89/silverstripe-web - working_dir: /var/www - volumes: - - .:/var/www/html - - database: - image: mysql - volumes: - - db-data:/var/lib/mysql - restart: always - environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=true - -volumes: - db-data: diff --git a/examples/multi-environment.example.yml b/examples/multi-environment.example.yml deleted file mode 100644 index 9c8698d..0000000 --- a/examples/multi-environment.example.yml +++ /dev/null @@ -1,33 +0,0 @@ -# Title: Multi Environment Setup Example -# Author: Brett Tasker -# -# Description: This configuration is an example of how you can use this configuration to run multiple websites at the same time -# -# Note: This configuration requires a network named `my-network` to be pre-setup and nginx-proxy to be runnin on that network -# prior to `running composer up -d` -# -version: '3' -services: - web: - image: brettt89/silverstripe-web - working_dir: /var/www - volumes: - - .:/var/www/html - environment: - - VIRTUAL_HOST=local.dev - - database: - image: mysql - volumes: - - db-data:/var/lib/mysql - restart: always - environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=true - -volumes: - db-data: - -networks: - default: - external: - name: my-network diff --git a/examples/nginx-proxy.example.yml b/examples/nginx-proxy.example.yml deleted file mode 100644 index bb498d6..0000000 --- a/examples/nginx-proxy.example.yml +++ /dev/null @@ -1,32 +0,0 @@ -# Title: Nginx-proxy Environment Setup Example -# Author: Brett Tasker -# -# Description: This configuration is an example of how you can use this configuration to run environment under nginx-proxy -# -version: '3' -services: - nginx-proxy: - image: jwilder/nginx-proxy - ports: - - "80:80" - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - web: - image: brettt89/silverstripe-web - working_dir: /var/www - volumes: - - .:/var/www/html - environment: - - VIRTUAL_HOST=local.dev - - database: - image: mysql - volumes: - - db-data:/var/lib/mysql - restart: always - environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=true - -volumes: - db-data: diff --git a/src/5.6/apache/jessie/Dockerfile b/src/5.6/apache/jessie/Dockerfile deleted file mode 100755 index 496f900..0000000 --- a/src/5.6/apache/jessie/Dockerfile +++ /dev/null @@ -1,72 +0,0 @@ -FROM php:5.6-apache-jessie -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure mysql --with-mysql=mysqlnd && \ - docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysql \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/5.6/apache/stretch/Dockerfile b/src/5.6/apache/stretch/Dockerfile deleted file mode 100755 index a00c440..0000000 --- a/src/5.6/apache/stretch/Dockerfile +++ /dev/null @@ -1,72 +0,0 @@ -FROM php:5.6-apache-stretch -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure mysql --with-mysql=mysqlnd && \ - docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysql \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/5.6/platform/Dockerfile b/src/5.6/platform/Dockerfile deleted file mode 100644 index 4bb341a..0000000 --- a/src/5.6/platform/Dockerfile +++ /dev/null @@ -1,71 +0,0 @@ -FROM php:5.6-apache-jessie -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure mysql --with-mysql=mysqlnd && \ - docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysql \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.1/apache/buster/Dockerfile b/src/7.1/apache/buster/Dockerfile deleted file mode 100755 index 573811d..0000000 --- a/src/7.1/apache/buster/Dockerfile +++ /dev/null @@ -1,69 +0,0 @@ -FROM php:7.1-apache-buster -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.1/apache/jessie/Dockerfile b/src/7.1/apache/jessie/Dockerfile deleted file mode 100755 index 6b57154..0000000 --- a/src/7.1/apache/jessie/Dockerfile +++ /dev/null @@ -1,69 +0,0 @@ -FROM php:7.1-apache-jessie -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.1/apache/stretch/Dockerfile b/src/7.1/apache/stretch/Dockerfile deleted file mode 100755 index 951e17b..0000000 --- a/src/7.1/apache/stretch/Dockerfile +++ /dev/null @@ -1,69 +0,0 @@ -FROM php:7.1-apache-stretch -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.1/platform/Dockerfile b/src/7.1/platform/Dockerfile deleted file mode 100644 index 328274f..0000000 --- a/src/7.1/platform/Dockerfile +++ /dev/null @@ -1,69 +0,0 @@ -FROM php:7.1-apache-jessie -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - libcurl4-openssl-dev \ - libgd-dev \ - libldap2-dev \ - libmcrypt-dev \ - libtidy-dev \ - libxslt-dev \ - zlib1g-dev \ - libicu-dev \ - g++ \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install PHP Extensions -RUN docker-php-ext-configure intl && \ - docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - bcmath \ - intl \ - gd \ - ldap \ - mcrypt \ - mysqli \ - pdo \ - pdo_mysql \ - soap \ - tidy \ - xsl \ - zip - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.2/apache/buster/Dockerfile b/src/7.2/apache/buster/Dockerfile deleted file mode 100755 index 2111bf4..0000000 --- a/src/7.2/apache/buster/Dockerfile +++ /dev/null @@ -1,83 +0,0 @@ -FROM php:7.2-apache-buster -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install default PHP Extensions -RUN docker-php-ext-install -j$(nproc) \ - bcmath \ - mysqli \ - pdo \ - pdo_mysql - - -# Install Intl, LDAP, GD, SOAP, Tidy, XSL, Zip PHP Extensions -RUN apt-get update -y && apt-get install -y \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libgd-dev \ - libzip-dev \ - libtidy-dev \ - libxml2-dev \ - libxslt-dev \ - --no-install-recommends && \ - apt-mark auto \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libxml2-dev \ - libxslt-dev && \ - docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - intl \ - ldap \ - gd \ - soap \ - tidy \ - xsl \ - zip && \ - apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.2/apache/stretch/Dockerfile b/src/7.2/apache/stretch/Dockerfile deleted file mode 100755 index 2ea0484..0000000 --- a/src/7.2/apache/stretch/Dockerfile +++ /dev/null @@ -1,83 +0,0 @@ -FROM php:7.2-apache-stretch -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install default PHP Extensions -RUN docker-php-ext-install -j$(nproc) \ - bcmath \ - mysqli \ - pdo \ - pdo_mysql - - -# Install Intl, LDAP, GD, SOAP, Tidy, XSL, Zip PHP Extensions -RUN apt-get update -y && apt-get install -y \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libgd-dev \ - libzip-dev \ - libtidy-dev \ - libxml2-dev \ - libxslt-dev \ - --no-install-recommends && \ - apt-mark auto \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libxml2-dev \ - libxslt-dev && \ - docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - intl \ - ldap \ - gd \ - soap \ - tidy \ - xsl \ - zip && \ - apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.3/apache/buster/Dockerfile b/src/7.3/apache/buster/Dockerfile deleted file mode 100755 index 602b289..0000000 --- a/src/7.3/apache/buster/Dockerfile +++ /dev/null @@ -1,83 +0,0 @@ -FROM php:7.3-apache-buster -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install default PHP Extensions -RUN docker-php-ext-install -j$(nproc) \ - bcmath \ - mysqli \ - pdo \ - pdo_mysql - - -# Install Intl, LDAP, GD, SOAP, Tidy, XSL, Zip PHP Extensions -RUN apt-get update -y && apt-get install -y \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libgd-dev \ - libzip-dev \ - libtidy-dev \ - libxml2-dev \ - libxslt-dev \ - --no-install-recommends && \ - apt-mark auto \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libxml2-dev \ - libxslt-dev && \ - docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - intl \ - ldap \ - gd \ - soap \ - tidy \ - xsl \ - zip && \ - apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.3/apache/stretch/Dockerfile b/src/7.3/apache/stretch/Dockerfile deleted file mode 100755 index 38462f9..0000000 --- a/src/7.3/apache/stretch/Dockerfile +++ /dev/null @@ -1,82 +0,0 @@ -FROM php:7.3-apache-stretch -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install default PHP Extensions -RUN docker-php-ext-install -j$(nproc) \ - bcmath \ - mysqli \ - pdo \ - pdo_mysql - -# Install Intl, LDAP, GD, SOAP, Tidy, XSL, Zip PHP Extensions -RUN apt-get update -y && apt-get install -y \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libgd-dev \ - libzip-dev \ - libtidy-dev \ - libxml2-dev \ - libxslt-dev \ - --no-install-recommends && \ - apt-mark auto \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libxml2-dev \ - libxslt-dev && \ - docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \ - docker-php-ext-install -j$(nproc) \ - intl \ - ldap \ - gd \ - soap \ - tidy \ - xsl \ - zip && \ - apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/7.4/apache/buster/Dockerfile b/src/7.4/apache/buster/Dockerfile deleted file mode 100755 index d9a4453..0000000 --- a/src/7.4/apache/buster/Dockerfile +++ /dev/null @@ -1,83 +0,0 @@ -FROM php:7.4-apache-buster -MAINTAINER Brett Tasker "" -ENV DEBIAN_FRONTEND=noninteractive - -# Install components -RUN apt-get update -y && apt-get install -y \ - curl \ - git-core \ - gzip \ - openssh-client \ - unzip \ - zip \ - --no-install-recommends && \ - apt-get autoremove -y && \ - rm -rf /var/lib/apt/lists/* - -# Install default PHP Extensions -RUN docker-php-ext-install -j$(nproc) \ - bcmath \ - mysqli \ - pdo \ - pdo_mysql - - -# Install Intl, LDAP, GD, SOAP, Tidy, XSL, Zip PHP Extensions -RUN apt-get update -y && apt-get install -y \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libgd-dev \ - libzip-dev \ - libtidy-dev \ - libxml2-dev \ - libxslt-dev \ - --no-install-recommends && \ - apt-mark auto \ - zlib1g-dev \ - libicu-dev \ - g++ \ - libldap2-dev \ - libxml2-dev \ - libxslt-dev && \ - docker-php-ext-configure intl && \ - docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - docker-php-ext-configure gd && \ - docker-php-ext-install -j$(nproc) \ - intl \ - ldap \ - gd \ - soap \ - tidy \ - xsl \ - zip && \ - apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ - rm -rf /var/lib/apt/lists/* - -# Apache + xdebug configuration -ENV DOCUMENT_ROOT /var/www/html -RUN { \ - echo ''; \ - echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ - echo ' LogLevel warn'; \ - echo ' ServerSignature Off'; \ - echo ' '; \ - echo ' Options +FollowSymLinks'; \ - echo ' Options -ExecCGI -Includes -Indexes'; \ - echo ' AllowOverride all'; \ - echo; \ - echo ' Require all granted'; \ - echo ' '; \ - echo ' '; \ - echo ' php_flag engine off'; \ - echo ' '; \ - echo; \ - echo ' IncludeOptional sites-available/000-default.local*'; \ - echo ''; \ - } | tee /etc/apache2/sites-available/000-default.conf - -RUN echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ - echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ - echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini && \ - a2enmod rewrite expires remoteip cgid diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..e34ab99 --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,5 @@ +ARG TAG + +FROM php:$TAG +MAINTAINER Brett Tasker "" +ENV DEBIAN_FRONTEND=noninteractive diff --git a/src/debian/Dockerfile.apache.tpl b/src/debian/Dockerfile.apache.tpl new file mode 100644 index 0000000..7d0e487 --- /dev/null +++ b/src/debian/Dockerfile.apache.tpl @@ -0,0 +1,23 @@ +# Apache configuration +ENV DOCUMENT_ROOT /var/www/html +RUN { \ + echo ''; \ + echo ' DocumentRoot ${DOCUMENT_ROOT}'; \ + echo ' LogLevel warn'; \ + echo ' ServerSignature Off'; \ + echo ' '; \ + echo ' Options +FollowSymLinks'; \ + echo ' Options -ExecCGI -Includes -Indexes'; \ + echo ' AllowOverride all'; \ + echo; \ + echo ' Require all granted'; \ + echo ' '; \ + echo ' '; \ + echo ' php_flag engine off'; \ + echo ' '; \ + echo; \ + echo ' IncludeOptional sites-available/000-default.local*'; \ + echo ''; \ + } | tee /etc/apache2/sites-available/000-default.conf && \ + echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf && \ + a2enmod rewrite expires remoteip cgid diff --git a/src/debian/Dockerfile.php.tpl b/src/debian/Dockerfile.php.tpl new file mode 100644 index 0000000..55c2c6f --- /dev/null +++ b/src/debian/Dockerfile.php.tpl @@ -0,0 +1,44 @@ +# Install default PHP Extensions +RUN docker-php-ext-install -j$(nproc) \ + bcmath \ + mysqli \ + pdo \ + pdo_mysql + +# Install Intl, LDAP, GD, SOAP, Tidy, XSL, Zip PHP Extensions +ARG GD_BUILD_ARGS="--with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/" +RUN apt-get update -y && apt-get install -y \ + zlib1g-dev \ + libicu-dev \ + g++ \ + libldap2-dev \ + libgd-dev \ + libzip-dev \ + libtidy-dev \ + libxml2-dev \ + libxslt-dev \ + zip \ + --no-install-recommends && \ + apt-mark auto \ + zlib1g-dev \ + g++ \ + libldap2-dev \ + libxml2-dev \ + libxslt-dev && \ + docker-php-ext-configure intl && \ + docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ + docker-php-ext-configure gd ${GD_BUILD_ARGS:-}&& \ + docker-php-ext-install -j$(nproc) \ + intl \ + ldap \ + gd \ + soap \ + tidy \ + xsl \ + zip && \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ + rm -rf /var/lib/apt/lists/* + +# Pipe errors to stdErr +RUN echo "date.timezone = Pacific/Auckland" > /usr/local/etc/php/conf.d/timezone.ini && \ + echo "log_errors = On\nerror_log = /dev/stderr" > /usr/local/etc/php/conf.d/errors.ini \ No newline at end of file diff --git a/tests/Dockerfile.sut b/tests/Dockerfile.sut new file mode 100644 index 0000000..a1b2b26 --- /dev/null +++ b/tests/Dockerfile.sut @@ -0,0 +1,10 @@ +FROM ubuntu:bionic + +RUN sed -i 's/archive.ubuntu.com/ucmirror.canterbury.ac.nz/g' /etc/apt/sources.list +RUN apt-get update && apt-get install -yq --no-install-recommends libfcgi-bin curl netcat lynx && apt-get clean + +WORKDIR /app + +ADD files/ /app/ + +ENTRYPOINT ["bash", "test.sh"] \ No newline at end of file diff --git a/tests/Dockerfile.test b/tests/Dockerfile.test index 5802550..65fc49b 100644 --- a/tests/Dockerfile.test +++ b/tests/Dockerfile.test @@ -1,10 +1,4 @@ -FROM ubuntu:bionic +ARG IMAGE +ARG TAG -RUN sed -i 's/archive.ubuntu.com/ucmirror.canterbury.ac.nz/g' /etc/apt/sources.list -RUN apt-get update && apt-get install -yq --no-install-recommends libfcgi-bin curl netcat lynx && apt-get clean - -WORKDIR /app - -ADD files/ /app/ - -CMD ["bash", "test.sh"] \ No newline at end of file +FROM $IMAGE:$TAG \ No newline at end of file diff --git a/tests/files/.env b/tests/files/.env deleted file mode 100755 index 48fd997..0000000 --- a/tests/files/.env +++ /dev/null @@ -1,10 +0,0 @@ -SS_TRUSTED_PROXY_IPS="*" -SS_ENVIRONMENT_TYPE="dev" - -SS_DATABASE_SERVER="database" -SS_DATABASE_NAME="SS_mysite" -SS_DATABASE_USERNAME="root" -SS_DATABASE_PASSWORD="" - -SS_DEFAULT_ADMIN_USERNAME="admin" -SS_DEFAULT_ADMIN_PASSWORD="password" \ No newline at end of file diff --git a/tests/files/test.sh b/tests/files/test.sh index d391583..6351e80 100644 --- a/tests/files/test.sh +++ b/tests/files/test.sh @@ -1,49 +1,142 @@ #!/bin/bash set -euo pipefail -try_curl() { - local -i max_attempts=5 - local -i attempt_num=1 +REQUEST_URI="/dev/build" +TAG=${TAG:-7.4-apache-buster} + +# Options + +while getopts "d" opt; do + case $opt in + d) + DEBUG=d + ;; + *) + ;; + esac +done + +# Retries a command on failure. +# $1 - the max number of attempts +# $2... - the command to run +error() { + MESSAGE=${1:-Unknown error} + echo "[ERROR] ${MESSAGE}" + exit 1 +} - until RESULT=$(lynx -dump http://silverstripe/dev/build) +warn() { + MESSAGE=$1 + if [ -n "$DEBUG" ]; then + echo "[WARNING] ${MESSAGE}" + fi +} + +info() { + MESSAGE=$1 + if [ -n "$DEBUG" ]; then + echo "[INFO] ${MESSAGE}" + fi +} + +retry() { + local -r -i max_attempts=$1; shift + local -r cmd=$* + local -i attempt_num=1 + until $cmd do if ((attempt_num==max_attempts)) then - echo "Attempt $attempt_num failed and there are no more attempts left!" return 1 else - echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..." sleep $((attempt_num++)) fi done +} + + +try_curl() { + RESULT=$(retry 5 lynx -dump http://silverstripe/dev/build) echo "${RESULT}" } -cp .env /src/ -cp _ss_environment.php /src/ +try_cgi() { + info "Attempting to try cgi connection" + RESULT=$(REQUEST_URI=${REQUEST_URI:-/dev/build} \ + SCRIPT_FILENAME=${WORK_DIR:-/var/www/html}/index.php \ + SERVER_PROTOCOL=HTTP/1.1 \ + REQUEST_METHOD=GET \ + QUERY_STRING=${QUERY_STRING:-} \ + ./wait-for silverstripe:9000 --quiet --timeout=20 -- cgi-fcgi -bind -connect silverstripe:9000 | lynx --dump -stdin) -chown -R www-data:www-data /src + echo "${RESULT}" +} + +fail() { + MESSAGE="Tests failed!" + echo "${MESSAGE}" + echo "" + echo "REQUEST_URI: ${REQUEST_URI:-}" + echo "WORK_DIR: ${WORK_DIR:-}" + echo "QUERY_STRING: ${QUERY_STRING:-}" + exit 1 +} -./wait-for database:3306 --quiet --timeout=20 +pass() { + MESSAGE=${1:-Tests passed!} + echo "${MESSAGE}" + exit 0 +} -if [ "${DISTRO}" == "apache" ]; then +failure() { + MESSAGE="Unknown failure" + echo "[FAULT] ${MESSAGE}" +} + +info "Test Runner" +info " - Arguments" +info " - REQUEST_URI=${REQUEST_URI}" +info " - TAG=${TAG}" +info " - Copying Environment files" +cp _ss_environment.php /src/ +info " - Changing ownership of codebase to 'www-data'" +chown -R www-data:www-data /src + +info " - Checking database connection..." +retry 5 ./wait-for database:3306 --quiet --timeout=30 +info " - Good" +info "" +info "Running tests" +if [[ "${TAG}" =~ "-apache-" ]]; then + info " - Detected apache in tag, trying test via curl" try_curl + if [[ "${RESULT}" =~ "Database build completed!" ]]; then - echo "Tests passed!" - exit 0 - else - echo "Tests failed!" - exit 1 + pass + fi +elif [[ "${TAG}" =~ "-fpm-" ]]; then + info " - Detected fpm in tag, trying test via cgi" + WORK_DIR=${MOUNT_DIR:-/var/www/html} + [ -d "/src/public" ] && WORK_DIR="${WORK_DIR}/public" + + try_cgi + # Check if 302 and for devbuildtoken and retry + if [[ "${RESULT}" =~ "Status: 302" ]]; then + info " - '302' response received, attempting to follow redirect" + TOKEN=$(echo "${RESULT}" | sed -nr 's/.*devbuildtoken=([a-z0-9]+).*/\1/p') + QUERY_STRING="devbuildtoken=${TOKEN}" + try_cgi fi -elif [ "${DISTRO}" == "fpm" ]; then - SCRIPT_NAME=/dev/build \ - SCRIPT_FILENAME=/dev/build \ - REQUEST_METHOD=GET \ - ./wait-for silverstripe:9000 --quiet --timeout=20 -- cgi-fcgi -bind -connect silverstripe:9000 - echo "Tests passed!" - exit 0 + if [[ "${RESULT}" =~ "Database build completed!" ]]; then + pass + fi +elif [[ "${TAG}" =~ "-cli-" ]]; then + pass "Skipping CLI test" fi -echo "Tests skipped!" -exit 0 \ No newline at end of file + +# If we get here. Tests failed. +fail + +trap failure EXIT \ No newline at end of file