Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Platform.sh specific app pull, fixes #5727 #5728

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/content/users/providers/platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ web_environment:
## Platform.sh Per-Project Configuration

1. Check out the site from Platform.sh and configure it with [`ddev config`](../usage/commands.md#config). You’ll want to use [`ddev start`](../usage/commands.md#start) and make sure the basic functionality is working.
2. Add `PLATFORM_PROJECT` and `PLATFORM_ENVIRONMENT` variables to your project.
2. Add `PLATFORM_PROJECT` and `PLATFORM_ENVIRONMENT` and `PLATFORM_APP` (optional) variables to your project.
nir-riskified marked this conversation as resolved.
Show resolved Hide resolved

* Either in `.ddev/config.yaml` or a `.ddev/config.*.yaml` file:

```yaml
web_environment:
- PLATFORM_PROJECT=nf4amudfn23biyourproject
- PLATFORM_ENVIRONMENT=main
- PLATFORM_APP=app (optional)
nir-riskified marked this conversation as resolved.
Show resolved Hide resolved
```

* Or with a command from your terminal:
Expand All @@ -42,6 +43,9 @@ web_environment:
4. Run `ddev pull platform`. After you agree to the prompt, the current upstream databases and files will be downloaded.
5. Optionally use `ddev push platform` to push local files and database to Platform.sh. The [`ddev push`](../usage/commands.md#push) command can potentially damage your production site, so we don’t recommend using it.

### Multiple apps
It is necessary to specify PLATFORM_APP variable under web_environment if your environment contains more than one app
nir-riskified marked this conversation as resolved.
Show resolved Hide resolved

### Managing Multiple Databases

If your project has only one database, it will automatically be pulled into and pushed from DDEV’s `'db'` database.
Expand Down
15 changes: 8 additions & 7 deletions pkg/ddevapp/dotddev_assets/providers/platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
# web_environment:
# - PLATFORMSH_CLI_TOKEN=abcdeyourtoken
# ```
# 3. Add PLATFORM_PROJECT and PLATFORM_ENVIRONMENT variables to your project `.ddev/config.yaml` or a `.ddev/config.platform.yaml`
# 3. Add PLATFORM_PROJECT and PLATFORM_ENVIRONMENT and PLATFORM_APP (optional) variables to your project `.ddev/config.yaml` or a `.ddev/config.platform.yaml`
nir-riskified marked this conversation as resolved.
Show resolved Hide resolved
# ```yaml
# web_environment:
# - PLATFORM_PROJECT=nf4amudfn23biyourproject
# - PLATFORM_ENVIRONMENT=main
# - PLATFORM_APP=app
# 4. `ddev restart`
# 5. Run `ddev pull platform`. After you agree to the prompt, the current upstream database and files will be downloaded.
# 6. Optionally use `ddev push platform` to push local files and database to platform.sh. Note that `ddev push` is a command that can potentially damage your production site, so this is not recommended.
Expand Down Expand Up @@ -51,7 +52,7 @@ db_pull_command:
ls /var/www/html/.ddev >/dev/null # This just refreshes stale NFS if possible
# /tmp/db_relationships.yaml is the full yaml output of the database relationships
db_relationships_file=/tmp/db_relationships.yaml
PLATFORM_RELATIONSHIPS="" platform relationships -y -e "${PLATFORM_ENVIRONMENT}" | yq 'with_entries(select(.[][].type == "mariadb:*" or .[][].type == "*mysql:*" or .[][].type == "postgresql:*")) ' >${db_relationships_file}
PLATFORM_RELATIONSHIPS="" platform relationships -y -e "${PLATFORM_ENVIRONMENT}" ${PLATFORM_APP:+"--app=${PLATFORM_APP}"} | yq 'with_entries(select(.[][].type == "mariadb:*" or .[][].type == "*mysql:*" or .[][].type == "postgresql:*")) ' >${db_relationships_file}
db_relationships=($(yq ' keys | .[] ' ${db_relationships_file}))
db_names=($(yq '.[][].path' ${db_relationships_file}))
db_count=${#db_relationships[@]}
Expand All @@ -68,18 +69,18 @@ db_pull_command:
db_name="db"
fi

platform db:dump --yes --relationship=${rel} --gzip --file=/var/www/html/.ddev/.downloads/${db_name}.sql.gz --project="${PLATFORM_PROJECT:-setme}" --environment="${PLATFORM_ENVIRONMENT:-setme}"
platform db:dump --yes ${PLATFORM_APP:+"--app=${PLATFORM_APP}"} --relationship=${rel} --gzip --file=/var/www/html/.ddev/.downloads/${db_name}.sql.gz --project="${PLATFORM_PROJECT:-setme}" --environment="${PLATFORM_ENVIRONMENT:-setme}"
done
echo "Downloaded db dumps for databases '${db_names[@]}'"

files_import_command:
command: |
# set -x # You can enable bash debugging output by uncommenting
#set -x # You can enable bash debugging output by uncommenting
set -eu -o pipefail
export PLATFORMSH_CLI_NO_INTERACTION=1
# Use $PLATFORM_MOUNTS if it exists to get list of mounts to download, otherwise just web/sites/default/files (drupal)
declare -a mounts=(${PLATFORM_MOUNTS:-/web/sites/default/files})
platform mount:download --all --yes --quiet --project="${PLATFORM_PROJECT}" --environment="${PLATFORM_ENVIRONMENT}" --target=/var/www/html
platform mount:download --all --yes --quiet --project="${PLATFORM_PROJECT}" --environment="${PLATFORM_ENVIRONMENT}" ${PLATFORM_APP:+"--app=${PLATFORM_APP}"} --target=/var/www/html


# push is a dangerous command. If not absolutely needed it's better to delete these lines.
Expand All @@ -93,7 +94,7 @@ db_push_command:
if [ "${PLATFORM_PRIMARY_RELATIONSHIP:-}" != "" ] ; then
rel="--relationship ${PLATFORM_PRIMARY_RELATIONSHIP}"
fi
gzip -dc db.sql.gz | platform db:sql --project="${PLATFORM_PROJECT}" ${rel:-} --environment="${PLATFORM_ENVIRONMENT}"
gzip -dc db.sql.gz | platform db:sql --project="${PLATFORM_PROJECT}" ${rel:-} --environment="${PLATFORM_ENVIRONMENT}" ${PLATFORM_APP:+"--app=${PLATFORM_APP}"}

# push is a dangerous command. If not absolutely needed it's better to delete these lines.
# TODO: This is a naive, Drupal-centric push, which needs adjustment for the mount to be pushed.
Expand All @@ -103,4 +104,4 @@ files_push_command:
set -eu -o pipefail
export PLATFORMSH_CLI_NO_INTERACTION=1
ls "${DDEV_FILES_DIR}" >/dev/null # This just refreshes stale NFS if possible
platform mount:upload --yes --quiet --project="${PLATFORM_PROJECT}" --environment="${PLATFORM_ENVIRONMENT}" --source="${DDEV_FILES_DIR}" --mount=web/sites/default/files
platform mount:upload --yes --quiet --project="${PLATFORM_PROJECT}" --environment="${PLATFORM_ENVIRONMENT}" ${PLATFORM_APP:+"--app=${PLATFORM_APP}"} --source="${DDEV_FILES_DIR}" --mount=web/sites/default/files