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

Feature/fix passing args ahoy cli #1290

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,15 @@ commands:

cli:
usage: Start a shell or run a command inside the CLI service container.
# Drop into shell if no arguments were supplied.
# If arguments were supplied - a new shell will be started with environment
# variables passed from the host environment and filtered by prefix.
# This allows passing the host environment variables to a container without
# the need to restart it.
# Escape double quotes with \" (slash double-quote) when passing arguments
# containing spaces.
# Drop into a shell if no arguments are supplied, otherwise run the command.
# Environment variables are passed from the host and filtered by prefix.
# Use \" (slash followed by a double quote) to escape double quotes in
# arguments that contain spaces.
cmd: |
if [ "${#}" -ne 0 ]; then
docker compose exec $(env | cut -f1 -d= | grep "TERM\|COMPOSE_\|GITHUB_\|DOCKER_\DRUPAL_\|DREVOPS_" | sed 's/^/-e /') -T cli bash -c "$*"
docker compose exec $(env | cut -f1 -d= | grep "TERM\|COMPOSE_\|GITHUB_\|DOCKER_\|DRUPAL_\|DREVOPS_" | sed 's/^/-e /') -T cli bash -c "$*"
else
docker compose exec $(env | cut -f1 -d= | grep "TERM\|COMPOSE_\|GITHUB_\|DOCKER_\DRUPAL_\|DREVOPS_" | sed 's/^/-e /') cli bash
docker compose exec $(env | cut -f1 -d= | grep "TERM\|COMPOSE_\|GITHUB_\|DOCKER_\|DRUPAL_\|DREVOPS_" | sed 's/^/-e /') cli bash
fi

composer:
Expand Down
61 changes: 33 additions & 28 deletions .scaffold/docs/content/workflows/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Defined in: `scripts/drevops/download-db-lagoon.sh`

The SSH user of the Lagoon environment.

Default value: `LAGOON_PROJECT-${DREVOPS_DB_DOWNLOAD_ENVIRONMENT`
Default value: `${LAGOON_PROJECT}-${DREVOPS_DB_DOWNLOAD_ENVIRONMENT}`

Defined in: `scripts/drevops/download-db-lagoon.sh`

Expand Down Expand Up @@ -364,7 +364,7 @@ Defined in: `.env`, `scripts/drevops/download-db.sh`

Default SSH file used if custom fingerprint is not provided.

Default value: `HOME/.ssh/id_rsa`
Default value: `${HOME}/.ssh/id_rsa`

Defined in: `scripts/drevops/download-db-lagoon.sh`

Expand All @@ -388,7 +388,7 @@ Defined in: `scripts/drevops/export-db-docker.sh`

Directory with database image archive file.

Default value: `DREVOPS_DB_DIR`
Default value: `${DREVOPS_DB_DIR}`

Defined in: `scripts/drevops/export-db-docker.sh`

Expand Down Expand Up @@ -497,15 +497,15 @@ Defined in: `scripts/drevops/deploy-artifact.sh`

Deployment log file name.

Default value: `DREVOPS_DEPLOY_ARTIFACT_ROOT/deployment_log.txt`
Default value: `${DREVOPS_DEPLOY_ARTIFACT_ROOT}/deployment_log.txt`

Defined in: `scripts/drevops/deploy-artifact.sh`

### `DREVOPS_DEPLOY_ARTIFACT_ROOT`

The root directory where the deployment script should run from. Defaults to<br />the current directory.

Default value: `(pwd)`
Default value: `$(pwd)`

Defined in: `scripts/drevops/deploy-artifact.sh`

Expand Down Expand Up @@ -603,7 +603,7 @@ Defined in: `scripts/drevops/deploy-lagoon.sh`

Default SSH file used if custom fingerprint is not provided.

Default value: `HOME/.ssh/id_rsa`
Default value: `${HOME}/.ssh/id_rsa`

Defined in: `scripts/drevops/deploy-artifact.sh`, `scripts/drevops/deploy-lagoon.sh`

Expand Down Expand Up @@ -667,15 +667,15 @@ Defined in: `scripts/drevops/doctor.sh`

### `DREVOPS_DOCTOR_CHECK_CONTAINERS`

Default value: `UNDEFINED`
Default value: `0`

Defined in: `scripts/drevops/doctor.sh`

### `DREVOPS_DOCTOR_CHECK_MINIMAL`

Check minimal Doctor requirements.

Default value: `UNDEFINED`
Default value: `0`

Defined in: `scripts/drevops/doctor.sh`

