Skip to content

Commit

Permalink
Automated tests against drupal9, php, laravel platformsh templates, for
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored Oct 7, 2022
1 parent d23f816 commit d2ca90f
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 50 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ jobs:
strategy:
matrix:
# ddev_version: [ HEAD ]
# ddev_version: [stable, HEAD]
ddev_version: [stable, HEAD]
# ddev_version: [PR]
fail-fast: false

runs-on: ubuntu-20.04

steps:
- run: echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
- uses: actions/checkout@v2
- name: Environment setup
run: |
brew install bats-core mkcert
# For bats-assert and friends
brew tap kaos/shell
brew install bats-core bats-assert bats-support jq mkcert yq
mkcert -install
- name: Use ddev stable
Expand Down Expand Up @@ -76,3 +79,6 @@ jobs:
- name: tests
run: bats tests

# keepalive-workflow adds a dummy commit if there's no other action here, keeps
# GitHub from turning off tests after 60 days
- uses: gautamkrishnar/keepalive-workflow@v1
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ This repository is used with `ddev get platformsh/ddev-platformsh` to get a rich
* hooks are converted to DDEV post-start hooks
* A working `ddev pull platform` integration with all mounts is created.

## What has been tested

These Platform.sh templates are included in the automated tests that run nightly:

