Skip to content

Commit

Permalink
Merge branch 'main' into 20221209_fail_on_hook_fail
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored Mar 11, 2023
2 parents bcf600e + db1d810 commit 74eb139
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 39 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ main ]

schedule:
- cron: '01 07 * * *'
- cron: '12 17 * * *'

workflow_dispatch:
inputs:
Expand All @@ -19,7 +19,10 @@ defaults:
shell: bash

env:
NIGHTLY_DDEV_PR_URL: "https://nightly.link/drud/ddev/actions/runs/1720215802/ddev-linux-amd64.zip"
NIGHTLY_DDEV_PR_URL: "https://nightly.link/ddev/ddev/actions/runs/1720215802/ddev-linux-amd64.zip"
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Allow `--HEAD` flag when running tests against HEAD
HOMEBREW_NO_INSTALL_FROM_API: 1

jobs:
tests:
Expand Down Expand Up @@ -50,15 +53,15 @@ jobs:
- name: Use ddev stable
if: matrix.ddev_version == 'stable'
run: brew install drud/ddev/ddev
run: brew install ddev/ddev/ddev

- name: Use ddev edge
if: matrix.ddev_version == 'edge'
run: brew install drud/ddev-edge/ddev
run: brew install ddev/ddev-edge/ddev

- name: Use ddev HEAD
if: matrix.ddev_version == 'HEAD'
run: brew install --HEAD drud/ddev/ddev
run: brew install --HEAD ddev/ddev/ddev