Expand Down Expand Up @@ -721,7 +721,7 @@ Defined in: `scripts/drevops/provision.sh`

Path to private files.

Default value: `./${DREVOPS_WEBROOT/sites/default/files/private}`
Default value: `./${DREVOPS_WEBROOT}/sites/default/files/private`

Defined in: `scripts/drevops/provision.sh`

Expand Down Expand Up @@ -899,7 +899,7 @@ Defined in: `.env`, `scripts/drevops/notify.sh`

Environment URL to notify about.

Default value: `DREVOPS_NOTIFY_ENVIRONMENT_URL`
Default value: `${DREVOPS_NOTIFY_ENVIRONMENT_URL}`

Defined in: `scripts/drevops/notify-email.sh`

Expand All @@ -915,7 +915,7 @@ Defined in: `.env`, `scripts/drevops/notify-email.sh`

Project name to notify.

Default value: `DREVOPS_NOTIFY_PROJECT`
Default value: `${DREVOPS_NOTIFY_PROJECT}`

Defined in: `scripts/drevops/notify-email.sh`

Expand All @@ -933,7 +933,7 @@ Defined in: `.env`, `scripts/drevops/notify-email.sh`

Git reference to notify about.

Default value: `DREVOPS_NOTIFY_REF`
Default value: `${DREVOPS_NOTIFY_REF}`

Defined in: `scripts/drevops/notify-email.sh`

Expand Down Expand Up @@ -965,7 +965,7 @@ Defined in: `scripts/drevops/notify-github.sh`, `scripts/drevops/notify.sh`

Deployment GitHub token.

Default value: `GITHUB_TOKEN`
Default value: `${GITHUB_TOKEN}`

Defined in: `scripts/drevops/notify-github.sh`

Expand Down Expand Up @@ -1043,7 +1043,7 @@ Defined in: `scripts/drevops/notify-newrelic.sh`

NewRelic application name as it appears in the dashboard.

Default value: `DREVOPS_NOTIFY_NEWRELIC_PROJECT-${DREVOPS_NOTIFY_NEWRELIC_REF}`
Default value: `${DREVOPS_NOTIFY_NEWRELIC_PROJECT}-${DREVOPS_NOTIFY_NEWRELIC_REF}`

Defined in: `scripts/drevops/notify-newrelic.sh`

Expand All @@ -1053,15 +1053,15 @@ Optional NewRelic notification changelog.

Defaults to the description.

Default value: `DREVOPS_NOTIFY_NEWRELIC_DESCRIPTION`
Default value: `${DREVOPS_NOTIFY_NEWRELIC_DESCRIPTION}`

Defined in: `scripts/drevops/notify-newrelic.sh`

### `DREVOPS_NOTIFY_NEWRELIC_DESCRIPTION`

Optional NewRelic notification description.

Default value: `DREVOPS_NOTIFY_NEWRELIC_REF deployed`
Default value: `${DREVOPS_NOTIFY_NEWRELIC_REF} deployed`

Defined in: `scripts/drevops/notify-newrelic.sh`

Expand All @@ -1077,23 +1077,23 @@ Defined in: `scripts/drevops/notify-newrelic.sh`

Project name to notify.

Default value: `DREVOPS_NOTIFY_PROJECT`
Default value: `${DREVOPS_NOTIFY_PROJECT}`

Defined in: `scripts/drevops/notify-newrelic.sh`

### `DREVOPS_NOTIFY_NEWRELIC_REF`

Deployment reference, such as a git branch or pr.

Default value: `DREVOPS_NOTIFY_REF`
Default value: `${DREVOPS_NOTIFY_REF}`

Defined in: `scripts/drevops/notify-newrelic.sh`

### `DREVOPS_NOTIFY_NEWRELIC_SHA`

Deployment commit reference, such as a git SHA.

Default value: `DREVOPS_NOTIFY_SHA`
Default value: `${DREVOPS_NOTIFY_SHA}`

Defined in: `scripts/drevops/notify-newrelic.sh`

Expand All @@ -1109,7 +1109,7 @@ Defined in: `scripts/drevops/notify-newrelic.sh`

The project to notify about.

Default value: `DREVOPS_PROJECT`
Default value: `${DREVOPS_PROJECT}`

Defined in: `scripts/drevops/notify.sh`

Expand Down Expand Up @@ -1185,7 +1185,7 @@ Defined in: `.env`, `.env.local.default`, `scripts/drevops/provision.sh`