* [php](https://github.com/platformsh-templates/php)
* [drupal9](https://github.com/platformsh-templates/drupal9)
* [laravel](https://github.com/platformsh-templates/laravel)

## What will it do in the future

- [x] Populate important PLATFORMSH environment variables that would be found upstream
- [ ] Populate PHP and other dependencies configured upstream
- [x] Populate PHP and other dependencies configured upstream
- [x] Automatically figure out the name and other information of the upstream project
- [x] Automatically configure the .ddev/providers/platform so you can immediately do a `ddev pull platform` with no configuration effort.
- [ ] Let us know what's important to you!
Expand Down
45 changes: 39 additions & 6 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ pre_install_actions:
# We don't want to allow new config if they're changing database types from what is currently there.
- |
#ddev-nodisplay
{{ $dbtype := "" }}
{{ if .platformapp.relationships.database }}
{{ $dbheader := index (split ":" .platformapp.relationships.database) "_0" }}
{{ $dbtype := replace "postgresql" "postgres" (get (get .services $dbheader) "type") }}
{{ $dbtype = replace "postgresql" "postgres" (get (get .services $dbheader) "type") }}
export upstream_db="{{ regexReplaceAll "oracle-" (regexReplaceAll ":.*$" $dbtype "") "" }}:{{ regexReplaceAll "^.*:" $dbtype "" }}"
# Unfortunate sed to remove color escape sequences from ddev debug output
current_db_version="$(ddev debug get-volume-db-version | sed -r 's/\x1b\[[0-9;]*m?//g')"
if [ "${current_db_version}" != "" ] && [ ">${upstream_db}<" != ">${current_db_version}<" ]; then
printf "There is an existing database in this project that doesn\'t match the upstream database type.\n Please use 'ddev delete' to delete the existing database and retry, or try 'ddev debug migrate-database ${upstream_db}' to migrate the database.\n"
false
fi
{{ end }}
# Write a config.platformsh.yaml based on calculated values, php version, database, docroot
# Write a config.platformsh.yaml based on calculated values, php version, database, docroot
- |
#ddev-nodisplay
# set -x
Expand Down Expand Up @@ -114,13 +118,18 @@ pre_install_actions:
cat <<-EOF >.ddev/config.platformsh.yaml
# #ddev-generated
# Generated configuration based on platform.sh project configuration
{{ $dbtype := "" }}
{{ if .platformapp.relationships.database }}
{{ $dbheader := index (split ":" .platformapp.relationships.database) "_0" }}
{{ $dbtype := replace "postgresql" "postgres" (get (get .services $dbheader) "type") }}
{{ $dbtype = replace "postgresql" "postgres" (get (get .services $dbheader) "type") }}
{{ end }}
{{ $phpversion := trimPrefix "php:" .platformapp.type }}
php_version: {{ $phpversion }}
{{ if .platformapp.relationships.database }}
database:
type: {{ regexReplaceAll "oracle-" (regexReplaceAll ":.*$" $dbtype "") "" }}
version: {{ regexReplaceAll "^.*:" $dbtype "" }}
{{ end }}
docroot: {{ dig "web" "locations" "/" "root" "notfound" .platformapp }}
web_environment:
# TODO: Review which of these matters and which can be dummied up
Expand All @@ -133,16 +142,20 @@ pre_install_actions:
- "PLATFORM_ROUTES=${PLATFORM_ROUTES}"
- "PLATFORM_VARIABLES=e30="
- "PATH=$PATH:/var/www/html/.global/bin"
{{ if .platformapp.variables.env }}
{{ range $key, $value := .platformapp.variables.env }}
- "{{$key}}={{$value}}"{{ end }}{{ end }}
# Provide all PHP extensions but blackfire, which has different pattern (blackfire-php) and is already installed
# and pdo_pgsql, which is already installed
{{ $phpversion := trimPrefix "php:" .platformapp.type }}
{{ if .platformapp.runtime.extensions }}
{{ $phpextensions := without .platformapp.runtime.extensions "blackfire" "pdo_pgsql" "sodium" }}
webimage_extra_packages:{{range $extension := $phpextensions }}
- php{{$phpversion}}-{{$extension}}{{end}}
{{ if has "sodium" .platformapp.runtime.extensions }}
- php-sodium
{{end}}
{{ end }}
# Add pip only if we have python3 dependencies
{{ if .platformapp.dependencies.python3 }}
Expand Down Expand Up @@ -199,11 +212,14 @@ post_install_actions:
# If redis is configured, do a ddev get to get it
- |
#ddev-nodisplay
{{ if eq .services.cache.type "redis:6.0" }}
{{ if and .services.cache.type (hasPrefix "redis" .services.cache.type) }}
echo "Running 'ddev get drud/ddev-redis'"
ddev get drud/ddev-redis
{{ end }}
{{ if and .services.search.type (hasPrefix "elasticsearch" .services.search.type "elasticsearch") }}
echo "Running 'ddev get drud/ddev-elasticsearch'"
ddev get drud/ddev-elasticsearch
{{ end }}
cat <<-ENDDOCKERFILE >> web-build/Dockerfile.platformsh
{{ if .platformapp.dependencies.php }}{{ range $pkg, $version := .platformapp.dependencies.php }}{{ if ne $pkg "composer/composer" }}
ENV COMPOSER_HOME=/usr/local/composer
Expand All @@ -218,6 +234,23 @@ post_install_actions:
{{ end }}
ENDDOCKERFILE
- |
#ddev-nodisplay
cd ..
unset DDEV_DEBUG
project_type=$(ddev describe -j | jq -r .raw.type)
case $project_type in
laravel)
# TODO: This depends on perl, but we can't start the project unless these are created
# so can't use ddev exec yet.
perl -p -e 's/DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)/DB_\1=db/g' .env.example >.env
perl -pi.bak -e "s#APP_URL=.*#APP_URL=${DDEV_PRIMARY_URL}#g" .env
;;
drupal9)
mkdir -p .drush
;;
esac
yaml_read_files:
platformapp: .platform.app.yaml
services: .platform/services.yaml
Expand Down
30 changes: 30 additions & 0 deletions tests/drupal.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Requires bats-assert and bats-support
# brew tap kaos/shell &&
# brew install bats-core bats-assert bats-support jq mkcert yq
setup() {
load setup.sh
}

teardown() {
load teardown.sh
}

@test "drupal9" {
load per_test.sh
template="drupal9"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
echo "# ddev get $source with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
per_test_setup

run ddev exec -s db 'echo ${DDEV_DATABASE}'
assert_output "mariadb:10.4"
run ddev exec "php --version | awk 'NR==1 { sub(/\.[0-9]+$/, \"\", \$2); print \$2 }'"
assert_output "8.0"
ddev describe -j >describe.json
run jq -r .raw.docroot <describe.json
assert_output "web"

docker inspect ddev-${PROJNAME}-redis >/dev/null
per_test_teardown
done
}
29 changes: 29 additions & 0 deletions tests/laravel.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Requires bats-assert and bats-support
# brew tap kaos/shell &&
# brew install bats-core bats-assert bats-support jq mkcert yq
setup() {
load setup.sh
load per_test.sh
}

teardown() {
load teardown.sh
}

@test "laravel" {
load per_test.sh
template="laravel"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
echo "# doing ddev get $source with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
per_test_setup

run ddev exec "php --version | awk 'NR==1 { sub(/\.[0-9]+$/, \"\", \$2); print \$2 }'"
assert_output "8.0"
ddev describe -j >describe.json
run jq -r .raw.docroot <describe.json
assert_output "public"
docker inspect ddev-${PROJNAME}-redis >/dev/null
per_test_teardown

done
}
20 changes: 20 additions & 0 deletions tests/per_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

per_test_setup() {
set -e -o pipefail
set +u
ddev delete -Oy ${PROJNAME} || true

rm -rf ${TESTDIR} && mkdir -p ${TESTDIR} && cd ${TESTDIR}

curl -sfL -o /tmp/testtemplate.tgz "https://github.com/platformsh-templates/${template}/tarball/master"
tar -zxf /tmp/testtemplate.tgz --strip-components=1
# Start with bogus settings so we know we got the right stuff when testing
ddev config --project-name=${PROJNAME} --php-version=5.6 --database=mariadb:10.1 --docroot=x --create-docroot --project-type=php --web-environment-add=PLATFORMSH_CLI_TOKEN=notokenrightnow,PLATFORM_PROJECT=notyet,PLATFORM_ENVIRONMENT=notyet
ddev get ${PROJECT_SOURCE}
ddev restart >/dev/null
}

per_test_teardown() {
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
}
28 changes: 28 additions & 0 deletions tests/php.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Requires bats-assert and bats-support
# brew tap kaos/shell &&
# brew install bats-core bats-assert bats-support jq mkcert yq
setup() {
load setup.sh
load per_test.sh
}

teardown() {
load teardown.sh
}

@test "php" {
load per_test.sh
template="php"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
echo "# doing ddev get $source with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
per_test_setup

run ddev exec "php --version | awk 'NR==1 { sub(/\.[0-9]+$/, \"\", \$2); print \$2 }'"
assert_output "8.0"
ddev describe -j >describe.json
run jq -r .raw.docroot <describe.json
assert_output "web"

per_test_teardown
done
}
12 changes: 12 additions & 0 deletions tests/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

bats_require_minimum_version 1.8.0
set -eu -o pipefail
export PROJECT_SOURCE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
export TESTDIR=~/tmp/testplatformsh
export PROJNAME=test-platformsh
export DDEV_NON_INTERACTIVE=true
brew_prefix=$(brew --prefix)
docker volume rm $PROJNAME-mariadb 2>/dev/null || true
load "${brew_prefix}/lib/bats-support/load.bash"
load "${brew_prefix}/lib/bats-assert/load.bash"
3 changes: 3 additions & 0 deletions tests/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

set -eu -o pipefail
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
41 changes: 0 additions & 41 deletions tests/test.bats

This file was deleted.

0 comments on commit d2ca90f

Please sign in to comment.