- name: Use ddev PR
if: matrix.ddev_version == 'PR'
Expand Down
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
[![tests](https://github.com/platformsh/ddev-platformsh/actions/workflows/tests.yml/badge.svg)](https://github.com/platformsh/ddev-platformsh/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2022.svg)
[![tests](https://github.com/ddev/ddev-platformsh/actions/workflows/tests.yml/badge.svg)](https://github.com/ddev/ddev-platformsh/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg)

## What is ddev-platformsh?

This repository is used with `ddev get platformsh/ddev-platformsh` to get a rich integration between your checked-out Platform.sh project and [DDEV](https://github.com/drud/ddev).
This repository is used with `ddev get ddev/ddev-platformsh` to get a rich integration between your checked-out Platform.sh project and [DDEV](https://github.com/ddev/ddev).

## Using with a Platform.sh project
1. Make sure you have [DDEV v1.21.1+ installed](https://ddev.readthedocs.io/en/latest/users/install/ddev-installation/)
2. Clone your project repository (e.g. `platform get <projectid>`)
3. `cd` into your project directory
4. Run `ddev config` and answer the questions as appropriate
5. Run `ddev get platformsh/ddev-platformsh` and answer the questions as appropriate
6. Run `ddev start`
7. (Optional) Run `ddev pull platform` to retrieve a copy of the database and contents from the project's file mounts from the environment you entered in step #5
### Dependencies

Make sure you have [DDEV v1.21.6+ installed](https://ddev.readthedocs.io/en/latest/users/install/ddev-installation/)

### Install
1. Clone your project repository (e.g. `platform get <projectid>`)
2. `cd` into your project directory
3. Run `ddev config` and answer the questions as appropriate
4. Run `ddev get ddev/ddev-platformsh` and answer the questions as appropriate
5. Run `ddev start`
6. (Optional) Run `ddev pull platform` to retrieve a copy of the database and contents from the project's file mounts from the environment you entered in step #5
1. If you only want to retrieve the database (skipping the file mounts), add the `--skip-files` flag to the `ddev pull platform` command

### Upgrade

To upgrade your version of ddev-platformsh, repeat the `ddev get ddev/ddev-platformsh` to get the latest release.

### Run it again if you change your Platform.sh configuration

If you change your `.platform.app.yaml` or something in your `.platform` directory, repeat the `ddev get ddev/ddev-platformsh` so that the generated configuration for DDEV will be updated.

## Notes

* If your local project has a different database type than the upstream (Platform.sh) database, it will conflict, so please back up your database with `ddev export-db` and `ddev delete -y` before starting the project with new config based on upstream.
Expand All @@ -34,6 +46,19 @@ This repository is used with `ddev get platformsh/ddev-platformsh` to get a rich
* Redis
* Memcached
* ElasticSearch
* Provides the following [Platform.sh-provided environmental variables](https://docs.platform.sh/development/variables/use-variables.html#use-platformsh-provided-variables):
* PLATFORM_APP_DIR
* PLATFORM_APPLICATION_NAME
* PLATFORM_CACHE_DIR
* PLATFORM_ENVIRONMENT
* PLATFORM_PROJECT
* PLATFORM_PROJECT_ENTROPY
* PLATFORM_RELATIONSHIPS
* PLATFORM_ROUTES (see note below)
* PLATFORM_TREE_ID
* PLATFORM_VARIABLES

DDEV does not currently parse the contents of `.platform/routes.yaml` and therefore, `PLATFORM_ROUTES` only contains information related to a single, default route.

## What has been tested

Expand Down
46 changes: 27 additions & 19 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ pre_install_actions:
- |
#ddev-nodisplay
#ddev-description:Checking DDEV version
(ddev debug capabilities | grep migrate-database >/dev/null) || (echo "Please upgrade DDEV to v1.21.1+ for appropriate capabilities" && false)
(ddev debug capabilities | grep web-start-hooks >/dev/null) || (echo "Please upgrade DDEV to v1.21.5+ for appropriate capabilities" && false)
- |
#ddev-nodisplay
#ddev-description:pull ddev/ddev-utilities
docker pull ddev/ddev-utilities
# Get PLATFORMSH_CLI_TOKEN from user if we don't have it yet
- |
#ddev-nodisplay
#ddev-description:Checking for PLATFORMSH_CLI_TOKEN
if ( {{ contains "PLATFORMSH_CLI_TOKEN" (list .DdevGlobalConfig.web_environment | toString) }} || {{ contains "PLATFORMSH_CLI_TOKEN" (list .DdevProjectConfig.web_environment | toString) }} ); then
echo "Using existing PLATFORMSH_CLI_TOKEN."
else
Expand All @@ -42,7 +46,6 @@ pre_install_actions:
# Get PLATFORM_PROJECT from user if we don't have it yet
- |
#ddev-nodisplay
#ddev-description:Checking for PLATFORM_PROJECT
# echo 'list ddevprojectconfig.web_environment={{ list .DdevProjectConfig.web_environment | toString }}'
if ({{ contains "PLATFORM_PROJECT=" (list .DdevProjectConfig.web_environment | toString) }} ); then
echo "Using existing PLATFORM_PROJECT from project config.yaml."
Expand All @@ -52,7 +55,7 @@ pre_install_actions:
- |
#ddev-nodisplay
#ddev-description:Setting PLATFORM_PROJECT
#ddev-description:Set PLATFORM_PROJECT
if !( {{ contains "PLATFORM_PROJECT" (list .DdevProjectConfig.web_environment | toString) }} ); then
read platform_project
echo "platform_project = '${platform_project}'"
Expand All @@ -75,7 +78,6 @@ pre_install_actions:
# Get PLATFORM_ENVIRONMENT from user if we don't have it
- |
#ddev-nodisplay
#ddev-description:Setting PLATFORM_ENVIRONMENT
# echo 'list ddevprojectconfig.web_environment={{ list .DdevProjectConfig.web_environment | toString }}'
if ({{ contains "PLATFORM_ENVIRONMENT=" (list .DdevProjectConfig.web_environment | toString) }} ); then
echo "Using existing PLATFORM_ENVIRONMENT from project config.yaml."
Expand Down Expand Up @@ -113,19 +115,26 @@ post_install_actions:
#ddev-nodisplay
cd ..
unset DDEV_DEBUG
project_type=$(ddev describe -j | jq -r .raw.type)
project_type=$(ddev describe -j | docker run -i --rm ddev/ddev-utilities 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
#set -x
# The double-run here is awkward, but I didn't figure out how to do it with two '-e'
docker run -i --rm ddev/ddev-utilities perl -p -e "s!APP_URL=.*!APP_URL=${DDEV_PRIMARY_URL}!g" <.env.example | docker run -i --rm ddev/ddev-utilities perl -p -e 's!DB_(HOST|DATABASE|USERNAME|PASSWORD)=(.*)!DB_\1=db!g' >.env
;;
drupal9)
mkdir -p .drush
;;
esac
- |
#ddev-nodisplay
#ddev-description: Install .environment file into web-entrypoint.d if needed
if [ -f ../.environment ]; then
mkdir -p web-entrypoint.d
cp ../.environment web-entrypoint.d/environment.sh
fi
# Write a config.platformsh.yaml based on calculated values, php version, database, docroot
- |
#ddev-nodisplay
Expand All @@ -145,11 +154,10 @@ post_install_actions:
}
ENDROUTES
)
BASE64_ENCODE="base64"
if base64 -w 0 </dev/null >/dev/null 2>&1; then BASE64_ENCODE="base64 -w 0"; fi
echo BASE64_ENCODE=${BASE64_ENCODE}
BASE64_ENCODE="docker run -i --rm ddev/ddev-utilities base64 -w 0"
BASE64_DECODE="docker run -i --rm ddev/ddev-utilities base64 -d"
PLATFORM_ROUTES="$(echo -n ${platform_routes} | ${BASE64_ENCODE})"
PLATFORM_PROJECT_ENTROPY="$(echo $RANDOM | shasum -a 256 | awk '{print $1}')"
PLATFORM_PROJECT_ENTROPY="$(echo $RANDOM | docker run -i --rm ddev/ddev-utilities shasum -a 256 | awk '{print $1}')"
{{/* Handling services relationships */}}
export relationships=()
Expand All @@ -170,15 +178,15 @@ post_install_actions:
{{ $supported_db_types := list "postgres" "mysql" "mariadb" }}
{{/* For supported services, key is the service name and value is the corresponding add-on to install if applicable (nil if not needed) */}}
{{ $supported_services := dict "redis" "drud/ddev-redis" "memcached" "drud/ddev-memcached" "elasticsearch" "drud/ddev-elasticsearch" }}
{{ $supported_services := dict "redis" "ddev/ddev-redis" "memcached" "ddev/ddev-memcached" "elasticsearch" "ddev/ddev-elasticsearch" }}
{{ if $supported_db_types | has $service_def.type }}
{{/* Databases */}}
{{ $dbtype := $service_def.fulltype }}
# echo dbtype={{ $dbtype }}
{{ if $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')"
current_db_version="$(ddev debug get-volume-db-version | docker run -i --rm ddev/ddev-utilities sed -r 's/\x1b\[[0-9;]*m?//g')"
export DBTYPE={{ regexReplaceAll ":.*$" $dbtype "" }}
export DBVERSION={{ regexReplaceAll "^.*:" $dbtype "" }}
if [ "${current_db_version}" != "" ] && [ ">{{ $dbtype }}<" != ">${current_db_version}<" ]; then
Expand All @@ -187,7 +195,7 @@ post_install_actions:
fi
# echo ./platformsh/generate_db_relationship.sh '{{ $relationship_name }}' '{{ $dbtype }}' '{{ $relationship_name }}'
relationships+=($(./platformsh/generate_db_relationship.sh '{{ $relationship_name }}' '{{ $dbtype }}' '{{ $relationship_name }}' | ${BASE64_ENCODE}))
#printf "relationships length after db=${#relationships[@]}\nrelationships value=$(echo $relationships | base64 -d)"
#printf "relationships length after db=${#relationships[@]}\nrelationships value=$(echo $relationships | ${BASE64_DECODE})"
{{ end }}
{{ else if hasKey $supported_services $service_def.type }}
{{/* Other services */}}
Expand All @@ -201,8 +209,8 @@ post_install_actions:
{{ end }}
#echo "Number of relationships=${#relationships[@]}"
PLATFORM_RELATIONSHIPS="$((echo '{'; for r in ${relationships[@]::${#relationships[@]}-1}; do echo $r | base64 -d; printf ', \n'; done; echo ${relationships[@]: -1:1} | base64 -d; echo ' }') | ${BASE64_ENCODE})"
#printf "PLATFORM_RELATIONSHIPS=$(echo $PLATFORM_RELATIONSHIPS | base64 -d)"
PLATFORM_RELATIONSHIPS="$((echo '{'; for r in ${relationships[@]::${#relationships[@]}-1}; do echo $r | ${BASE64_DECODE}; printf ', \n'; done; echo ${relationships[@]: -1:1} | ${BASE64_DECODE}; echo ' }') | ${BASE64_ENCODE})"
#printf "PLATFORM_RELATIONSHIPS=$(echo $PLATFORM_RELATIONSHIPS | ${BASE64_DECODE})"
if [ -f config.platformsh.yaml ] && ! grep '#ddev-generated' config.platformsh.yaml; then
echo "Existing config.platformsh.yaml does not have #ddev-generated, so can't be updated"
Expand Down
2 changes: 1 addition & 1 deletion tests/drupal8.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ teardown() {
@test "drupal8" {
load per_test.sh
template="drupal8"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
for source in $PROJECT_SOURCE ddev/ddev-platformsh; do
per_test_setup

run ddev exec -s db 'echo ${DDEV_DATABASE}'
Expand Down
4 changes: 2 additions & 2 deletions tests/drupal9.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ teardown() {
@test "drupal9" {
load per_test.sh
template="drupal9"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
for source in $PROJECT_SOURCE ddev/ddev-platformsh; do
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"
assert_output "8.1"

ddev exec 'touch ${PLATFORM_CACHE_DIR}/junk.txt'

Expand Down
2 changes: 1 addition & 1 deletion tests/laravel.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ teardown() {
@test "laravel" {
load per_test.sh
template="laravel"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
for source in $PROJECT_SOURCE ddev/ddev-platformsh; do
per_test_setup

run ddev exec "php --version | awk 'NR==1 { sub(/\.[0-9]+$/, \"\", \$2); print \$2 }'"
Expand Down
3 changes: 3 additions & 0 deletions tests/per_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ per_test_setup() {
ddev get ${PROJECT_SOURCE}
echo "# doing ddev restart with template ${template} PROJNAME=${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev restart >/dev/null
if [ -f ${PROJECT_SOURCE}/tests/testdata/${template}/db.sql.gz ]; then
ddev import-db --src=${PROJECT_SOURCE}/tests/testdata/${template}/db.sql.gz
fi
}

per_test_teardown() {
Expand Down
2 changes: 1 addition & 1 deletion tests/php.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ teardown() {
@test "php" {
load per_test.sh
template="php"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
for source in $PROJECT_SOURCE ddev/ddev-platformsh; do
per_test_setup

run ddev exec "php --version | awk 'NR==1 { sub(/\.[0-9]+$/, \"\", \$2); print \$2 }'"
Expand Down
Binary file added tests/testdata/wordpress-bedrock/db.sql.gz
Binary file not shown.
32 changes: 32 additions & 0 deletions tests/wordpress-bedrock.bats
Original file line number Diff line number Diff line change
@@ -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
}

teardown() {
load teardown.sh
}

@test "wordpress-bedrock" {
load per_test.sh
template="wordpress-bedrock"
for source in $PROJECT_SOURCE ddev/ddev-platformsh; do
per_test_setup
printf "<?php\nprint 'DB_USER=' . getenv('DB_USER') . ' DB_PASSWORD=' . getenv('DB_PASSWORD');" >web/phpinfo.php
run curl -s http://${PROJNAME}.ddev.site/phpinfo.php
assert_line "DB_USER=db DB_PASSWORD=db"
curl -s http://${PROJNAME}.ddev.site | grep "Mindblown: a blog about"
run ddev exec -s db 'echo ${DDEV_DATABASE}'
assert_output "mariadb:10.4"
run ddev exec 'echo $PLATFORM_RELATIONSHIPS | base64 -d | jq -r ".database[0].username"'
assert_output "db"
run ddev exec "php --version | awk 'NR==1 { sub(/\.[0-9]+$/, \"\", \$2); print \$2 }'"
assert_output "8.1"
ddev describe -j >describe.json
run jq -r .raw.docroot <describe.json
assert_output "web"
per_test_teardown
done
}
2 changes: 1 addition & 1 deletion tests/wordpress-composer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ teardown() {
@test "wordpress-composer" {
load per_test.sh
template="wordpress-composer"
for source in $PROJECT_SOURCE platformsh/ddev-platformsh; do
for source in $PROJECT_SOURCE ddev/ddev-platformsh; do
per_test_setup

run ddev exec -s db 'echo ${DDEV_DATABASE}'
Expand Down

0 comments on commit 74eb139

Please sign in to comment.