Flag to skip running of operations after site provision is complete.<br />Useful to only import the database from file (or install from profile) and not<br />perform any additional operations. For example, when need to capture database<br />state before any updates ran (for example, DB caching in CI).

Default value: `UNDEFINED`
Default value: `0`

Defined in: `scripts/drevops/provision.sh`

Expand Down Expand Up @@ -1277,15 +1277,20 @@ Defined in: `scripts/drevops/info.sh`

Default SSH key file.

Default value: `HOME/.ssh/id_rsa`
Default value: `${HOME}/.ssh/id_rsa`

Defined in: `scripts/drevops/doctor.sh`

### `DREVOPS_SSH_PREFIX`

Default value: `DEPLOY" ./scripts/drevops/setup-ssh.sh`
Prefix used to load SSH key from prefixes environment variables:
- DREVOPS_[`${DREVOPS_SSH_PREFIX}`](#drevops_ssh_prefix)_SSH_FINGERPRINT - the variable name with the<br />SSH key fingerprint value.
- DREVOPS_[`${DREVOPS_SSH_PREFIX}`](#drevops_ssh_prefix)_SSH_FILE - the variable name with the SSH
key file path.

Default value: `UNDEFINED`

Defined in: `scripts/drevops/deploy-artifact.sh`, `scripts/drevops/deploy-lagoon.sh`, `scripts/drevops/download-db-lagoon.sh`, `scripts/drevops/mirror-code.sh`, `scripts/drevops/setup-ssh.sh`, `scripts/drevops/task-custom-lagoon.sh`
Defined in: `scripts/drevops/setup-ssh.sh`

### `DREVOPS_TASK_COPY_DB_ACQUIA_DST`

Expand Down Expand Up @@ -1435,7 +1440,7 @@ Defined in: `scripts/drevops/task-custom-lagoon.sh`

The Lagoon project to run tasks for.

Default value: `LAGOON_PROJECT`
Default value: `${LAGOON_PROJECT}`

Defined in: `scripts/drevops/task-custom-lagoon.sh`

Expand Down Expand Up @@ -1475,7 +1480,7 @@ Defined in: `scripts/drevops/task-purge-cache-acquia.sh`

Default SSH file used if custom fingerprint is not provided.

Default value: `HOME/.ssh/id_rsa`
Default value: `${HOME}/.ssh/id_rsa`

Defined in: `scripts/drevops/task-custom-lagoon.sh`

Expand Down Expand Up @@ -1575,7 +1580,7 @@ Defined in: `.env`, `scripts/drevops/provision.sh`

Drupal site name.<br />Used only when installing from profile.

Default value: `DREVOPS_PROJECT`
Default value: `${DREVOPS_PROJECT}`

Defined in: `.env`, `scripts/drevops/provision.sh`

Expand Down Expand Up @@ -1643,7 +1648,7 @@ Defined in: `LAGOON ENVIRONMENT`

Special variable to remap target env to the sub-domain prefix based on UI name.

Default value: `target_env`
Default value: `${target_env}`

Defined in: `scripts/drevops/task-purge-cache-acquia.sh`

8 changes: 8 additions & 0 deletions .scaffold/tests/bats/_helper.workflow.bash
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@
assert_success
assert_output_not_contains "Containers are not running."
assert_output_contains "Test from inside of the container"

# Assert that only allowed filtered variables are passed from the environment.
export DRUPAL_UNFILTERED_VAR="drupalvar"
export OTHER_FILTERED_VAR="othervar"

Check warning on line 185 in .scaffold/tests/bats/_helper.workflow.bash

View check run for this annotation

Codecov / codecov/patch

.scaffold/tests/bats/_helper.workflow.bash#L184-L185

Added lines #L184 - L185 were not covered by tests

run ahoy cli "echo \$DRUPAL_UNFILTERED_VAR"
asser_output_contains "${DRUPAL_UNFILTERED_VAR}"
asser_output_not_contains "${OTHER_FILTERED_VAR}"

Check warning on line 189 in .scaffold/tests/bats/_helper.workflow.bash

View check run for this annotation

Codecov / codecov/patch

.scaffold/tests/bats/_helper.workflow.bash#L187-L189

Added lines #L187 - L189 were not covered by tests
}

assert_env_changes() {
Expand Down
1 change: 1 addition & 0 deletions scripts/drevops/github-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ jsonval() {
}

uriencode() {
local s
s="${1//'%'/%25}"
s="${s//' '/%20}"
s="${s//'"'/%22}"
Expand Down
Loading