Skip to content

Commit

Permalink
[#1144] Added support for .env.local in docker-compose.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 19, 2024
1 parent 4c86e94 commit 248f4f9
Show file tree
Hide file tree
Showing 6 changed files with 1,186 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .drevops/tests/bats/docker-compose.bats
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ load _helper.bash
assert_files_equal docker-compose.actual.json docker-compose.env_mod.json
}

@test "Docker Compose: default with .env and .env.local" {
prepare_docker_compose

cp "${ROOT_DIR}/.env" .env
cp "${ROOT_DIR}/.env.local.default" .env.local

substep "Validate configuration"
run docker compose -f docker-compose.yml config
assert_success

substep "Compare with fixture"
prepare_docker_compose_fixtures

docker compose -f docker-compose.yml config --format json >docker-compose.actual.json
process_docker_compose_json docker-compose.actual.json
update_docker_compose_fixture "${PWD}"/docker-compose.actual.json docker-compose.env_local.json

assert_files_equal docker-compose.actual.json docker-compose.env_local.json
}

# Prepare current docker compose file for testing.
prepare_docker_compose() {
cp "${ROOT_DIR}/docker-compose.yml" docker-compose.yml
Expand All @@ -92,6 +112,7 @@ prepare_docker_compose_fixtures() {
cp "${ROOT_DIR}/.drevops/tests/bats/fixtures/docker-compose.env.json" docker-compose.env.json
cp "${ROOT_DIR}/.drevops/tests/bats/fixtures/docker-compose.env_mod.json" docker-compose.env_mod.json
cp "${ROOT_DIR}/.drevops/tests/bats/fixtures/docker-compose.noenv.json" docker-compose.noenv.json
cp "${ROOT_DIR}/.drevops/tests/bats/fixtures/docker-compose.env_local.json" docker-compose.env_local.json
replace_string_content "FIXTURE_CUR_DIR" "${CURRENT_PROJECT_DIR}" "${CURRENT_PROJECT_DIR}"

# Replace symlink /private paths in MacOS.
Expand Down Expand Up @@ -127,6 +148,12 @@ process_docker_compose_json() {
}
});
array_walk_recursive(\$data, function (&\$value) {
if (\$value !== null && str_contains(\$value, \"$HOME\")) {
\$value = str_replace(\"$HOME\", 'HOME', \$value);
}
});
\$data = json_encode(\$data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
print \$data;
Expand Down
210 changes: 210 additions & 0 deletions .drevops/tests/bats/fixtures/docker-compose.env.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down Expand Up @@ -66,11 +96,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down Expand Up @@ -109,11 +169,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down Expand Up @@ -161,11 +251,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down Expand Up @@ -210,11 +330,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down Expand Up @@ -269,11 +419,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down Expand Up @@ -338,11 +518,41 @@
"entrypoint": null,
"environment": {
"CI": "true",
"DREVOPS_ACQUIA_APP_NAME": "",
"DREVOPS_DB_DIR": "./.data",
"DREVOPS_DB_DOWNLOAD_ACQUIA_DB_NAME": "your_site",
"DREVOPS_DB_DOWNLOAD_CURL_URL": "https://github.com/drevops/drevops/releases/download/1.18.0/db_d10.demo.sql",
"DREVOPS_DB_DOWNLOAD_ENVIRONMENT": "prod",
"DREVOPS_DB_DOWNLOAD_FTP_FILE": "db.sql",
"DREVOPS_DB_DOWNLOAD_FTP_HOST": "",
"DREVOPS_DB_DOWNLOAD_FTP_PORT": "21",
"DREVOPS_DB_DOWNLOAD_SOURCE": "curl",
"DREVOPS_DB_FILE": "db.sql",
"DREVOPS_DEPLOY_TYPES": "artifact",
"DREVOPS_LAGOON_PRODUCTION_BRANCH": "main",
"DREVOPS_LOCALDEV_URL": "star_wars.docker.amazee.io",
"DREVOPS_NOTIFY_CHANNELS": "email",
"DREVOPS_NOTIFY_EMAIL_FROM": "[email protected]",
"DREVOPS_NOTIFY_EMAIL_RECIPIENTS": "[email protected]",
"DREVOPS_PROJECT": "your_site",
"DREVOPS_PROVISION_OVERRIDE_DB": "0",
"DREVOPS_PROVISION_SANITIZE_DB_EMAIL": "user_%[email protected]",
"DREVOPS_PROVISION_SANITIZE_DB_SKIP": "0",
"DREVOPS_PROVISION_USE_MAINTENANCE_MODE": "1",
"DREVOPS_PROVISION_USE_PROFILE": "0",
"DREVOPS_TZ": "Australia/Melbourne",
"DREVOPS_WEBROOT": "web",
"DRUPAL_CLAMAV_ENABLED": "1",
"DRUPAL_CLAMAV_MODE": "daemon",
"DRUPAL_PROFILE": "standard",
"DRUPAL_REDIS_ENABLED": "0",
"DRUPAL_SHIELD_PASS": "",
"DRUPAL_SHIELD_PRINT": "Restricted access.",
"DRUPAL_SHIELD_USER": "",
"DRUPAL_STAGE_FILE_PROXY_ORIGIN": "https://your-site-url.example/",
"DRUPAL_THEME": "your_site_theme",
"LAGOON_ENVIRONMENT_TYPE": "local",
"LAGOON_PROJECT": "your_site",
"LAGOON_ROUTE": "star_wars.docker.amazee.io",
"MARIADB_DATABASE": "drupal",
"MARIADB_HOST": "mariadb",
Expand Down
Loading

0 comments on commit 248f4f9

Please sign in to comment.