From e120314879a77c11116988f2fe376172de386dd3 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Mon, 29 Aug 2022 14:40:57 -0600 Subject: [PATCH 01/16] Minor starting updates --- .github/workflows/tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1ae0e0c..90eadfc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,7 +30,7 @@ jobs: strategy: matrix: # ddev_version: [ HEAD ] -# ddev_version: [stable, HEAD] + ddev_version: [stable, HEAD] # ddev_version: [PR] fail-fast: false @@ -40,7 +40,7 @@ jobs: - uses: actions/checkout@v2 - name: Environment setup run: | - brew install bats-core mkcert + brew install bats-core mkcert yq mkcert -install - name: Use ddev stable @@ -76,3 +76,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 From cb833f1f81b3447a6432edf0ce30ec147f3b846d Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Mon, 29 Aug 2022 17:32:41 -0600 Subject: [PATCH 02/16] First template - drupal9 sort of working --- .github/workflows/tests.yml | 4 ++- tests/test.bats | 56 ++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 90eadfc..1abb087 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,7 +40,9 @@ jobs: - uses: actions/checkout@v2 - name: Environment setup run: | - brew install bats-core mkcert yq + # 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 diff --git a/tests/test.bats b/tests/test.bats index 7895e2a..242a216 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -2,40 +2,52 @@ setup() { set -eu -o pipefail export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export TESTDIR=~/tmp/testplatformsh - mkdir -p $TESTDIR - cp -r tests/testdata/.platform* ${TESTDIR} export PROJNAME=test-platformsh export DDEV_NON_INTERACTIVE=true ddev delete -Oy ${PROJNAME} || true - cd "${TESTDIR}" - ddev config --project-name=${PROJNAME} --web-environment-add=PLATFORMSH_CLI_TOKEN=notokenrightnow + brew_prefix=$(brew --prefix) + load "${brew_prefix}/lib/bats-support/load.bash" + load "${brew_prefix}/lib/bats-assert/load.bash" } teardown() { set -eu -o pipefail - cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) ddev delete -Oy ${PROJNAME} - [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} +# [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} } -@test "install from directory" { - set -eu -o pipefail - cd ${TESTDIR} - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 +@test "drupal9" { + set -e -o pipefail + set +u + template="drupal9" + 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:5.5 --docroot=x --create-docroot --project-type=php --web-environment-add=PLATFORMSH_CLI_TOKEN=notokenrightnow,PLATFORM_PROJECT=notyet,PLATFORM_ENVIRONMENT=notyet + echo "# ddev get ${DIR} with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 ddev get ${DIR} - ddev restart >/dev/null - [ "$(ddev exec -s db 'echo ${DDEV_DATABASE}')" = "mysql:8.0" ] - [ "$(ddev exec 'echo ${DDEV_PHP_VERSION}')" = "8.0" ] - docker inspect ddev-${PROJNAME}-redis >/dev/null -} -@test "install from release" { - set -eu -o pipefail - cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) - echo "# ddev get drud/ddev-platformsh with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get platformsh/ddev-platformsh ddev restart >/dev/null - [ "$(ddev exec -s db 'echo ${DDEV_DATABASE}')" = "mysql:8.0" ] - [ "$(ddev exec 'echo ${DDEV_PHP_VERSION}')" = "8.0" ] + 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 /dev/null } + +#@test "install from release" { +# set -eu -o pipefail +# cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) +# echo "# ddev get drud/ddev-platformsh with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 +# ddev get platformsh/ddev-platformsh +# ddev restart >/dev/null +# [ "$(ddev exec -s db 'echo ${DDEV_DATABASE}')" = "mysql:8.0" ] +# [ "$(ddev exec 'echo ${DDEV_PHP_VERSION}')" = "8.0" ] +# docker inspect ddev-${PROJNAME}-redis >/dev/null +#} From c9f7cdf0a6a7e2d1314dcf4cdf24c1ebe3a139d1 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Tue, 30 Aug 2022 17:00:11 -0600 Subject: [PATCH 03/16] Working with drupal9 template --- tests/test.bats | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/test.bats b/tests/test.bats index 242a216..6345685 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -1,11 +1,11 @@ setup() { set -eu -o pipefail - export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." + 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 - ddev delete -Oy ${PROJNAME} || true brew_prefix=$(brew --prefix) + docker volume rm $PROJNAME-mariadb || true load "${brew_prefix}/lib/bats-support/load.bash" load "${brew_prefix}/lib/bats-assert/load.bash" } @@ -13,32 +13,40 @@ setup() { teardown() { set -eu -o pipefail ddev delete -Oy ${PROJNAME} -# [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} + [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} } -@test "drupal9" { +per_test_setup() { set -e -o pipefail set +u - template="drupal9" + 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:5.5 --docroot=x --create-docroot --project-type=php --web-environment-add=PLATFORMSH_CLI_TOKEN=notokenrightnow,PLATFORM_PROJECT=notyet,PLATFORM_ENVIRONMENT=notyet - echo "# ddev get ${DIR} with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ${DIR} - + ddev get ${PROJECT_SOURCE} ddev restart >/dev/null - 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 /dev/null +} + +@test "drupal9" { + 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 /dev/null + done } #@test "install from release" { From dcf366cc199e02a2af5b4ca054e52dc1df1b4c10 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Tue, 30 Aug 2022 17:26:20 -0600 Subject: [PATCH 04/16] Add more tests --- install.yaml | 6 ++++++ tests/test.bats | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/install.yaml b/install.yaml index 44fdc8a..d14cd3b 100644 --- a/install.yaml +++ b/install.yaml @@ -75,6 +75,7 @@ pre_install_actions: # We don't want to allow new config if they're changing database types from what is currently there. - | #ddev-nodisplay + {{ if .platformapp.relationships.database }} {{ $dbheader := index (split ":" .platformapp.relationships.database) "_0" }} {{ $dbtype := replace "postgresql" "postgres" (get (get .services $dbheader) "type") }} export upstream_db="{{ regexReplaceAll "oracle-" (regexReplaceAll ":.*$" $dbtype "") "" }}:{{ regexReplaceAll "^.*:" $dbtype "" }}" @@ -84,6 +85,7 @@ pre_install_actions: 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 - | @@ -114,13 +116,17 @@ pre_install_actions: cat <<-EOF >.ddev/config.platformsh.yaml # #ddev-generated # Generated configuration based on platform.sh project configuration + {{ if .platformapp.relationshps.database }} {{ $dbheader := index (split ":" .platformapp.relationships.database) "_0" }} {{ $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 diff --git a/tests/test.bats b/tests/test.bats index 6345685..72c5c79 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -31,6 +31,10 @@ per_test_setup() { ddev restart >/dev/null } +per_test_teardown() { + ddev delete -Oy ${PROJNAME} || true +} + @test "drupal9" { template="drupal9" for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do @@ -46,16 +50,38 @@ per_test_setup() { assert_output "web" docker inspect ddev-${PROJNAME}-redis >/dev/null + per_test_teardown done } -#@test "install from release" { -# set -eu -o pipefail -# cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) -# echo "# ddev get drud/ddev-platformsh with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 -# ddev get platformsh/ddev-platformsh -# ddev restart >/dev/null -# [ "$(ddev exec -s db 'echo ${DDEV_DATABASE}')" = "mysql:8.0" ] -# [ "$(ddev exec 'echo ${DDEV_PHP_VERSION}')" = "8.0" ] -# docker inspect ddev-${PROJNAME}-redis >/dev/null -#} + +@test "php" { + template="php" + 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 "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 &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 /dev/null + + done +} From 7f92f4cfcdd9e153c1aad66311520d29576a253a Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Wed, 31 Aug 2022 15:14:37 -0600 Subject: [PATCH 05/16] Add teardown to extra items --- tests/test.bats | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test.bats b/tests/test.bats index 72c5c79..eb2a4c3 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -66,6 +66,9 @@ per_test_teardown() { ddev describe -j >describe.json run jq -r .raw.docroot /dev/null + per_test_teardown done } From 45f4303a5becf7f5a86fa79d56a7e48e80f8079c Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Wed, 31 Aug 2022 15:23:23 -0600 Subject: [PATCH 06/16] Hide even though it's hidden in if statement --- install.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/install.yaml b/install.yaml index d14cd3b..3732bdd 100644 --- a/install.yaml +++ b/install.yaml @@ -75,9 +75,10 @@ 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')" @@ -116,9 +117,10 @@ pre_install_actions: cat <<-EOF >.ddev/config.platformsh.yaml # #ddev-generated # Generated configuration based on platform.sh project configuration + {{ $dbtype := "" }} {{ if .platformapp.relationshps.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 }} @@ -143,12 +145,14 @@ pre_install_actions: # 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 }} From 386555ed4c1be364a55c1dfefd39e1f23c50c7f0 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Wed, 31 Aug 2022 16:47:36 -0600 Subject: [PATCH 07/16] Add handling of platformapp env variables --- install.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/install.yaml b/install.yaml index 3732bdd..d5b8a9f 100644 --- a/install.yaml +++ b/install.yaml @@ -118,7 +118,7 @@ pre_install_actions: # #ddev-generated # Generated configuration based on platform.sh project configuration {{ $dbtype := "" }} - {{ if .platformapp.relationshps.database }} + {{ if .platformapp.relationships.database }} {{ $dbheader := index (split ":" .platformapp.relationships.database) "_0" }} {{ $dbtype = replace "postgresql" "postgres" (get (get .services $dbheader) "type") }} {{ end }} @@ -141,7 +141,9 @@ 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 }} @@ -209,11 +211,16 @@ post_install_actions: # If redis is configured, do a ddev get to get it - | #ddev-nodisplay + # TODO: Looking for specific redis here will not work {{ if eq .services.cache.type "redis:6.0" }} echo "Running 'ddev get drud/ddev-redis'" ddev get drud/ddev-redis {{ end }} - + # TODO: Looking for specific elasticsearch here will never work + {{ if eq .services.search.type "elasticsearch:7.5" }} + 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 From ea4e36e4098f0162670683351f3082018122efd5 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Wed, 31 Aug 2022 17:13:38 -0600 Subject: [PATCH 08/16] Add special handling for laravel .env on startup --- install.yaml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/install.yaml b/install.yaml index d5b8a9f..02e2922 100644 --- a/install.yaml +++ b/install.yaml @@ -88,7 +88,8 @@ pre_install_actions: 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 @@ -235,6 +236,19 @@ post_install_actions: {{ end }} ENDDOCKERFILE +- | + #ddev-nodisplay + cd .. + set -x + project_type=$(ddev describe -j | jq -r .raw.type) + case $project_type in + laravel) + # TODO: This depends on sed and cat, but we can't start the project unless these are created + # so can't use ddev exec yet. + cat .env.example | sed -E 's/DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)/DB_\1=db/g' > .env + sed -i "s#APP_URL=.*#APP_URL=${DDEV_PRIMARY_URL}#g" .env + esac + yaml_read_files: platformapp: .platform.app.yaml services: .platform/services.yaml From 931638cd5f395ced67ade04fd9d0204fd4afec54 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Wed, 31 Aug 2022 17:17:28 -0600 Subject: [PATCH 09/16] Special handling for drupal9 --- install.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install.yaml b/install.yaml index 02e2922..3bbce2e 100644 --- a/install.yaml +++ b/install.yaml @@ -239,7 +239,7 @@ post_install_actions: - | #ddev-nodisplay cd .. - set -x + unset DDEV_DEBUG project_type=$(ddev describe -j | jq -r .raw.type) case $project_type in laravel) @@ -247,6 +247,10 @@ post_install_actions: # so can't use ddev exec yet. cat .env.example | sed -E 's/DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)/DB_\1=db/g' > .env sed -i "s#APP_URL=.*#APP_URL=${DDEV_PRIMARY_URL}#g" .env + ;; + drupal9) + mkdir -p .drush + ;; esac yaml_read_files: From d9c274e69ecf6d91be31a16248561bf84aa339e3 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 15:17:41 -0600 Subject: [PATCH 10/16] Move each template into separate file for easier testing --- .github/workflows/tests.yml | 1 + tests/drupal.bats | 34 ++++++++++++++ tests/laravel.bats | 32 +++++++++++++ tests/per_test.sh | 20 ++++++++ tests/php.bats | 28 ++++++++++++ tests/setup.sh | 12 +++++ tests/teardown.sh | 3 ++ tests/test.bats | 91 ------------------------------------- 8 files changed, 130 insertions(+), 91 deletions(-) create mode 100644 tests/drupal.bats create mode 100644 tests/laravel.bats create mode 100644 tests/per_test.sh create mode 100644 tests/php.bats create mode 100644 tests/setup.sh create mode 100644 tests/teardown.sh delete mode 100644 tests/test.bats diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1abb087..fa0cd86 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,6 +37,7 @@ jobs: 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: | diff --git a/tests/drupal.bats b/tests/drupal.bats new file mode 100644 index 0000000..48b5e00 --- /dev/null +++ b/tests/drupal.bats @@ -0,0 +1,34 @@ +# Requires bats-assert and bats-support +# brew tap kaos/shell && +# brew install bats-core bats-assert bats-support jq mkcert yq +setup() { + echo "# start setup" >&3 + load setup.sh + echo "# end setup" >&3 +} + +teardown() { + echo "# begin teardown" >&3 + load teardown.sh + echo "# end teardown" >&3 +} + +@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 /dev/null + per_test_teardown + done +} diff --git a/tests/laravel.bats b/tests/laravel.bats new file mode 100644 index 0000000..0e8ff6f --- /dev/null +++ b/tests/laravel.bats @@ -0,0 +1,32 @@ +# 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 + echo "# setup complete" >&3 + +} + +teardown() { + echo "# begin teardown" >&3 + 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 /dev/null + per_test_teardown + + done +} diff --git a/tests/per_test.sh b/tests/per_test.sh new file mode 100644 index 0000000..31588b6 --- /dev/null +++ b/tests/per_test.sh @@ -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 +} diff --git a/tests/php.bats b/tests/php.bats new file mode 100644 index 0000000..e20ef69 --- /dev/null +++ b/tests/php.bats @@ -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 /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" diff --git a/tests/teardown.sh b/tests/teardown.sh new file mode 100644 index 0000000..759ee64 --- /dev/null +++ b/tests/teardown.sh @@ -0,0 +1,3 @@ + +set -eu -o pipefail +[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} diff --git a/tests/test.bats b/tests/test.bats deleted file mode 100644 index eb2a4c3..0000000 --- a/tests/test.bats +++ /dev/null @@ -1,91 +0,0 @@ -setup() { - 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 || true - load "${brew_prefix}/lib/bats-support/load.bash" - load "${brew_prefix}/lib/bats-assert/load.bash" -} - -teardown() { - set -eu -o pipefail - ddev delete -Oy ${PROJNAME} - [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} -} - -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:5.5 --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} || true -} - -@test "drupal9" { - 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 /dev/null - per_test_teardown - done -} - - -@test "php" { - template="php" - 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 "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 &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 /dev/null - per_test_teardown - - done -} From e6497ac7ba9c4d4ce0298e7736210181e26a2b8c Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 15:56:40 -0600 Subject: [PATCH 11/16] Use perl instead of sed in install.yaml --- install.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.yaml b/install.yaml index 3bbce2e..2cea0a4 100644 --- a/install.yaml +++ b/install.yaml @@ -243,10 +243,10 @@ post_install_actions: project_type=$(ddev describe -j | jq -r .raw.type) case $project_type in laravel) - # TODO: This depends on sed and cat, but we can't start the project unless these are created + # TODO: This depends on perl, but we can't start the project unless these are created # so can't use ddev exec yet. - cat .env.example | sed -E 's/DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)/DB_\1=db/g' > .env - sed -i "s#APP_URL=.*#APP_URL=${DDEV_PRIMARY_URL}#g" .env + 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 From 949efefa7a68b1f51042c3aa789357fe4fafb98b Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 16:23:43 -0600 Subject: [PATCH 12/16] Maybe laravel is working --- install.yaml | 3 +-- tests/laravel.bats | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/install.yaml b/install.yaml index 2cea0a4..86f94cc 100644 --- a/install.yaml +++ b/install.yaml @@ -212,8 +212,7 @@ post_install_actions: # If redis is configured, do a ddev get to get it - | #ddev-nodisplay - # TODO: Looking for specific redis here will not work - {{ if eq .services.cache.type "redis:6.0" }} + {{ if hasPrefix "redis" .services.cache.type }} echo "Running 'ddev get drud/ddev-redis'" ddev get drud/ddev-redis {{ end }} diff --git a/tests/laravel.bats b/tests/laravel.bats index 0e8ff6f..de45ac2 100644 --- a/tests/laravel.bats +++ b/tests/laravel.bats @@ -10,7 +10,7 @@ setup() { teardown() { echo "# begin teardown" >&3 - load teardown.sh + load teardown.sh } @test "laravel" { From 14452f10251b71a65b4135bda54f13f1b22c6711 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 16:40:35 -0600 Subject: [PATCH 13/16] Correctly check to see if cache.type is set before using it --- install.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.yaml b/install.yaml index 86f94cc..6a74a7c 100644 --- a/install.yaml +++ b/install.yaml @@ -212,7 +212,7 @@ post_install_actions: # If redis is configured, do a ddev get to get it - | #ddev-nodisplay - {{ if hasPrefix "redis" .services.cache.type }} + {{ if and .services.cache.type (hasPrefix "redis" .services.cache.type) }} echo "Running 'ddev get drud/ddev-redis'" ddev get drud/ddev-redis {{ end }} From 6dc58fbf4672562641f6c02bfb0d8b7c92cfd066 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 16:42:08 -0600 Subject: [PATCH 14/16] Remove some comments --- tests/drupal.bats | 4 ---- tests/laravel.bats | 3 --- 2 files changed, 7 deletions(-) diff --git a/tests/drupal.bats b/tests/drupal.bats index 48b5e00..aba8503 100644 --- a/tests/drupal.bats +++ b/tests/drupal.bats @@ -2,15 +2,11 @@ # brew tap kaos/shell && # brew install bats-core bats-assert bats-support jq mkcert yq setup() { - echo "# start setup" >&3 load setup.sh - echo "# end setup" >&3 } teardown() { - echo "# begin teardown" >&3 load teardown.sh - echo "# end teardown" >&3 } @test "drupal9" { diff --git a/tests/laravel.bats b/tests/laravel.bats index de45ac2..928e254 100644 --- a/tests/laravel.bats +++ b/tests/laravel.bats @@ -4,12 +4,9 @@ setup() { load setup.sh load per_test.sh - echo "# setup complete" >&3 - } teardown() { - echo "# begin teardown" >&3 load teardown.sh } From c1fdc3f6e1b452734129b4d9453bb15a348fa87e Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 16:49:52 -0600 Subject: [PATCH 15/16] Do same to elasticsearch as done with redis --- install.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install.yaml b/install.yaml index 6a74a7c..0604bc0 100644 --- a/install.yaml +++ b/install.yaml @@ -216,8 +216,7 @@ post_install_actions: echo "Running 'ddev get drud/ddev-redis'" ddev get drud/ddev-redis {{ end }} - # TODO: Looking for specific elasticsearch here will never work - {{ if eq .services.search.type "elasticsearch:7.5" }} + {{ if and .services.search.type (hasPrefix "elasticsearch" .services.search.type "elasticsearch") }} echo "Running 'ddev get drud/ddev-elasticsearch'" ddev get drud/ddev-elasticsearch {{ end }} From fe75f415c855c3708a11586fcbfe76ca9dd5ca27 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Fri, 7 Oct 2022 16:53:43 -0600 Subject: [PATCH 16/16] Update README with tests --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d22654..8a86be5 100644 --- a/README.md +++ b/README.md @@ -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!