From 5a60858c5597a7b79c046f2ae08eb1ab70df620d Mon Sep 17 00:00:00 2001 From: David Mattei Date: Tue, 8 Oct 2024 23:08:37 +0200 Subject: [PATCH 1/5] fix: build for 5.22.0 --- test/configs/elasticms/demo-dev.env | 6 +- test/configs/elasticms/demo.env | 6 +- test/configs/skeleton/zz-live.env | 4 +- test/docker-compose.yml | 22 ++- test/helpers/containers.bash | 12 +- test/helpers/tests.bash | 3 +- test/tests.bats | 280 +++------------------------- 7 files changed, 52 insertions(+), 281 deletions(-) diff --git a/test/configs/elasticms/demo-dev.env b/test/configs/elasticms/demo-dev.env index f751950..578ef91 100644 --- a/test/configs/elasticms/demo-dev.env +++ b/test/configs/elasticms/demo-dev.env @@ -38,14 +38,14 @@ EMSCO_DATE_TIME_FORMAT='j/m/Y \a\t G:i' EMSCO_DATEPICKER_FORMAT='dd/mm/yyyy' EMSCO_DATEPICKER_WEEKSTART='1' EMSCO_DATEPICKER_DAYSOFWEEK_HIGHLIGHTED='[0,6]' -EMSCO_ALLOW_USER_REGISTRATION='false' -EMSCO_LOG_BY_PASS=true ###< Core ### ###> EMSCH ### +EMSCH_ENV='default' +EMSCH_ENVS='{"default":{"alias":"ems_promo_v2_preview","backend":"http://demo-admin","router": false, "default": true}}' EMSCH_TEMPLATE_EMS_LINK='@EMSCH/template/ems/{type}.ems_link.twig' EMSCH_LOCALES='["en","fr","nl","de"]' EMSCH_TRANSLATION_TYPE='label' EMSCH_ROUTE_TYPE='route' -EMSCH_TEMPLATES='{"template":{"name":"name","code":"body"}}' +EMSCH_TEMPLATES='{"template": {"name": "name","code": "body"},"template_ems": {"name": "name","code": "body"}}' ###< EMSCH ### \ No newline at end of file diff --git a/test/configs/elasticms/demo.env b/test/configs/elasticms/demo.env index 86652d3..1880ecb 100644 --- a/test/configs/elasticms/demo.env +++ b/test/configs/elasticms/demo.env @@ -38,14 +38,14 @@ EMSCO_DATE_TIME_FORMAT='j/m/Y \a\t G:i' EMSCO_DATEPICKER_FORMAT='dd/mm/yyyy' EMSCO_DATEPICKER_WEEKSTART='1' EMSCO_DATEPICKER_DAYSOFWEEK_HIGHLIGHTED='[0,6]' -EMSCO_ALLOW_USER_REGISTRATION='false' -EMSCO_LOG_BY_PASS=true ###< Core ### ###> EMSCH ### +EMSCH_ENV='default' +EMSCH_ENVS='{"default":{"alias":"ems_promo_v2_preview","backend":"http://demo-admin","router": false, "default": true}}' EMSCH_TEMPLATE_EMS_LINK='@EMSCH/template/ems/{type}.ems_link.twig' EMSCH_LOCALES='["en","fr","nl","de"]' EMSCH_TRANSLATION_TYPE='label' EMSCH_ROUTE_TYPE='route' -EMSCH_TEMPLATES='{"template":{"name":"name","code":"body"}}' +EMSCH_TEMPLATES='{"template":{"name":"name","code":"body"},"template_ems":{"name":"name","code":"body"}}' ###< EMSCH ### \ No newline at end of file diff --git a/test/configs/skeleton/zz-live.env b/test/configs/skeleton/zz-live.env index 05c7009..c04091f 100644 --- a/test/configs/skeleton/zz-live.env +++ b/test/configs/skeleton/zz-live.env @@ -1,5 +1,5 @@ ###> Apache ### -SERVER_NAME='demo' +SERVER_NAME='demo-live' SERVER_ALIASES='*' APACHE_CACHE_CONTROL='immutable, max-age=63072000, public' APACHE_ENVIRONMENTS='[]' @@ -37,4 +37,4 @@ EMSCH_TEMPLATE_EMS_LINK='@EMSCH/template/ems/{type}.ems_link.twig' ###> EMS Form ### EMSF_LOAD_FROMJSON=true -###< EMS Form ### +###< EMS Form ### \ No newline at end of file diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 70089f2..463f855 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -109,10 +109,8 @@ services: networks: default: aliases: - - demo-admin - demo-admin-dev - - demo-pgsql-admin - - demo-pgsql-admin-dev + - demo-admin container_name: ems environment: - AWS_S3_STORAGE_BUCKET_NAME=${BATS_S3_STORAGE_BUCKET_NAME} @@ -137,12 +135,22 @@ services: - JOBS_ENABLED=${BATS_JOBS_ENABLED} - METRICS_ENABLED=${BATS_METRICS_ENABLED} - CLI_PHP_MEMORY_LIMIT=512M + volumes: + - ./demo/configs/admin:/opt/src/configs/admin + - ./demo/configs/document:/opt/src/configs/document command: ["wait-for-it", "${BATS_DB_HOST}:${BATS_DB_PORT}", "--", "/usr/bin/supervisord", "-c", "/etc/supervisord/supervisord.conf"] mem_limit: 512m + ports: + - "8881:9000" emsch: image: ${BATS_DOCKER_IMAGE_NAME} container_name: emsch + networks: + default: + aliases: + - demo-live + - demo-preview-dev environment: - APP_ENV=dev - REDIS_HOST=${BATS_REDIS_HOST} @@ -168,15 +176,15 @@ services: - METRICS_ENABLED=${BATS_METRICS_ENABLED} - VARNISH_ENABLED=${BATS_VARNISH_ENABLED} volumes: - - ./demo/configs/admin:/opt/src/admin - - ./demo/configs/document:/opt/src/document - ./demo/dist:/opt/src/public/skeleton:ro - ./demo/skeleton:/opt/src/local/ems_promo_v2_preview - ./demo/skeleton:/opt/src/local/ems_promo_v2_live - ./demo/skeleton:/opt/src/local/skeleton mem_limit: 512m + ports: + - "8882:9000" networks: default: - external: - name: docker_default + name: docker_default + external: true \ No newline at end of file diff --git a/test/helpers/containers.bash b/test/helpers/containers.bash index 8435af0..76702d6 100644 --- a/test/helpers/containers.bash +++ b/test/helpers/containers.bash @@ -3,9 +3,9 @@ # Removes container $1 function container_clean { run ${BATS_CONTAINER_ENGINE} kill $1 &>/dev/null ||: - sleep .25s + sleep 25 run ${BATS_CONTAINER_ENGINE} rm -vf $1 &>/dev/null ||: - sleep .25s + sleep 25 } # get the ip of container $1 @@ -78,7 +78,7 @@ function container_wait_for_log { local -r container=$1 local -ir timeout_sec=$2 shift 2 - retry $(( $timeout_sec * 2 )) .5s container_assert_log $container "$*" + retry $(( $timeout_sec * 2 )) 5 container_assert_log $container "$*" } # wait for a container to produce a given text in its command output @@ -90,7 +90,7 @@ function container_wait_for_command { local -r cmd=$2 local -ir timeout_sec=$3 shift 3 - retry $(( $timeout_sec * 2 )) .5s container_assert_command $container "$cmd" "$*" + retry $(( $timeout_sec * 2 )) 5 container_assert_command $container "$cmd" "$*" } # wait for a container healthy state @@ -100,5 +100,5 @@ function container_wait_for_healthy { local -r container=$1 local -ir timeout_sec=$2 shift 2 - retry $(( $timeout_sec * 2 )) .5s container_assert_healthy $container -} + retry $(( $timeout_sec * 2 )) 0.5 container_assert_healthy $container +} \ No newline at end of file diff --git a/test/helpers/tests.bash b/test/helpers/tests.bash index 9528740..1aee1b1 100644 --- a/test/helpers/tests.bash +++ b/test/helpers/tests.bash @@ -1,7 +1,6 @@ # Test if requirements are met ( type ${BATS_CONTAINER_ENGINE} &>/dev/null || ( echo "${BATS_CONTAINER_ENGINE} is not available"; exit 1 ) - type ${BATS_CONTAINER_COMPOSE_ENGINE} &>/dev/null || ( echo "${BATS_CONTAINER_COMPOSE_ENGINE} is not available"; exit 1 ) )>&2 TEST_FILE=$(basename $BATS_TEST_FILENAME .bats) @@ -59,4 +58,4 @@ function retry { echo "Command \"$@\" failed $attempts times. Status: $status. Output: $output" >&2 false -} +} \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index 20a276a..faab096 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -212,285 +212,59 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" } -@test "[$TEST_FILE] Login to Elasticms for configuration." { +@test "[$TEST_FILE] Login to Elasticms for admin." { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:login --username=${BATS_ELASTICMS_ADMIN_USERNAME} --password=${BATS_ELASTICMS_ADMIN_PASSWORD} ${BATS_ELASTICMS_SKELETON_BACKEND_URL} + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:login --no-debug ${BATS_ELASTICMS_SKELETON_BACKEND_URL} --username=${BATS_ELASTICMS_ADMIN_USERNAME} --password=${BATS_ELASTICMS_ADMIN_PASSWORD} assert_output -r ".*\[OK\] Welcome ${BATS_ELASTICMS_ADMIN_USERNAME} on ${BATS_ELASTICMS_SKELETON_BACKEND_URL}" } -@test "[$TEST_FILE] Upload Elasticms assets." { +@test "[$TEST_FILE] Restore elasticms configuration" { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:folder-upload -- /opt/src/admin/assets - assert_output -r ".*\[OK\] .* \(on .*\) assets have been uploaded" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:local:upload --filename=/opt/src/local/skeleton/template/asset_hash.twig - assert_output -r ".*\[OK\] Assets .* have been uploaded" - -} - -@test "[$TEST_FILE] Configure Elasticms Filters." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter dutch_stemmer - assert_output -r "filter dutch_stemmer with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter dutch_stop - assert_output -r "filter dutch_stop with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter empty_elision - assert_output -r "filter empty_elision with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter english_stemmer - assert_output -r "filter english_stemmer with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter english_stop - assert_output -r "filter english_stop with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter french_elision - assert_output -r "filter french_elision with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter french_stemmer - assert_output -r "filter french_stemmer with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter french_stop - assert_output -r "filter french_stop with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter german_stemmer - assert_output -r "filter german_stemmer with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update filter german_stop - assert_output -r "filter german_stop with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms Analyzers." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update analyzer alpha_order - assert_output -r "analyzer alpha_order with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update analyzer dutch_for_highlighting - assert_output -r "analyzer dutch_for_highlighting with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update analyzer english_for_highlighting - assert_output -r "analyzer english_for_highlighting with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update analyzer french_for_highlighting - assert_output -r "analyzer french_for_highlighting with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update analyzer german_for_highlighting - assert_output -r "analyzer german_for_highlighting with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update analyzer html_strip - assert_output -r "analyzer html_strip with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms Schedules." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update schedule check-aliases - assert_output -r "schedule check-aliases with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update schedule clear-logs - assert_output -r "schedule clear-logs with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update schedule publish-releases - assert_output -r "schedule publish-releases with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update schedule remove-expired-submissions - assert_output -r "schedule remove-expired-submissions with id .* has been updated" + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:restore --no-debug --configs --configs-folder=/opt/src/configs/admin --force } -@test "[$TEST_FILE] Configure Elasticms Wysiwygs." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update wysiwyg-style-set bootstrap - assert_output -r "wysiwyg-style-set bootstrap with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update wysiwyg-style-set revealjs - assert_output -r "wysiwyg-style-set revealjs with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update wysiwyg-profile Full - assert_output -r "wysiwyg-profile Full with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update wysiwyg-profile Light - assert_output -r "wysiwyg-profile Light with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update wysiwyg-profile Sample - assert_output -r "wysiwyg-profile Sample with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update wysiwyg-profile Standard - assert_output -r "wysiwyg-profile Standard with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms I18N." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n config - assert_output -r "i18n config with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n ems.documentation.body - assert_output -r "i18n ems.documentation.body with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n locale.fr - assert_output -r "i18n locale.fr with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n locale.nl - assert_output -r "i18n locale.nl with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n locale.de - assert_output -r "i18n locale.de with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n locale.en - assert_output -r "i18n locale.en with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n locales - assert_output -r "i18n locales with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update i18n asset.type.manual - assert_output -r "i18n asset.type.manual with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms Environments." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update environment default - assert_output -r "environment default with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update environment preview - assert_output -r "environment preview with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update environment live - assert_output -r "environment live with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms Forms." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form add_menu_item - assert_output -r "form add_menu_item with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form dashboard_default_search_options - assert_output -r "form dashboard_default_search_options with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form dashboard_sitemap_options - assert_output -r "form dashboard_sitemap_options with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form display - assert_output -r "form display with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form label - assert_output -r "form label with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form menu-locales - assert_output -r "form menu-locales with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update form search_fields - assert_output -r "form search_fields with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms ContentTypes." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type category - assert_output -r "content-type category with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type form_instance - assert_output -r "content-type form_instance with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type label - assert_output -r "content-type label with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type media_file - assert_output -r "content-type media_file with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type news - assert_output -r "content-type news with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type page - assert_output -r "content-type page with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type route - assert_output -r "content-type route with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type section - assert_output -r "content-type section with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type slideshow - assert_output -r "content-type slideshow with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type template - assert_output -r "content-type template with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type template_ems - assert_output -r "content-type template_ems with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update content-type user_group - assert_output -r "content-type user_group with id .* has been updated" - -} - -@test "[$TEST_FILE] Configure Elasticms QuerySearches." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update query-search categories - assert_output -r "query-search categories with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update query-search pages - assert_output -r "query-search pages with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update query-search documents - assert_output -r "query-search documents with id .* has been updated" +@test "[$TEST_FILE] Activate Elasticms content types." { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update query-search forms - assert_output -r "query-search forms with id .* has been updated" + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:contenttype:activate --all --force } -@test "[$TEST_FILE] Configure Elasticms Dashboards." { - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update dashboard default-search - assert_output -r "dashboard default-search with id .* has been updated" +@test "[$TEST_FILE] Rebuild Elasticms Environments." { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update dashboard media-library - assert_output -r "dashboard media-library with id .* has been updated" + envs=(`docker exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:environment:list --no-debug`) - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update dashboard sitemap - assert_output -r "dashboard sitemap with id .* has been updated" + for e in ${envs[@]}; do + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:environment:rebuild ${e} --no-debug --yellow-ok + assert_output -r "The alias .* is now point to .*" + done } -@test "[$TEST_FILE] Configure Elasticms Channels." { +@test "[$TEST_FILE] Restore elasticms documents" { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update channel preview - assert_output -r "channel preview with id .* has been updated" - - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:admin:update channel live - assert_output -r "channel live with id .* has been updated" + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:restore --no-debug --documents --documents-folder=/opt/src/configs/document --force } -@test "[$TEST_FILE] Rebuild Elasticms Environments." { - - envs=(`docker exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:environment:list --no-debug`) +@test "[$TEST_FILE] Login to Elasticms for web." { - for e in ${envs[@]}; do - run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:environment:rebuild ${e} --no-debug --yellow-ok - assert_output -r "The alias .* is now point to .*" - done + run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:login ${BATS_ELASTICMS_ADMIN_USERNAME} ${BATS_ELASTICMS_ADMIN_PASSWORD} + assert_output -r ".*\[OK\] Welcome ${BATS_ELASTICMS_ADMIN_USERNAME} on ${BATS_ELASTICMS_SKELETON_BACKEND_URL}" } -@test "[$TEST_FILE] Activate Elasticms content types." { +@test "[$TEST_FILE] Upload web assets." { - run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:contenttype:activate --all --force - - # Missing message when action is done (with success or not) - # assert_output -r "" + run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:upload --filename=/opt/src/local/skeleton/template/asset_hash.twig + assert_output -r ".*\[OK\] Assets .* have been uploaded" } @test "[$TEST_FILE] Push templates, routes and translations." { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:local:push --force + run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:push --force # Missing message when action is done (with success or not) # assert_output -r "" @@ -501,16 +275,6 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:health-check -g } -@test "[$TEST_FILE] Upload documents." { - - for type in form_instance category page section slideshow media_file news user_group; do - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} ems:document:upload ${type} - # Missing message when action is done (with success or not) - # assert_output -r "" - done - -} - @test "[$TEST_FILE] Align live." { run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:environment:align preview live --force --no-debug @@ -593,4 +357,4 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" @test "[$TEST_FILE] Stop all and delete test containers" { command ${BATS_CONTAINER_COMPOSE_ENGINE} -f ${BATS_TEST_DIRNAME%/}/docker-compose.yml down -v -} +} \ No newline at end of file From 640d5e7bc38e8fec23b5f52f3511a4bc4f7d9905 Mon Sep 17 00:00:00 2001 From: Sebastian Molle Date: Mon, 3 Feb 2025 08:08:12 +0100 Subject: [PATCH 2/5] Initial working version --- .build.env | 2 +- .github/workflows/docker-release.yml | 2 +- Dockerfiles/Builder.m4 | 13 +- Dockerfiles/Common.m4 | 21 +- Dockerfiles/Dockerfile.in | 6 +- README.md | 44 ++- bin/container-entrypoint.d/01-install.sh | 34 ++ bin/container-entrypoint.d/02-setup.sh | 18 + .../elasticms.d/01-core.sh | 5 + .../elasticms.d/10-folders.sh | 7 + .../elasticms.d/20-shell-scripts.sh | 8 + .../elasticms.d/30-varnish.sh | 20 + .../elasticms.d/40-apache.sh | 33 ++ .../elasticms.d/41-basicauth.sh | 19 + .../elasticms.d/60-assets.sh | 9 + .../elasticms.d/70-cache.sh | 9 + .../elasticms.d/80-metrics.sh | 13 + .../entrypoint.d/01-core.sh | 13 + .../entrypoint.d/02-php.sh | 9 + .../entrypoint.d/10-folders.sh | 11 + .../entrypoint.d/30-varnish.sh | 31 ++ .../entrypoint.d/40-apache.sh | 52 +++ .../entrypoint.d/41.basicauth.sh | 17 + .../entrypoint.d/80-metrics.sh | 9 + bin/emsch-setup.sh | 368 ------------------ bin/metrics-setup.sh | 170 -------- bin/varnish-setup.sh | 152 -------- config/apache2/conf.d/elasticms.conf.gtpl | 125 ++++++ config/apache2/conf.d/metrics.conf.gtpl | 32 ++ config/php/conf.d/elasticms.ini.tmpl | 2 + config/sbin/instance.sh.gtpl | 7 + config/varnish/default.vcl.gtpl | 101 +++++ etc/php/conf.d/skeleton.ini | 2 - test/docker-compose.yml | 41 +- test/helpers/tests.bash | 4 +- test/tests.bats | 77 ++-- 36 files changed, 723 insertions(+), 763 deletions(-) create mode 100644 bin/container-entrypoint.d/01-install.sh create mode 100644 bin/container-entrypoint.d/02-setup.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/01-core.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/10-folders.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/20-shell-scripts.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/30-varnish.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/40-apache.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/41-basicauth.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/60-assets.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/70-cache.sh create mode 100644 bin/container-entrypoint.d/elasticms.d/80-metrics.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/01-core.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/02-php.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/10-folders.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/30-varnish.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/40-apache.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/41.basicauth.sh create mode 100644 bin/container-entrypoint.d/entrypoint.d/80-metrics.sh delete mode 100644 bin/emsch-setup.sh delete mode 100644 bin/metrics-setup.sh delete mode 100644 bin/varnish-setup.sh create mode 100644 config/apache2/conf.d/elasticms.conf.gtpl create mode 100644 config/apache2/conf.d/metrics.conf.gtpl create mode 100644 config/php/conf.d/elasticms.ini.tmpl create mode 100644 config/sbin/instance.sh.gtpl create mode 100644 config/varnish/default.vcl.gtpl delete mode 100644 etc/php/conf.d/skeleton.ini diff --git a/.build.env b/.build.env index 924b1ed..ffa4948 100644 --- a/.build.env +++ b/.build.env @@ -2,4 +2,4 @@ DOCKER_IMAGE_NAME=docker.io/elasticms/website-skeleton # Default ElasticMS Website Skeleton Version -ELASTICMS_WEB_VERSION=5.7.0 \ No newline at end of file +ELASTICMS_WEB_VERSION=6.0.0 \ No newline at end of file diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index ac37b8b..88b7c13 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -197,7 +197,7 @@ jobs: CONTAINER_ENGINE: docker run: | docker network create docker_default - docker pull docker.io/curlimages/curl:8.1.2 + docker pull docker.io/curlimages/curl:8.11.1 bats -r test/tests.bats sign-dev: diff --git a/Dockerfiles/Builder.m4 b/Dockerfiles/Builder.m4 index 6c9cd26..af8a5c3 100644 --- a/Dockerfiles/Builder.m4 +++ b/Dockerfiles/Builder.m4 @@ -1,9 +1,8 @@ -ENV ELASTICMS_VERSION=${VERSION_ARG:-5.1.2} \ +ENV ELASTICMS_VERSION=${VERSION_ARG:-6.0.0} \ ELASTICMS_DOWNLOAD_URL="https://github.com/ems-project/elasticms-web/archive" -RUN echo "Download and install ElastiCMS ..." \ - && mkdir -p /opt/src \ - && curl -sSfLk ${ELASTICMS_DOWNLOAD_URL}/${ELASTICMS_VERSION}.tar.gz \ - | tar -xzC /opt/src --strip-components=1 \ - && COMPOSER_MEMORY_LIMIT=-1 composer -vvvv install --no-interaction --no-suggest --no-scripts --working-dir /opt/src -o \ - && rm -rf /opt/src/bootstrap/cache/* /opt/src/.env /opt/src/.env.dist \ No newline at end of file +RUN set -x ; \ + mkdir -p /app/src/elasticms ; \ + curl -sSfLk ${ELASTICMS_DOWNLOAD_URL}/${ELASTICMS_VERSION}.tar.gz \ + | tar -xzC /app/src/elasticms --strip-components=1 ; \ + COMPOSER_MEMORY_LIMIT=-1 composer -vvv install --no-interaction --no-suggest --no-scripts --working-dir /app/src/elasticms -o ; \ No newline at end of file diff --git a/Dockerfiles/Common.m4 b/Dockerfiles/Common.m4 index 14948a2..aadaaf2 100644 --- a/Dockerfiles/Common.m4 +++ b/Dockerfiles/Common.m4 @@ -11,23 +11,20 @@ LABEL be.fgov.elasticms.web.build-date=$BUILD_DATE_ARG \ USER root -COPY bin/ /opt/bin/container-entrypoint.d/ -COPY etc/ /usr/local/etc/ -COPY --from=builder /opt/src /opt/src +COPY --chmod=775 --chown=${PUID:-1001}:0 bin/ /app/bin/ +COPY --chmod=664 --chown=${PUID:-1001}:0 config/ /app/config/ -ENV APP_DISABLE_DOTENV=true -ENV EMS_METRIC_PORT="9090" +COPY --chmod=664 --chown=${PUID:-1001}:0 --from=builder /app/src/elasticms /app/src/elasticms -RUN echo -e "\nListen ${EMS_METRIC_PORT}\n" >> /etc/apache2/httpd.conf \ - && echo "Setup permissions on filesystem for non-privileged user ..." \ - && chmod -Rf +x /opt/bin \ - && chown -Rf ${PUID:-1001}:0 /opt \ - && chmod -R ug+rw /opt \ - && find /opt -type d -exec chmod ug+x {} \; +ENV APP_DISABLE_DOTENV=true \ + EMS_METRIC_PORT="9090" \ + PATH=/app/bin:/app/sbin:/usr/local/bin:/usr/bin:$PATH + +RUN find /app -type d -exec chmod ugo+x {} \; USER ${PUID:-1001} EXPOSE ${EMS_METRIC_PORT}/tcp -HEALTHCHECK --start-period=10s --interval=1m --timeout=5s --retries=5 \ +HEALTHCHECK --start-period=5s --interval=1m --timeout=2s --retries=5 \ CMD curl --fail --header "Host: default.localhost" http://localhost:9000/index.php || exit 1 \ No newline at end of file diff --git a/Dockerfiles/Dockerfile.in b/Dockerfiles/Dockerfile.in index 5f4e8c0..53768ff 100644 --- a/Dockerfiles/Dockerfile.in +++ b/Dockerfiles/Dockerfile.in @@ -1,17 +1,17 @@ # syntax=docker/dockerfile:1.3 -FROM docker.io/elasticms/base-php:8.1-apache-dev as builder +FROM docker.io/elasticms/base-php:8.4-apache-dev as builder # include(Args.m4) # include(Builder.m4) -FROM docker.io/elasticms/base-php:8.1-apache as prd +FROM docker.io/elasticms/base-php:8.4-apache as prd LABEL be.fgov.elasticms.web.environment="prd" # include(Args.m4) # include(Common.m4) -FROM docker.io/elasticms/base-php:8.1-apache-dev as dev +FROM docker.io/elasticms/base-php:8.4-apache-dev as dev LABEL be.fgov.elasticms.web.environment="dev" diff --git a/README.md b/README.md index aaba4f3..61e8fa7 100644 --- a/README.md +++ b/README.md @@ -187,4 +187,46 @@ Return WebSite Skeleton Prometheus metrics. | Variable Name | Description | Default | | - | - | - | | METRICS_ENABLED | Add metrics dedicated vhost running on a specific port (9090). | `empty` | -| METRICS_VHOST_SERVER_NAME_CUSTOM | Apache ServerName directive used for dedicated vhost. | `$(hostname -i)` | \ No newline at end of file +| METRICS_VHOST_SERVER_NAME | Apache ServerName directive used for dedicated vhost. | `$(hostname -i)` | + +# 6.x ( PHP v8.4 - Road to ReadOnly Containers ... ) + +- paths : + - /opt/(configs|secrets) -> /app/config/elasticms + -> plus de distinction entre secrets et configmaps + + - /opt/src -> /app/src/elasticms + - /opt/bin -> /app/sbin ( scripts créés dynamiquement , peut-etre être un volume ) + - /tmp -> /app/tmp/elasticms.d + - /var/lib/ems -> deleted + +- utilisation des variables environment non prefixee dans les scripts + - METRICS_ENABLED vs EMS_METRIC_ENABLED + +- rename variables + METRICS_VHOST_SERVER_NAME_CUSTOM -> METRICS_VHOST_SERVER_NAME + ENVIRONMENT_ALIAS -> APACHE_ENVIRONMENT_ALIAS + +- new variables + +export APP_BIN_DIR="/app/sbin" +export APP_SRC_DIR="/app/src/elasticms" +export APP_TMP_DIR="${TMPDIR}" + +export APP_CONFIG_DIR="${APP_TMP_DIR}/elasticms.d" +export APP_CACHE_DIR="/app/var/cache/elasticms" +export APP_LOG_DIR="/app/var/log/elasticms" + +export APACHE_PUBLIC_DIR="${APP_SRC_DIR}/public" +export APACHE_ASSETS_DIR="${APACHE_PUBLIC_DIR}/bundles" + +HTPASSWD_FILE + +true + + + +APP_PUBLIC_DIR +APP_ASSETS_DIR + +- use gtpl ald. tmpl pour éviter gomplate standard de l'image de base. les templates reprennent des variables lues plus tard (dans les fichiers de config ems) \ No newline at end of file diff --git a/bin/container-entrypoint.d/01-install.sh b/bin/container-entrypoint.d/01-install.sh new file mode 100644 index 0000000..9b3ed2e --- /dev/null +++ b/bin/container-entrypoint.d/01-install.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -eo pipefail + +log "INFO" "- Install ElasticMS WebSite Configuration files" + +mkdir -p ${APP_CONFIG_DIR} + +if [ ! -z "$AWS_S3_CONFIG_BUCKET_NAME" ]; then + + export AWS_S3_CONFIG_BUCKET_NAME=${AWS_S3_CONFIG_BUCKET_NAME#s3://} + + list=(`aws s3 ls ${AWS_S3_CONFIG_BUCKET_NAME%/}/ ${AWS_CLI_EXTRA_ARGS} | awk '{print $4}'`) + + for config in ${list[@]}; + do + name=${config%.*} + log "INFO" "+ Install s3://${AWS_S3_CONFIG_BUCKET_NAME%/}/$config to ${APP_CONFIG_DIR}/$name" + aws s3 cp s3://${AWS_S3_CONFIG_BUCKET_NAME%/}/$config ${AWS_CLI_EXTRA_ARGS} - | envsubst > ${APP_CONFIG_DIR}/$name + done + +elif [ "$(ls -A /app/config/elasticms)" ]; then + + for file in /app/config/elasticms/*; do + name=$(basename "$file" .${file##*.}) + log "INFO" "+ Install $file to ${APP_CONFIG_DIR}/$name" + envsubst < $file > ${APP_CONFIG_DIR}/$name + done + +else + + log "INFO" "+ Install default to ${APP_CONFIG_DIR}/default" + env | envsubst > ${APP_CONFIG_DIR}/default + +fi diff --git a/bin/container-entrypoint.d/02-setup.sh b/bin/container-entrypoint.d/02-setup.sh new file mode 100644 index 0000000..60205f6 --- /dev/null +++ b/bin/container-entrypoint.d/02-setup.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -eo pipefail + +log "INFO" "- Configure ElasticMS WebSite Container" + +for I in $(find ${APP_CONFIG_DIR}/* | sort) +do + + log "INFO" "+ Configure ElasticMS [$(basename "$I" .${I##*.})] WebSite instance" + + for FILE in $(find /app/bin/container-entrypoint.d/elasticms.d -iname \*.sh | sort) + do + ELASTICMS_INSTANCE_NAME=$(basename "$I" .${I##*.}) \ + ELASTICMS_INSTANCE_CONFIG_FILE=${I} \ + source ${FILE} + done + +done diff --git a/bin/container-entrypoint.d/elasticms.d/01-core.sh b/bin/container-entrypoint.d/elasticms.d/01-core.sh new file mode 100644 index 0000000..27d9b81 --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/01-core.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -a +source ${ELASTICMS_INSTANCE_CONFIG_FILE} +set +a \ No newline at end of file diff --git a/bin/container-entrypoint.d/elasticms.d/10-folders.sh b/bin/container-entrypoint.d/elasticms.d/10-folders.sh new file mode 100644 index 0000000..2f6c58a --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/10-folders.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +log "INFO" "| Create required folders" + +OUTDIR="${APP_CONFIG_DIR} ${APP_LOG_DIR} ${APP_CACHE_DIR}" + +mkdir -p $OUTDIR diff --git a/bin/container-entrypoint.d/elasticms.d/20-shell-scripts.sh b/bin/container-entrypoint.d/elasticms.d/20-shell-scripts.sh new file mode 100644 index 0000000..4d654cf --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/20-shell-scripts.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +log "INFO" "| Create ElasticMS WebSite Shell script in ${APP_BIN_DIR}" + +gomplate -f /app/config/sbin/instance.sh.gtpl \ + -o ${APP_BIN_DIR}/${ELASTICMS_INSTANCE_NAME} + +chmod a+x ${APP_BIN_DIR}/${ELASTICMS_INSTANCE_NAME} diff --git a/bin/container-entrypoint.d/elasticms.d/30-varnish.sh b/bin/container-entrypoint.d/elasticms.d/30-varnish.sh new file mode 100644 index 0000000..925f718 --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/30-varnish.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +log "INFO" "| Configure Varnish VCL file" + +if [[ ! -z ${VARNISH_ENABLED} ]] && [[ ${VARNISH_ENABLED,,} = true ]]; then + + if [[ -f ${VARNISH_VCL_CONF} ]]; then + + log "INFO" "+ Varnish VCL file [ ${VARNISH_VCL_CONF} ] already exist. Using this VCL with Varnish." + + else + + log "INFO" "+ Varnish VCL file [ ${VARNISH_VCL_CONF} ] not exist. Generation of the VCL dynamically." + + gomplate -f /app/config/varnish/default.vcl.gtpl \ + -o ${VARNISH_VCL_CONF} + + fi + +fi diff --git a/bin/container-entrypoint.d/elasticms.d/40-apache.sh b/bin/container-entrypoint.d/elasticms.d/40-apache.sh new file mode 100644 index 0000000..62e6ec5 --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/40-apache.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +log "INFO" "| Configure ElasticMS Apache VirtualHosts ..." + +if [[ ! -z ${APACHE_ENABLED} ]] && [[ ${APACHE_ENABLED,,} = true ]]; then + + log "INFO" "+ Configure [ ${ELASTICMS_INSTANCE_NAME} ] VirtualHost for ElasticMS WebSite on [ ${SERVER_NAME} ]." + + gomplate -f /app/config/apache2/conf.d/elasticms.conf.gtpl \ + -o /app/etc/apache2/conf.d/${ELASTICMS_INSTANCE_NAME}-app.conf + + cat ${APP_CONFIG_DIR}/${ELASTICMS_INSTANCE_NAME} | sed '/^\s*$/d' | grep -v '^#' | sed "s/\([a-zA-Z0-9_]*\)\=\(.*\)/ SetEnv \1 \2/g" >> /app/etc/apache2/conf.d/${ELASTICMS_INSTANCE_NAME}-app.env + + if [[ ! -z ${METRICS_ENABLED} ]] && [[ ${METRICS_ENABLED,,} = true ]]; then + + if [ ! -f /app/etc/apache2/conf.d/__metrics.conf ] ; then + + if [[ ! -z ${EMS_METRIC_ENABLED} ]] && [[ ${EMS_METRIC_ENABLED,,} = true ]]; then + + log "INFO" "+ Configure [ metrics ] VirtualHost for ElasticMS WebSite on [ ${METRICS_VHOST_SERVER_NAME} ]." + + gomplate -f /app/config/apache2/conf.d/metrics.conf.gtpl \ + -o /app/etc/apache2/conf.d/__metrics.conf + + cat ${APP_CONFIG_DIR}/${ELASTICMS_INSTANCE_NAME} | sed '/^\s*$/d' | grep -v '^#' | sed "s/\([a-zA-Z0-9_]*\)\=\(.*\)/SetEnv \1 \2/g" >> /app/etc/apache2/conf.d/__metrics.env + + fi + + fi + + fi + +fi diff --git a/bin/container-entrypoint.d/elasticms.d/41-basicauth.sh b/bin/container-entrypoint.d/elasticms.d/41-basicauth.sh new file mode 100644 index 0000000..7378ee6 --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/41-basicauth.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +if [[ -n ${APACHE_PROTECTED_URL} ]]; then + + log "INFO" "+ Configure Basic Authentification on [ ${APACHE_PROTECTED_URL} ]." + + if ! [ -w ${HTPASSWD_FILE} ]; then + + htpasswd -bc ${HTPASSWD_FILE} ${HTPASSWD_USERNAME} ${HTPASSWD_PASSWORD} + + if [ $? -ne 0 ]; then + log "ERROR" "! Something was wrong when we create .htpasswd file !" + fi + + else + log "WARN" "! .htpasswd file already exist. We use it to protect !" + fi + +fi diff --git a/bin/container-entrypoint.d/elasticms.d/60-assets.sh b/bin/container-entrypoint.d/elasticms.d/60-assets.sh new file mode 100644 index 0000000..236fc49 --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/60-assets.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +log "INFO" "+ Running ElasticMS assets installation to ${APACHE_ASSETS_DIR} folder for [ ${ELASTICMS_INSTANCE_NAME} ] WebSite Domain ..." + +${APP_BIN_DIR}/${ELASTICMS_INSTANCE_NAME} asset:install ${APACHE_PUBLIC_DIR} --symlink --no-interaction --env=prod + +if [ $? -ne 0 ]; then + log "WARN" "! Something doesn't work with ElasticMS assets installation !" +fi diff --git a/bin/container-entrypoint.d/elasticms.d/70-cache.sh b/bin/container-entrypoint.d/elasticms.d/70-cache.sh new file mode 100644 index 0000000..c9d4e46 --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/70-cache.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +log "INFO" "+ Running ElasticMS cache warming up for [ ${ELASTICMS_INSTANCE_NAME} ] WebSite Domain ..." + +${APP_BIN_DIR}/${ELASTICMS_INSTANCE_NAME} cache:warm --no-interaction --env=prod + +if [ $? -ne 0 ]; then + log "WARN" "! Something doesn't work with ElasticMS cache warming up !" +fi \ No newline at end of file diff --git a/bin/container-entrypoint.d/elasticms.d/80-metrics.sh b/bin/container-entrypoint.d/elasticms.d/80-metrics.sh new file mode 100644 index 0000000..5df1d0c --- /dev/null +++ b/bin/container-entrypoint.d/elasticms.d/80-metrics.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if [[ ! -z ${EMS_METRICS_ENABLED} ]] && [[ ${EMS_METRICS_ENABLED,,} = true ]]; then + + log "INFO" "+ Clear ElasticMS metrics for [ ${ELASTICMS_INSTANCE_NAME} ] WebSite Domain ..." + + ${APP_BIN_DIR}/${ELASTICMS_INSTANCE_NAME} ems:metric:collect --clear + + if [ $? -ne 0 ]; then + log "WARN" "! Something doesn't work with ElasticMS metrics clearing !" + fi + +fi \ No newline at end of file diff --git a/bin/container-entrypoint.d/entrypoint.d/01-core.sh b/bin/container-entrypoint.d/entrypoint.d/01-core.sh new file mode 100644 index 0000000..c90cbf3 --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/01-core.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +LOG_LEVEL_DEFAULT="WARNING" +CLI_PHP_MEMORY_LIMIT_DEFAULT="512M" + +export LOG_LEVEL=${LOG_LEVEL:-"${LOG_LEVEL_DEFAULT}"} +export CLI_PHP_MEMORY_LIMIT=${CLI_PHP_MEMORY_LIMIT:-"${CLI_PHP_MEMORY_LIMIT_DEFAULT}"} + +if [ ! -z "$AWS_S3_ENDPOINT_URL" ]; then + export AWS_CLI_EXTRA_ARGS="--endpoint-url ${AWS_S3_ENDPOINT_URL}" +fi + +true diff --git a/bin/container-entrypoint.d/entrypoint.d/02-php.sh b/bin/container-entrypoint.d/entrypoint.d/02-php.sh new file mode 100644 index 0000000..4aef7e9 --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/02-php.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +PHP_POST_MAX_SIZE_DEFAULT="128" +PHP_UPLOAD_MAX_FILESIZE_DEFAULT="128" + +export PHP_POST_MAX_SIZE=${PHP_POST_MAX_SIZE:-"${PHP_POST_MAX_SIZE_DEFAULT}"} +export PHP_UPLOAD_MAX_FILESIZE=${PHP_UPLOAD_MAX_FILESIZE:-"${PHP_UPLOAD_MAX_FILESIZE_DEFAULT}"} + +true diff --git a/bin/container-entrypoint.d/entrypoint.d/10-folders.sh b/bin/container-entrypoint.d/entrypoint.d/10-folders.sh new file mode 100644 index 0000000..021af7f --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/10-folders.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +export APP_BIN_DIR="/app/sbin" +export APP_SRC_DIR="/app/src/elasticms" +export APP_TMP_DIR="${TMPDIR}" + +export APP_CONFIG_DIR="${APP_TMP_DIR}/elasticms.d" +export APP_CACHE_DIR="/app/var/cache/elasticms" +export APP_LOG_DIR="/app/var/log/elasticms" + +true diff --git a/bin/container-entrypoint.d/entrypoint.d/30-varnish.sh b/bin/container-entrypoint.d/entrypoint.d/30-varnish.sh new file mode 100644 index 0000000..2685c43 --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/30-varnish.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD_DEFAULT="HEAD" +VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI_DEFAULT="/index.php?varnish" +VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION_DEFAULT="HTTP/1.1" +VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST_DEFAULT="default.localhost" +VARNISH_VCL_BACKEND_PROBE_TIMEOUT_DEFAULT="1s" +VARNISH_VCL_BACKEND_PROBE_INTERVAL_DEFAULT="5s" +VARNISH_VCL_BACKEND_PROBE_WINDOW_DEFAULT="5" +VARNISH_VCL_BACKEND_PROBE_THRESHOLD_DEFAULT="3" + +VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME_DEFAULT="X-Forwarded-Proto" + +VARNISH_VCL_BACKEND_RESPONSE_TTL_DEFAULT="10s" +VARNISH_VCL_BACKEND_RESPONSE_GRACE_DEFAULT="24h" + +export VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_TIMEOUT=${VARNISH_VCL_BACKEND_PROBE_TIMEOUT_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_TIMEOUT_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_INTERVAL=${VARNISH_VCL_BACKEND_PROBE_INTERVAL_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_INTERVAL_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_WINDOW=${VARNISH_VCL_BACKEND_PROBE_WINDOW_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_WINDOW_DEFAULT}"} +export VARNISH_VCL_BACKEND_PROBE_THRESHOLD=${VARNISH_VCL_BACKEND_PROBE_THRESHOLD_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_THRESHOLD_DEFAULT}"} + +export VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME=${VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME_CUSTOM:-"${VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME_DEFAULT}"} + +export VARNISH_VCL_BACKEND_RESPONSE_TTL=${VARNISH_VCL_BACKEND_RESPONSE_TTL_CUSTOM:-"${VARNISH_VCL_BACKEND_RESPONSE_TTL_DEFAULT}"} +export VARNISH_VCL_BACKEND_RESPONSE_GRACE=${VARNISH_VCL_BACKEND_RESPONSE_GRACE_CUSTOM:-"${VARNISH_VCL_BACKEND_RESPONSE_GRACE_DEFAULT}"} + +true \ No newline at end of file diff --git a/bin/container-entrypoint.d/entrypoint.d/40-apache.sh b/bin/container-entrypoint.d/entrypoint.d/40-apache.sh new file mode 100644 index 0000000..9b0becd --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/40-apache.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +export APACHE_PUBLIC_DIR="${APP_SRC_DIR}/public" +export APACHE_ASSETS_DIR="${APACHE_PUBLIC_DIR}/bundles" + +SERVER_NAME_DEFAULT="localhost" +SERVER_ALIASES_DEFAULT="" +ALIAS_DEFAULT="" + +export SERVER_NAME=${SERVER_NAME:-"${SERVER_NAME_DEFAULT}"} +export SERVER_ALIASES=${SERVER_ALIASES:-"${SERVER_ALIASES_DEFAULT}"} +export ALIAS=${ALIAS:-"${ALIAS_DEFAULT}"} + +APACHE_CACHE_CONTROL_DEFAULT="max-age=86400, public" +export APACHE_CACHE_CONTROL=${APACHE_CACHE_CONTROL:-"${APACHE_CACHE_CONTROL_DEFAULT}"} + +APACHE_X_FRAME_OPTIONS_DEFAULT="SAMEORIGIN" +APACHE_X_XSS_PROTECTION_DEFAULT="1" +APACHE_X_CONTENT_TYPE_OPTIONS_DEFAULT="nosniff" + +export APACHE_X_FRAME_OPTIONS=${APACHE_X_FRAME_OPTIONS:-"${APACHE_X_FRAME_OPTIONS_DEFAULT}"} +export APACHE_X_XSS_PROTECTION=${APACHE_X_XSS_PROTECTION:-"${APACHE_X_XSS_PROTECTION_DEFAULT}"} +export APACHE_X_CONTENT_TYPE_OPTIONS=${APACHE_X_CONTENT_TYPE_OPTIONS:-"${APACHE_X_CONTENT_TYPE_OPTIONS_DEFAULT}"} + +APACHE_STRICT_TRANSPORT_SECURITY_DEFAULT="" +APACHE_CONTENT_SECURITY_POLICY_DEFAULT="" +APACHE_REFERRER_POLICY_DEFAULT="" +APACHE_PERMISSIONS_POLICY_DEFAULT="" + +export APACHE_STRICT_TRANSPORT_SECURITY=${APACHE_STRICT_TRANSPORT_SECURITY:-"${APACHE_STRICT_TRANSPORT_SECURITY_DEFAULT}"} +export APACHE_CONTENT_SECURITY_POLICY=${APACHE_CONTENT_SECURITY_POLICY:-"${APACHE_CONTENT_SECURITY_POLICY_DEFAULT}"} +export APACHE_REFERRER_POLICY=${APACHE_REFERRER_POLICY:-"${APACHE_REFERRER_POLICY_DEFAULT}"} +export APACHE_PERMISSIONS_POLICY=${APACHE_PERMISSIONS_POLICY:-"${APACHE_PERMISSIONS_POLICY_DEFAULT}"} + +APACHE_ACCESS_CONTROL_ALLOW_ORIGIN_DEFAULT="" +APACHE_ACCESS_CONTROL_ALLOW_METHODS_DEFAULT="GET" +APACHE_ACCESS_CONTROL_ALLOW_HEADERS_DEFAULT="application/json" + +export APACHE_ACCESS_CONTROL_ALLOW_ORIGIN=${APACHE_ACCESS_CONTROL_ALLOW_ORIGIN:-"${APACHE_ACCESS_CONTROL_ALLOW_ORIGIN_DEFAULT}"} +export APACHE_ACCESS_CONTROL_ALLOW_METHODS=${APACHE_ACCESS_CONTROL_ALLOW_METHODS:-"${APACHE_ACCESS_CONTROL_ALLOW_METHODS_DEFAULT}"} +export APACHE_ACCESS_CONTROL_ALLOW_HEADERS=${APACHE_ACCESS_CONTROL_ALLOW_HEADERS:-"${APACHE_ACCESS_CONTROL_ALLOW_HEADERS_DEFAULT}"} + +APACHE_ENVIRONMENTS_DEFAULT="" +APACHE_CUSTOM_ASSETS_RC_DEFAULT="" + +export APACHE_ENVIRONMENTS=${APACHE_ENVIRONMENTS:-"${APACHE_ENVIRONMENTS_DEFAULT}"} +export APACHE_CUSTOM_ASSETS_RC=${APACHE_CUSTOM_ASSETS_RC:-"${APACHE_CUSTOM_ASSETS_RC_DEFAULT}"} + +APACHE_ENVIRONMENT_ALIAS_DEFAULT="emsch_assets" +export APACHE_ENVIRONMENT_ALIAS=${APACHE_ENVIRONMENT_ALIAS:-"${APACHE_ENVIRONMENT_ALIAS_DEFAULT}"} + +true diff --git a/bin/container-entrypoint.d/entrypoint.d/41.basicauth.sh b/bin/container-entrypoint.d/entrypoint.d/41.basicauth.sh new file mode 100644 index 0000000..3ed363e --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/41.basicauth.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +PROTECTED_URL_DEFAULT="" + +export PROTECTED_URL=${PROTECTED_URL:-"${PROTECTED_URL_DEFAULT}"} + +HTPASSWD_USERNAME_DEFAULT="default" +HTPASSWD_PASSWORD_DEFAULT="password" + +export HTPASSWD_USERNAME=${HTPASSWD_USERNAME:-"${HTPASSWD_USERNAME_DEFAULT}"} +export HTPASSWD_PASSWORD=${HTPASSWD_PASSWORD:-"${HTPASSWD_PASSWORD_DEFAULT}"} + +HTPASSWD_FILE_DEFAULT="/app/etc/apache2/.htpasswd" + +export HTPASSWD_FILE="${HTPASSWD_FILE:-"${HTPASSWD_FILE_DEFAULT}"}" + +true diff --git a/bin/container-entrypoint.d/entrypoint.d/80-metrics.sh b/bin/container-entrypoint.d/entrypoint.d/80-metrics.sh new file mode 100644 index 0000000..a2f7155 --- /dev/null +++ b/bin/container-entrypoint.d/entrypoint.d/80-metrics.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +METRICS_ENABLED_DEFAULT="false" +METRICS_VHOST_SERVER_NAME_DEFAULT=$(hostname -i) + +export METRICS_ENABLED=${METRICS_ENABLED:-"${METRICS_ENABLED_DEFAULT}"} +export METRICS_VHOST_SERVER_NAME=${METRICS_VHOST_SERVER_NAME:-"${METRICS_VHOST_SERVER_NAME_DEFAULT}"} + +true diff --git a/bin/emsch-setup.sh b/bin/emsch-setup.sh deleted file mode 100644 index 75b5d0b..0000000 --- a/bin/emsch-setup.sh +++ /dev/null @@ -1,368 +0,0 @@ -#!/bin/bash - -function create-wrapper-script { - local -r _instance_name=$1 - - mkdir -p /opt/bin - - cat >/opt/bin/$_instance_name <> /etc/apache2/conf.d/${_name}-app.conf << EOL - $(echo ${APACHE_ENVIRONMENTS} | jq -r 'map("Alias "+.alias+"/bundles/emsch_assets /opt/src/public/bundles/"+.env) | join("\n")') - $(echo ${APACHE_ENVIRONMENTS} | jq -r 'map("Alias "+.alias+" /opt/src/public") | join("\n")') - $(echo ${APACHE_ENVIRONMENTS} | jq -r 'map(["RewriteEngine on", "RewriteCond %{REQUEST_URI} !^"+.alias+"/index.php", "RewriteCond %{REQUEST_URI} !'${APACHE_CUSTOM_ASSETS_RC:-^\"+.alias+\"/bundles}'", "RewriteCond %{REQUEST_URI} !^"+.alias+"/favicon.ico$", "RewriteCond %{REQUEST_URI} !^"+.alias+"/apple-touch-icon.png$", "RewriteCond %{REQUEST_URI} !^"+.alias+"/robots.txt$", "RewriteRule ^"+.alias+" "+.alias+"/index.php$1 [PT]"])' | jq -r '.[] | join("\n")') -EOL - - fi - -} - -function setup-only-one-alias { - - if ! [ -z ${ENVIRONMENT_ALIAS+x} ]; then - echo "Configure Apache Alias (/bundles/emsch_assets) [ ${ENVIRONMENT_ALIAS} ] ..." - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Alias /bundles/emsch_assets /opt/src/public/bundles/$ENVIRONMENT_ALIAS -EOL - fi - - if ! [ -z ${ALIAS+x} ]; then - echo "Configure Apache Alias (/opt/src/public) [ ${ALIAS} ] ..." - echo "Caution do not add an alias that exists somewhere in a ems route (i.e. admin)" - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Alias $ALIAS /opt/src/public - Alias $ALIAS/bundles/emsch_assets /opt/src/public/bundles/${ENVIRONMENT_ALIAS:-emsch_assets} - - RewriteCond %{REQUEST_URI} !^$ALIAS/index.php - RewriteCond %{REQUEST_URI} !^$ALIAS/bundles - RewriteCond %{REQUEST_URI} !^$ALIAS/favicon.ico\$ - RewriteCond %{REQUEST_URI} !^$ALIAS/apple-touch-icon.png\$ - RewriteCond %{REQUEST_URI} !^$ALIAS/robots.txt\$ - RewriteRule "^$ALIAS" "$ALIAS/index.php\$1" [PT] - -EOL - fi - -} -function create-apache-vhost { - local -r _name=$1 - - echo "Configure Apache Virtual Host for [ $_name ] Skeleton Domains [ ${SERVER_NAME} ] ..." - - if [ -f /etc/apache2/conf.d/${_name}-app.conf ] ; then - rm /etc/apache2/conf.d/${_name}-app.conf - fi - - cat > /etc/apache2/conf.d/${_name}-app.conf < - ServerName $SERVER_NAME -EOL - - if ! [ -z ${SERVER_ALIASES+x} ]; then - echo "Configure Apache ServerAlias [ ${SERVER_ALIASES} ] ..." - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - ServerAlias $SERVER_ALIASES -EOL - fi - - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - LimitRequestLine 16384 - - # Uncomment the following line to force Apache to pass the Authorization - # header to PHP: required for "basic_auth" under PHP-FPM and FastCGI - # - # SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=\$1 - - # For Apache 2.4.9 or higher - # Using SetHandler avoids issues with using ProxyPassMatch in combination - # with mod_rewrite or mod_autoindex - - SetHandler "proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost/" - - - DocumentRoot /opt/src/public - - AllowOverride None - Require all granted - FallbackResource /index.php - - - - FallbackResource disabled - - - ErrorLog /dev/stderr - CustomLog /dev/stdout common - - - Header set Cache-Control "${APACHE_CACHE_CONTROL:-"max-age=86400, public"}" - - Header setifempty X-Frame-Options "${APACHE_X_FRAME_OPTIONS:-"SAMEORIGIN"}" - Header setifempty X-XSS-Protection "${APACHE_X_XSS_PROTECTION:-"1"}" - Header setifempty X-Content-Type-Options "${APACHE_X_CONTENT_TYPE_OPTIONS:-"nosniff"}" -EOL - - if ! [ -z ${APACHE_STRICT_TRANSPORT_SECURITY+x} ]; then - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Header setifempty Strict-Transport-Security "${APACHE_STRICT_TRANSPORT_SECURITY}" -EOL - fi; - - if ! [ -z ${APACHE_CONTENT_SECURITY_POLICY+x} ]; then - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Header setifempty Content-Security-Policy "${APACHE_CONTENT_SECURITY_POLICY}" -EOL - fi; - - if ! [ -z ${APACHE_REFERRER_POLICY+x} ]; then - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Header setifempty Referrer-Policy "${APACHE_REFERRER_POLICY}" -EOL - fi; - - if ! [ -z ${APACHE_PERMISSIONS_POLICY+x} ]; then - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Header setifempty Permissions-Policy "${APACHE_PERMISSIONS_POLICY}" -EOL - fi; - - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - RewriteEngine On - RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] - -EOL - - # APACHE_ACCESS_CONTROL_ALLOW_ORIGIN is not unset AND APACHE_ACCESS_CONTROL_ALLOW_ORIGIN.length > 0 - if [ ! -z ${APACHE_ACCESS_CONTROL_ALLOW_ORIGIN+x} ] && [ -n "${APACHE_ACCESS_CONTROL_ALLOW_ORIGIN}" ]; then - export APACHE_ACCESS_CONTROL_ALLOW_METHODS=${APACHE_ACCESS_CONTROL_ALLOW_METHODS:-"GET"} - export APACHE_ACCESS_CONTROL_ALLOW_HEADERS=${APACHE_ACCESS_CONTROL_ALLOW_HEADERS:-"application/json"} - - echo "Configure Apache CORS Headers ..." - echo " -> Access-Control-Allow-Origin ${APACHE_ACCESS_CONTROL_ALLOW_ORIGIN}" - echo " -> Access-Control-Allow-Methods ${APACHE_ACCESS_CONTROL_ALLOW_METHODS}" - echo " -> Access-Control-Allow-Headers ${APACHE_ACCESS_CONTROL_ALLOW_HEADERS}" - - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - Header set Access-Control-Allow-Origin "${APACHE_ACCESS_CONTROL_ALLOW_ORIGIN}" - Header set Access-Control-Allow-Methods "${APACHE_ACCESS_CONTROL_ALLOW_METHODS}" - Header set Access-Control-Allow-Headers "${APACHE_ACCESS_CONTROL_ALLOW_HEADERS}" - -EOL - fi - - if [ -z ${APACHE_ENVIRONMENTS+x} ]; then - #APACHE_ENVIRONMENTS is not set, apply old code for backward compatibility - setup-only-one-alias - else - setup-multi-alias - fi - - if ! [ -z ${PROTECTED_URL+x} ]; then - echo "Configure Apache Location (PROTECTED_URL) [ ${PROTECTED_URL} ] ..." - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - - AuthType Basic - AuthName "protected area" - # (La ligne suivante est facultative) - AuthBasicProvider file - AuthUserFile /opt/src/.htpasswd - Require valid-user - - -EOL - - if ! [ -w /opt/src/.htpasswd ]; then - HTPASSWD_USERNAME=${HTPASSWD_USERNAME:-default} - HTPASSWD_PASSWORD=${HTPASSWD_PASSWORD:-password} - htpasswd -bc /opt/src/.htpasswd ${HTPASSWD_USERNAME} ${HTPASSWD_PASSWORD} - if [ $? -ne 0 ]; then - echo "Something was wrong when we create .htpasswd file !" - fi - else - echo "htpasswd file already exist. We use it to protect '${PROTECTED_URL}'" - fi - fi - - echo "Configure Apache Environment Variables ..." - cat /tmp/$_name | sed '/^\s*$/d' | grep -v '^#' | sed "s/\([a-zA-Z0-9_]*\)\=\(.*\)/ SetEnv \1 \2/g" >> /etc/apache2/conf.d/${_name}-app.conf - - if ! [ -z ${BASE_URL+x} ]; then - echo "Configure Apache Proxy Load Balancer for Elasticsearch Cluster [ ${EMSCH_ELASTICSEARCH_CLUSTER} ] ..." - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - - ProxyRequests On - - -EOL - echo $EMSCH_ELASTICSEARCH_CLUSTER | sed "s/,/\n/g" | sed "s/[\s\[\"]*\([^\"]*\)\".*/ BalancerMember \1/" >> /etc/apache2/conf.d/${_name}-app.conf - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - #ProxySet lbmethod=byrequests - - -EOL - - echo $ELASTICSEARCH_CLUSTER | sed "s/,/\n/g" | sed "s/[\s\[\"]*\([^\"]*\)\".*/\1/" | grep ".*https.*" && echo " SSLProxyEngine On" >> /etc/apache2/conf.d/${_name}-app.conf - - echo "Configure Apache Location for [ ${BASE_URL} ] ..." - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - - ProxyPass "balancer://myset/" - ProxyPassReverse "balancer://myset/" - AllowMethods GET - - -EOL - fi; - - cat >> /etc/apache2/conf.d/${_name}-app.conf << EOL - -EOL - - echo "Apache Virtual Host for [ $_name ] Skeleton Domains [ ${SERVER_NAME} ] configured successfully ..." - -} - -# fork a subprocess -function configure ( - local -r _name=$1 - - source /tmp/${_name} - - create-apache-vhost "${_name}" - create-wrapper-script "${_name}" - - echo "Running Elasticms assets installation to /opt/src/public folder for [ $_name ] Skeleton Domain ..." - /opt/bin/$_name asset:install /opt/src/public --symlink --no-interaction - if [ $? -eq 0 ]; then - echo "Elasticms assets installation for [ $_name ] Skeleton Domain run successfully ..." - else - echo "Warning: something doesn't work with Elasticms assets installation !" - fi - - echo "Running Elasticms cache warming up for [ $_name ] Skeleton Domain ..." - /opt/bin/$_name cache:warm --no-interaction - if [ $? -eq 0 ]; then - echo "Elasticms warming up for [ $_name ] Skeleton Domain run successfully ..." - else - echo "Warning: something doesn't work with Elasticms cache warming up !" - fi - - if [[ ! -z ${EMS_METRIC_ENABLED} ]] && [[ ${EMS_METRIC_ENABLED,,} = true ]]; then - echo "Clear Elasticms metrics for [ $_name ] Skeleton Domain ..." - /opt/bin/$_name ems:metric:collect --clear - if [ $? -eq 0 ]; then - echo "Clear Elasticms metrics for [ $_name ] Skeleton Domain run successfully ..." - else - echo "Warning: something doesn't work with Elasticms metrics clearing !" - fi - fi - - #if [ ! -z "${ENVIRONMENT_ALIAS}" ]; then - # echo "Found ENVIRONMENT_ALIAS environment variable." - # echo "Made simlink /opt/src/public/bundles/${ENVIRONMENT_ALIAS} to /opt/src/public/bundles/emsch_assets ..." - # ln -s /opt/src/public/bundles/${ENVIRONMENT_ALIAS} /opt/src/public/bundles/emsch_assets - #fi - -) - -function install { - - if [ ! -z "$AWS_S3_CONFIG_BUCKET_NAME" ]; then - echo "Found AWS_S3_CONFIG_BUCKET_NAME environment variable. Reading properties files ..." - - export AWS_S3_CONFIG_BUCKET_NAME=${AWS_S3_CONFIG_BUCKET_NAME#s3://} - - list=(`aws s3 ls ${AWS_S3_CONFIG_BUCKET_NAME%/}/ ${AWS_CLI_EXTRA_ARGS} | awk '{print $4}'`) - - for config in ${list[@]}; - do - - name=${config%.*} - - echo "Install [ $name ] Skeleton Domain from S3 Bucket [ $config ] file ..." - - aws s3 cp s3://${AWS_S3_CONFIG_BUCKET_NAME%/}/$config ${AWS_CLI_EXTRA_ARGS} - | envsubst > /tmp/$name - - configure "${name}" - - echo "Install [ $name ] Skeleton Domain from S3 Bucket [ $config ] file successfully ..." - - done - - elif [ "$(ls -A /opt/secrets)" ]; then - - echo "Found '/opt/secrets' folder with files. Reading properties files ..." - - for file in /opt/secrets/*; do - - filename=$(basename $file) - name=${filename%.*} - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/secrets/ [ $filename ] file ..." - - envsubst < $file > /tmp/$name - - configure "${name}" - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/secrets/ [ $filename ] file successfully ..." - - done - - elif [ "$(ls -A /opt/configs)" ]; then - - echo "Found '/opt/configs' folder with files. Reading properties files ..." - - for file in /opt/configs/*; do - - filename=$(basename $file) - name=${filename%.*} - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/configs/ [ $filename ] file ..." - - envsubst < $file > /tmp/$name - - configure "${name}" - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/configs/ [ $filename ] file successfully ..." - - done - - else - - echo "Install [ default ] Skeleton Domain from Environment variables ..." - - env | envsubst > /tmp/default - - configure "default" - - echo "Install [ default ] Skeleton Domain from Environment variables successfully ..." - - fi - -} - -if [ ! -z "$AWS_S3_ENDPOINT_URL" ]; then - echo "Found AWS_S3_ENDPOINT_URL environment variable. Add --endpoint-run argument to AWS CLI" - AWS_CLI_EXTRA_ARGS="--endpoint-url ${AWS_S3_ENDPOINT_URL}" -fi - -install diff --git a/bin/metrics-setup.sh b/bin/metrics-setup.sh deleted file mode 100644 index f05c6c3..0000000 --- a/bin/metrics-setup.sh +++ /dev/null @@ -1,170 +0,0 @@ -#!/bin/bash -function create-metrics-vhost { - local -r _name=$1 - local -r METRICS_VHOST_SERVER_NAME_DEFAULT=$(hostname -i) - - local METRICS_VHOST_SERVER_NAME=${METRICS_VHOST_SERVER_NAME_CUSTOM:-"${METRICS_VHOST_SERVER_NAME_DEFAULT}"} - - echo "Configure Metrics Apache Virtual Host for [ ${_name} ] ..." - - if [ -f /etc/apache2/conf.d/__metrics.conf ] ; then - echo " Metrics Apache Virtual Host already configured ... Skip." - return 0 - fi - - cat > /etc/apache2/conf.d/__metrics.conf < - ServerName ${METRICS_VHOST_SERVER_NAME} - ServerAlias * - LimitRequestLine 16384 - - # Uncomment the following line to force Apache to pass the Authorization - # header to PHP: required for "basic_auth" under PHP-FPM and FastCGI - # - # SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=\$1 - - # For Apache 2.4.9 or higher - # Using SetHandler avoids issues with using ProxyPassMatch in combination - # with mod_rewrite or mod_autoindex - - SetHandler "proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost/" - - - DocumentRoot /opt/src/public - - AllowOverride None - Require all granted - FallbackResource /index.php - - - - FallbackResource disabled - - - ErrorLog /dev/stderr - CustomLog /dev/stdout common - Header set Cache-Control "${APACHE_CACHE_CONTROL:-"max-age=86400, public"}" - RewriteEngine On - RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] - -EOL - - echo "Configure Apache Environment Variables ..." - cat /tmp/${_name} | sed '/^\s*$/d' | grep -v '^#' | sed "s/\([a-zA-Z0-9_]*\)\=\(.*\)/ SetEnv \1 \2/g" >> /etc/apache2/conf.d/__metrics.conf - - cat >> /etc/apache2/conf.d/__metrics.conf << EOL - -EOL - - echo "Apache Metrics Virtual Host for [ ${_name} ] configured successfully ..." - -} - -# fork a subprocess -function configure ( - local -r _name=$1 - - source /tmp/${_name} - - if [ -z ${EMS_METRIC_ENABLED} ] || [ "${EMS_METRIC_ENABLED}" != "true" ]; then - echo "No Prometheus Metrics is requiered for [ ${_name} ]. Skip ..." - else - echo "Configure Apache Prometheus Metrics Vhost for [ ${_name} ] ..." - create-metrics-vhost "${_name}" - fi - -) - -function install { - - if [ ! -z "$AWS_S3_CONFIG_BUCKET_NAME" ]; then - echo "Found AWS_S3_CONFIG_BUCKET_NAME environment variable. Reading properties files ..." - - export AWS_S3_CONFIG_BUCKET_NAME=${AWS_S3_CONFIG_BUCKET_NAME#s3://} - - list=(`aws s3 ls ${AWS_S3_CONFIG_BUCKET_NAME%/}/ ${AWS_CLI_EXTRA_ARGS} | awk '{print $4}'`) - - for config in ${list[@]}; - do - - name=${config%.*} - - echo "Install [ $name ] Skeleton Domain from S3 Bucket [ $config ] file ..." - - aws s3 cp s3://${AWS_S3_CONFIG_BUCKET_NAME%/}/$config ${AWS_CLI_EXTRA_ARGS} - | envsubst > /tmp/$name - - configure "${name}" - - echo "Install [ $name ] Skeleton Domain from S3 Bucket [ $config ] file successfully ..." - - done - - elif [ "$(ls -A /opt/secrets)" ]; then - - echo "Found '/opt/secrets' folder with files. Reading properties files ..." - - for file in /opt/secrets/*; do - - filename=$(basename $file) - name=${filename%.*} - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/secrets/ [ $filename ] file ..." - - envsubst < $file > /tmp/$name - - configure "${name}" - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/secrets/ [ $filename ] file successfully ..." - - done - - elif [ "$(ls -A /opt/configs)" ]; then - - echo "Found '/opt/configs' folder with files. Reading properties files ..." - - for file in /opt/configs/*; do - - filename=$(basename $file) - name=${filename%.*} - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/configs/ [ $filename ] file ..." - - envsubst < $file > /tmp/$name - - configure "${name}" - - echo "Install [ $name ] Skeleton Domain from FS Folder /opt/configs/ [ $filename ] file successfully ..." - - done - - else - - echo "Install [ default ] Skeleton Domain from Environment variables ..." - - env | envsubst > /tmp/default - - configure "default" - - echo "Install [ default ] Skeleton Domain from Environment variables successfully ..." - - fi - -} - -if [ -z ${METRICS_ENABLED} ] || [ "${METRICS_ENABLED}" != "true" ]; then - - echo "Disable Prometheus Metrics ..." - -else - - echo "Configure Prometheus Metrics ..." - - if [ ! -z "$AWS_S3_ENDPOINT_URL" ]; then - echo "Found AWS_S3_ENDPOINT_URL environment variable. Add --endpoint-run argument to AWS CLI" - AWS_CLI_EXTRA_ARGS="--endpoint-url ${AWS_S3_ENDPOINT_URL}" - fi - - install - -fi - diff --git a/bin/varnish-setup.sh b/bin/varnish-setup.sh deleted file mode 100644 index 1877412..0000000 --- a/bin/varnish-setup.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/bin/bash - -function generate-emsch-vcl { - local -r VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD_DEFAULT="HEAD" - local -r VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI_DEFAULT="/index.php?varnish" - local -r VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION_DEFAULT="HTTP/1.1" - local -r VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST_DEFAULT="default.localhost" - local -r VARNISH_VCL_BACKEND_PROBE_TIMEOUT_DEFAULT="1s" - local -r VARNISH_VCL_BACKEND_PROBE_INTERVAL_DEFAULT="5s" - local -r VARNISH_VCL_BACKEND_PROBE_WINDOW_DEFAULT="5" - local -r VARNISH_VCL_BACKEND_PROBE_THRESHOLD_DEFAULT="3" - - local -r VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME_DEFAULT="X-Forwarded-Proto" - - local -r VARNISH_VCL_BACKEND_RESPONSE_TTL_DEFAULT="10s" - local -r VARNISH_VCL_BACKEND_RESPONSE_GRACE_DEFAULT="24h" - - local VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST=${VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_TIMEOUT=${VARNISH_VCL_BACKEND_PROBE_TIMEOUT_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_TIMEOUT_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_INTERVAL=${VARNISH_VCL_BACKEND_PROBE_INTERVAL_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_INTERVAL_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_WINDOW=${VARNISH_VCL_BACKEND_PROBE_WINDOW_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_WINDOW_DEFAULT}"} - local VARNISH_VCL_BACKEND_PROBE_THRESHOLD=${VARNISH_VCL_BACKEND_PROBE_THRESHOLD_CUSTOM:-"${VARNISH_VCL_BACKEND_PROBE_THRESHOLD_DEFAULT}"} - - local VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME=${VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME_CUSTOM:-"${VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME_DEFAULT}"} - - local VARNISH_VCL_BACKEND_RESPONSE_TTL=${VARNISH_VCL_BACKEND_RESPONSE_TTL_CUSTOM:-"${VARNISH_VCL_BACKEND_RESPONSE_TTL_DEFAULT}"} - local VARNISH_VCL_BACKEND_RESPONSE_GRACE=${VARNISH_VCL_BACKEND_RESPONSE_GRACE_CUSTOM:-"${VARNISH_VCL_BACKEND_RESPONSE_GRACE_DEFAULT}"} - - echo " Configure Varnish VCL ${VARNISH_VCL_CONF} file ..." - - # VCL config Based on: - # Based on: https://github.com/theus77/my_blog/blob/master/configs/varnish.vcl - - cat > ${VARNISH_VCL_CONF} << EOF -vcl 4.0; - -import std; - -backend default { - .host = "127.0.0.1"; - .port = "9000"; - .probe = { - .request = - "${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD} ${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI} ${VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION}" - "Host: ${VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST}" - "Connection: close" - "User-Agent: Varnish Health Probe"; - .timeout = ${VARNISH_VCL_BACKEND_PROBE_TIMEOUT}; - .interval = ${VARNISH_VCL_BACKEND_PROBE_INTERVAL}; - .window = ${VARNISH_VCL_BACKEND_PROBE_WINDOW}; - .threshold = ${VARNISH_VCL_BACKEND_PROBE_THRESHOLD}; - } -} - -sub vcl_recv { - - if (req.http.${VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME} == "https" ) { - set req.http.X-Forwarded-Port = "443"; - } else { - set req.http.X-Forwarded-Port = "80"; - } - - //activate the render_esi responses - set req.http.Surrogate-Capability = "ESI/1.0"; - - if (std.healthy(default)) { - // change the behavior for healthy backends: Cap grace to 10s - set req.grace = 10s; - } - - - // Remove all cookies except the session ID. - if (req.http.Cookie) { - set req.http.Cookie = ";" + req.http.Cookie; - set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";"); - set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1="); - set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); - set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); - - if (req.http.Cookie == "") { - // If there are no more cookies, remove the header to get page cached. - unset req.http.Cookie; - } - } - unset req.http.x-cache; -} - -sub vcl_backend_response { - set beresp.ttl = ${VARNISH_VCL_BACKEND_RESPONSE_TTL}; - set beresp.grace = ${VARNISH_VCL_BACKEND_RESPONSE_GRACE}; - - // Check for ESI acknowledgement and remove Surrogate-Control header - if (beresp.http.Surrogate-Control ~ "ESI/1.0") { - unset beresp.http.Surrogate-Control; - set beresp.do_esi = true; - } -} - -sub vcl_hit { - set req.http.x-cache = "hit"; -} - -sub vcl_miss { - set req.http.x-cache = "miss"; -} - -sub vcl_pass { - set req.http.x-cache = "pass"; -} - -sub vcl_pipe { - set req.http.x-cache = "pipe uncacheable"; -} - -sub vcl_synth { - set resp.http.x-cache = "synth synth"; -} - -sub vcl_deliver { - if (obj.uncacheable) { - set req.http.x-cache = req.http.x-cache + " uncacheable" ; - } else { - set req.http.x-cache = req.http.x-cache + " cached" ; - } - # (un)comment the following line to show the information in the response - set resp.http.x-cache = req.http.x-cache; - - #For monitoring - if (std.healthy(default)) { - set resp.http.x-healthy = "true"; - } - else { - set resp.http.x-healthy = "false"; - } -} -EOF - -} - -if [[ "${VARNISH_ENABLED}" == "true" ]]; then - - if [[ -f ${VARNISH_VCL_CONF} ]]; then - echo " Varnish VCL file ${VARNISH_VCL_CONF} exist. Using this VCL with Varnish ..." - else - echo " Varnish VCL file ${VARNISH_VCL_CONF} not exist. Generation of the VCL dynamically ..." - generate-emsch-vcl - fi - -fi diff --git a/config/apache2/conf.d/elasticms.conf.gtpl b/config/apache2/conf.d/elasticms.conf.gtpl new file mode 100644 index 0000000..925ec28 --- /dev/null +++ b/config/apache2/conf.d/elasticms.conf.gtpl @@ -0,0 +1,125 @@ +# This VirtualHost is autogenerated by the container startup script + + ServerName {{ .Env.SERVER_NAME }} + +{{- if ne .Env.SERVER_ALIASES "" }} + ServerAlias {{ .Env.SERVER_ALIASES }} +{{- end }} + + LimitRequestLine 16384 + + # Uncomment the following line to force Apache to pass the Authorization + # header to PHP: required for "basic_auth" under PHP-FPM and FastCGI + # + # SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=\$1 + + # For Apache 2.4.9 or higher + # Using SetHandler avoids issues with using ProxyPassMatch in combination + # with mod_rewrite or mod_autoindex + + SetHandler "proxy:unix:/app/var/run/php-fpm/php-fpm.sock|fcgi://localhost/" + + + DocumentRoot {{ .Env.APACHE_PUBLIC_DIR }} + + AllowOverride None + Require all granted + FallbackResource /index.php + + + # Bug in < 6.x ? + + FallbackResource disabled + + + + Header set Cache-Control "{{ .Env.APACHE_CACHE_CONTROL }}" + + + RewriteEngine On + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + Header setifempty X-Frame-Options "{{ .Env.APACHE_X_FRAME_OPTIONS }}" + Header setifempty X-XSS-Protection "{{ .Env.APACHE_X_XSS_PROTECTION }}" + Header setifempty X-Content-Type-Options "{{ .Env.APACHE_X_CONTENT_TYPE_OPTIONS }}" + +{{- if ne .Env.APACHE_STRICT_TRANSPORT_SECURITY "" }} + Header setifempty Strict-Transport-Security "{{ .Env.APACHE_STRICT_TRANSPORT_SECURITY }}" +{{- end }} + +{{- if ne .Env.APACHE_CONTENT_SECURITY_POLICY "" }} + Header setifempty Content-Security-Policy "{{ .Env.APACHE_CONTENT_SECURITY_POLICY }}" +{{- end }} + +{{- if ne .Env.APACHE_REFERRER_POLICY "" }} + Header setifempty Referrer-Policy "{{ .Env.APACHE_REFERRER_POLICY }}" +{{- end }} + +{{- if ne .Env.APACHE_PERMISSIONS_POLICY "" }} + Header setifempty Referrer-Policy "{{ .Env.APACHE_PERMISSIONS_POLICY }}" +{{- end }} + +{{- if ne .Env.APACHE_ACCESS_CONTROL_ALLOW_ORIGIN "" }} + Header set Access-Control-Allow-Origin "{{ .Env.APACHE_ACCESS_CONTROL_ALLOW_ORIGIN }}" + Header set Access-Control-Allow-Methods "{{ .Env.APACHE_ACCESS_CONTROL_ALLOW_METHODS }}" + Header set Access-Control-Allow-Headers "{{ .Env.APACHE_ACCESS_CONTROL_ALLOW_HEADERS }}" +{{ end }} + +{{- if ne .Env.APACHE_ENVIRONMENTS "" }} + + {{- $environments := env.Getenv "APACHE_ENVIRONMENTS" | jsonArray -}} + {{- range $env := $environments }} + + Alias {{ $env.alias }}/bundles/emsch_assets {{ .Env.APP_SRC_DIR }}/public/bundles/{{ $env.env }} + Alias {{ $env.alias }} {{ .Env.APP_SRC_DIR }}/public + + RewriteCond %{REQUEST_URI} !^{{ $env.alias }}/index.php + + {{- if ne .Env.APACHE_CUSTOM_ASSETS_RC "" }} + + RewriteCond %{REQUEST_URI} !^{{ .Env.APACHE_CUSTOM_ASSETS_RC }} + + {{ else }} + + RewriteCond %{REQUEST_URI} !^{{ $env.alias }}/bundles + + {{- end }} + + RewriteCond %{REQUEST_URI} !^{{ $env.alias }}/favicon.ico$ + RewriteCond %{REQUEST_URI} !^{{ $env.alias }}/apple-touch-icon.png$ + RewriteCond %{REQUEST_URI} !^{{ $env.alias }}/robots.txt$ + RewriteRule {{ $env.alias }} {{ $env.alias }}/index.php$1 [PT] + + {{- end }} + +{{ else }} + + {{- if ne .Env.ALIAS "" }} + + Alias {{ .Env.ALIAS }} {{ .Env.APACHE_PUBLIC_DIR }} + Alias {{ .Env.ALIAS }}/bundles/emsch_assets {{ .Env.APP_ASSETS_DIR }}/{{ .Env.APACHE_ENVIRONMENT_ALIAS }} + + RewriteCond %{REQUEST_URI} !^{{ .Env.ALIAS }}/index.php + RewriteCond %{REQUEST_URI} !^{{ .Env.ALIAS }}/bundles + RewriteCond %{REQUEST_URI} !^{{ .Env.ALIAS }}/favicon.ico$ + RewriteCond %{REQUEST_URI} !^{{ .Env.ALIAS }}/apple-touch-icon.png$ + RewriteCond %{REQUEST_URI} !^{{ .Env.ALIAS }}/robots.txt$ + RewriteRule ^{{ .Env.ALIAS }} {{ .Env.ALIAS }}/index.php$1 [PT] + + {{- end }} + +{{- end }} + +{{- if ne .Env.PROTECTED_URL "" }} + + AuthType Basic + AuthName "Protected Area" + AuthBasicProvider file + AuthUserFile {{ .Env.HTPASSWD_FILE }} + Require valid-user + +{{ end }} + + IncludeOptional /app/etc/apache2/conf.d/{{ .Env.ELASTICMS_INSTANCE_NAME }}-app.env + + \ No newline at end of file diff --git a/config/apache2/conf.d/metrics.conf.gtpl b/config/apache2/conf.d/metrics.conf.gtpl new file mode 100644 index 0000000..f9ffe21 --- /dev/null +++ b/config/apache2/conf.d/metrics.conf.gtpl @@ -0,0 +1,32 @@ +# This VirtualHost is autogenerated by the container startup script + +Listen {{ .Env.EMS_METRIC_PORT }} + + + ServerName {{ .Env.METRICS_VHOST_SERVER_NAME }} + ServerAlias * + LimitRequestLine 16384 + + + SetHandler "proxy:unix:/app/var/run/php-fpm/php-fpm.sock|fcgi://localhost/" + + + DocumentRoot {{ .Env.APACHE_PUBLIC_DIR }} + + AllowOverride None + Order Allow,Deny + Allow from All + Require all granted + FallbackResource /index.php + + + + FallbackResource disabled + + + RewriteEngine On + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + IncludeOptional /app/etc/apache2/conf.d/__metrics.env + + \ No newline at end of file diff --git a/config/php/conf.d/elasticms.ini.tmpl b/config/php/conf.d/elasticms.ini.tmpl new file mode 100644 index 0000000..cf382f9 --- /dev/null +++ b/config/php/conf.d/elasticms.ini.tmpl @@ -0,0 +1,2 @@ +post_max_size = {{ .Env.PHP_POST_MAX_SIZE }}M +upload_max_filesize = {{ .Env.PHP_UPLOAD_MAX_FILESIZE }}M diff --git a/config/sbin/instance.sh.gtpl b/config/sbin/instance.sh.gtpl new file mode 100644 index 0000000..4a90cd4 --- /dev/null +++ b/config/sbin/instance.sh.gtpl @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# This script is autogenerated by the container startup script +set -o allexport +source {{ .Env.APP_CONFIG_DIR }}/{{ .Env.ELASTICMS_INSTANCE_NAME }} +set +o allexport + +php {{ .Env.APP_SRC_DIR }}/bin/console "$@" diff --git a/config/varnish/default.vcl.gtpl b/config/varnish/default.vcl.gtpl new file mode 100644 index 0000000..98647a3 --- /dev/null +++ b/config/varnish/default.vcl.gtpl @@ -0,0 +1,101 @@ +vcl 4.0; + +import std; + +backend default { + .host = "127.0.0.1"; + .port = "9000"; + .probe = { + .request = + "{{ .Env.VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_METHOD }} {{ .Env.VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_URI }} {{ .Env.VARNISH_VCL_BACKEND_PROBE_REQUEST_HTTP_VERSION }}" + "Host: {{ .Env.VARNISH_VCL_BACKEND_PROBE_REQUEST_HOST }}" + "Connection: close" + "User-Agent: Varnish Health Probe"; + .timeout = {{ .Env.VARNISH_VCL_BACKEND_PROBE_TIMEOUT }}; + .interval = {{ .Env.VARNISH_VCL_BACKEND_PROBE_INTERVAL }}; + .window = {{ .Env.VARNISH_VCL_BACKEND_PROBE_WINDOW }}; + .threshold = {{ .Env.VARNISH_VCL_BACKEND_PROBE_THRESHOLD }}; + } +} + +sub vcl_recv { + + if (req.http.{{ .Env.VARNISH_VCL_RECV_REQUEST_X_FORWARDED_PROTO_HEADER_NAME }} == "https" ) { + set req.http.X-Forwarded-Port = "443"; + } else { + set req.http.X-Forwarded-Port = "80"; + } + + //activate the render_esi responses + set req.http.Surrogate-Capability = "ESI/1.0"; + + if (std.healthy(default)) { + // change the behavior for healthy backends: Cap grace to 10s + set req.grace = 10s; + } + + + // Remove all cookies except the session ID. + if (req.http.Cookie) { + set req.http.Cookie = ";" + req.http.Cookie; + set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";"); + set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1="); + set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); + set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); + + if (req.http.Cookie == "") { + // If there are no more cookies, remove the header to get page cached. + unset req.http.Cookie; + } + } + unset req.http.x-cache; +} + +sub vcl_backend_response { + set beresp.ttl = {{ .Env.VARNISH_VCL_BACKEND_RESPONSE_TTL }}; + set beresp.grace = {{ .Env.VARNISH_VCL_BACKEND_RESPONSE_GRACE }}; + + // Check for ESI acknowledgement and remove Surrogate-Control header + if (beresp.http.Surrogate-Control ~ "ESI/1.0") { + unset beresp.http.Surrogate-Control; + set beresp.do_esi = true; + } +} + +sub vcl_hit { + set req.http.x-cache = "hit"; +} + +sub vcl_miss { + set req.http.x-cache = "miss"; +} + +sub vcl_pass { + set req.http.x-cache = "pass"; +} + +sub vcl_pipe { + set req.http.x-cache = "pipe uncacheable"; +} + +sub vcl_synth { + set resp.http.x-cache = "synth synth"; +} + +sub vcl_deliver { + if (obj.uncacheable) { + set req.http.x-cache = req.http.x-cache + " uncacheable" ; + } else { + set req.http.x-cache = req.http.x-cache + " cached" ; + } + # (un)comment the following line to show the information in the response + set resp.http.x-cache = req.http.x-cache; + + #For monitoring + if (std.healthy(default)) { + set resp.http.x-healthy = "true"; + } + else { + set resp.http.x-healthy = "false"; + } +} \ No newline at end of file diff --git a/etc/php/conf.d/skeleton.ini b/etc/php/conf.d/skeleton.ini deleted file mode 100644 index a850a76..0000000 --- a/etc/php/conf.d/skeleton.ini +++ /dev/null @@ -1,2 +0,0 @@ -post_max_size = 128M -upload_max_filesize = 128M diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 463f855..6d7a932 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -105,7 +105,7 @@ services: mem_limit: 512m elasticms: - image: docker.io/elasticms/admin:5 + image: docker.io/elasticms/admin:6 networks: default: aliases: @@ -136,12 +136,18 @@ services: - METRICS_ENABLED=${BATS_METRICS_ENABLED} - CLI_PHP_MEMORY_LIMIT=512M volumes: - - ./demo/configs/admin:/opt/src/configs/admin - - ./demo/configs/document:/opt/src/configs/document - command: ["wait-for-it", "${BATS_DB_HOST}:${BATS_DB_PORT}", "--", "/usr/bin/supervisord", "-c", "/etc/supervisord/supervisord.conf"] + - app_admin_bin:/app/sbin + - app_admin_var:/app/var + - app_admin_etc:/app/etc + - app_admin_tmp:/app/tmp + - app_admin_ems_var:/app/src/elasticms/var + - ./demo/configs/admin:/app/src/elasticms/configs/admin + - ./demo/configs/document:/app/src/elasticms/configs/document + command: ["wait-for-it", "${BATS_DB_HOST}:${BATS_DB_PORT}", "--", "/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] mem_limit: 512m ports: - "8881:9000" + read_only: true emsch: image: ${BATS_DOCKER_IMAGE_NAME} @@ -176,14 +182,33 @@ services: - METRICS_ENABLED=${BATS_METRICS_ENABLED} - VARNISH_ENABLED=${BATS_VARNISH_ENABLED} volumes: - - ./demo/dist:/opt/src/public/skeleton:ro - - ./demo/skeleton:/opt/src/local/ems_promo_v2_preview - - ./demo/skeleton:/opt/src/local/ems_promo_v2_live - - ./demo/skeleton:/opt/src/local/skeleton + - ./demo/dist:/app/src/elasticms/public/skeleton:ro + - ./demo/skeleton:/app/src/elasticms/local/ems_promo_v2_preview + - ./demo/skeleton:/app/src/elasticms/local/ems_promo_v2_live + - ./demo/skeleton:/app/src/elasticms/local/skeleton +# - app_ems_bundles:/app/src/elasticms/public/bundles +# - app_ems_var:/app/src/elasticms/var mem_limit: 512m ports: - "8882:9000" +volumes: + app_admin_bin: + external: + name: ${BATS_APP_ADMIN_BIN_VOLUME_NAME} + app_admin_var: + external: + name: ${BATS_APP_ADMIN_VAR_VOLUME_NAME} + app_admin_ems_var: + external: + name: ${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME} + app_admin_etc: + external: + name: ${BATS_APP_ADMIN_ETC_VOLUME_NAME} + app_admin_tmp: + external: + name: ${BATS_APP_ADMIN_TMP_VOLUME_NAME} + networks: default: name: docker_default diff --git a/test/helpers/tests.bash b/test/helpers/tests.bash index 1aee1b1..356fa76 100644 --- a/test/helpers/tests.bash +++ b/test/helpers/tests.bash @@ -24,9 +24,7 @@ docker_cleanup() { # $2 HTTP path to query # $@ additional options to pass to the curl command function curl_container { - #local -r curl_image_name="docker.io/appropriate/curl:latest" - #local -r curl_image_name="docker.io/curlimages/curl:7.88.1" - local -r curl_image_name="docker.io/curlimages/curl:8.1.2" + local -r curl_image_name="docker.io/curlimages/curl:8.11.1" local -r container=$1 local -r path=$2 diff --git a/test/tests.bats b/test/tests.bats index faab096..1867940 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -60,6 +60,12 @@ export BATS_CONTAINER_ENGINE="${CONTAINER_ENGINE:-podman}" export BATS_CONTAINER_COMPOSE_ENGINE="${BATS_CONTAINER_ENGINE} compose" export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" +export BATS_APP_ADMIN_TMP_VOLUME_NAME=${BATS_APP_ADMIN_TMP_VOLUME_NAME:-ems_admin_tmp} +export BATS_APP_ADMIN_VAR_VOLUME_NAME=${BATS_APP_ADMIN_VAR_VOLUME_NAME:-ems_admin_var} +export BATS_APP_ADMIN_ETC_VOLUME_NAME=${BATS_APP_ADMIN_ETC_VOLUME_NAME:-ems_admin_etc} +export BATS_APP_ADMIN_BIN_VOLUME_NAME=${BATS_APP_ADMIN_BIN_VOLUME_NAME:-ems_admin_bin} +export BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME=${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME:-ems_admin_ems_var} + @test "[$TEST_FILE] Prepare Skeleton [$BATS_EMS_VERSION]." { run git clone -b ${BATS_EMS_VERSION} git@github.com:ems-project/elasticms-demo.git ${BATS_TEST_DIRNAME%/}/demo @@ -70,6 +76,14 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" } +@test "[$TEST_FILE] Create Docker external volumes (local)" { + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_TMP_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_VAR_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_ETC_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_BIN_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME} +} + @test "[$TEST_FILE] Starting Services (PostgreSQL, Elasticsearch, Redis, Minio, Tika)." { command ${BATS_CONTAINER_COMPOSE_ENGINE} -f ${BATS_TEST_DIRNAME%/}/docker-compose.yml up -d postgresql es01 es02 es03 redis tika minio @@ -117,7 +131,7 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" } -@test "[$TEST_FILE] Loading Elasticms Config files in Configuration S3 Bucket." { +@test "[$TEST_FILE] Loading ElasticMS Config files in Configuration S3 Bucket." { # TODO : update demo project to use more env vars in config file and use theses here (instead of manage own config files) for file in ${BATS_TEST_DIRNAME%/}/configs/elasticms/*.env ; do @@ -141,7 +155,7 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" done } -@test "[$TEST_FILE] Starting Elasticms." { +@test "[$TEST_FILE] Starting ElasticMS." { export BATS_EMS_ELASTICSEARCH_HOSTS="[\"http://$(container_ip es01):9200\",\"http://$(container_ip es02):9200\",\"http://$(container_ip es03):9200\"]" export BATS_S3_ENDPOINT_URL=http://$(container_ip minio):9000 export BATS_TIKA_LOCAL_ENDPOINT_URL=http://$(container_ip tika):9998 @@ -151,16 +165,7 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" } -@test "[$TEST_FILE] Check Elasticms startup messages in container logs." { - - for file in ${BATS_TEST_DIRNAME%/}/configs/elasticms/*.env ; do - _basename=$(basename $file) - _name=${_basename%.*} - container_wait_for_log ems 60 "Install \[ ${_name} \] CMS Domain from S3 Bucket \[ ${_basename} \] file successfully ..." - container_wait_for_log ems 60 "Doctrine database migration for \[ ${_name} \] CMS Domain run successfully ..." - container_wait_for_log ems 60 "Elasticms assets installation for \[ ${_name} \] CMS Domain run successfully ..." - container_wait_for_log ems 60 "Elasticms warming up for \[ ${_name} \] CMS Domain run successfully ..." - done +@test "[$TEST_FILE] Check ElasticMS startup messages in container logs." { container_wait_for_log ems 60 "NOTICE: ready to handle connections" container_wait_for_log ems 60 "AH00292: Apache/.* \(Unix\) OpenSSL/.* configured -- resuming normal operations" @@ -178,41 +183,35 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" } @test "[$TEST_FILE] Check Skeleton startup messages in containers logs." { - for file in ${BATS_TEST_DIRNAME%/}/configs/skeleton/*.env ; do - _basename=$(basename $file) - _name=${_basename%.*} - container_wait_for_log emsch 15 "Install \[ ${_name} \] Skeleton Domain from S3 Bucket \[ ${_basename} \] file successfully ..." - container_wait_for_log emsch 15 "Elasticms assets installation for \[ ${_name} \] Skeleton Domain run successfully ..." - container_wait_for_log emsch 15 "Elasticms warming up for \[ ${_name} \] Skeleton Domain run successfully ..." - done container_wait_for_log emsch 15 "NOTICE: ready to handle connections" container_wait_for_log emsch 15 "AH00292: Apache/.* \(Unix\) OpenSSL/.* configured -- resuming normal operations" + } -@test "[$TEST_FILE] Create Elasticms Super Admin user." { +@test "[$TEST_FILE] Create ElasticMS Super Admin user." { - run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/opt/bin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:create --super-admin --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ${BATS_ELASTICMS_ADMIN_EMAIL} ${BATS_ELASTICMS_ADMIN_PASSWORD}" + run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/app/sbin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:create --super-admin --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ${BATS_ELASTICMS_ADMIN_EMAIL} ${BATS_ELASTICMS_ADMIN_PASSWORD}" assert_output -r ".*\[OK\] Created user \"${BATS_ELASTICMS_ADMIN_USERNAME}\"" - run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/opt/bin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_API" + run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/app/sbin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_API" assert_output -r ".*\[OK\] Role \"ROLE_API\" has been added to user \"${BATS_ELASTICMS_ADMIN_USERNAME}\".*" - run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/opt/bin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_COPY_PASTE" + run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/app/sbin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_COPY_PASTE" assert_output -r ".*\[OK\] Role \"ROLE_COPY_PASTE\" has been added to user \"${BATS_ELASTICMS_ADMIN_USERNAME}\".*" - run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/opt/bin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_ALLOW_ALIGN" + run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/app/sbin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_ALLOW_ALIGN" assert_output -r ".*\[OK\] Role \"ROLE_ALLOW_ALIGN\" has been added to user \"${BATS_ELASTICMS_ADMIN_USERNAME}\".*" - run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/opt/bin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_FORM_CRM" + run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/app/sbin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_FORM_CRM" assert_output -r ".*\[OK\] Role \"ROLE_FORM_CRM\" has been added to user \"${BATS_ELASTICMS_ADMIN_USERNAME}\".*" - run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/opt/bin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_TASK_MANAGER" + run ${BATS_CONTAINER_ENGINE} exec ems sh -c "/app/sbin/${BATS_ELASTICMS_ADMIN_ENVIRONMENT} emsco:user:promote --no-debug ${BATS_ELASTICMS_ADMIN_USERNAME} ROLE_TASK_MANAGER" assert_output -r ".*\[OK\] Role \"ROLE_TASK_MANAGER\" has been added to user \"${BATS_ELASTICMS_ADMIN_USERNAME}\".*" } -@test "[$TEST_FILE] Login to Elasticms for admin." { +@test "[$TEST_FILE] Login to ElasticMS for admin." { run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:login --no-debug ${BATS_ELASTICMS_SKELETON_BACKEND_URL} --username=${BATS_ELASTICMS_ADMIN_USERNAME} --password=${BATS_ELASTICMS_ADMIN_PASSWORD} assert_output -r ".*\[OK\] Welcome ${BATS_ELASTICMS_ADMIN_USERNAME} on ${BATS_ELASTICMS_SKELETON_BACKEND_URL}" @@ -221,17 +220,17 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" @test "[$TEST_FILE] Restore elasticms configuration" { - run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:restore --no-debug --configs --configs-folder=/opt/src/configs/admin --force + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:restore --no-debug --configs --configs-folder=/app/src/elasticms/configs/admin --force } -@test "[$TEST_FILE] Activate Elasticms content types." { +@test "[$TEST_FILE] Activate ElasticMS content types." { run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:contenttype:activate --all --force } -@test "[$TEST_FILE] Rebuild Elasticms Environments." { +@test "[$TEST_FILE] Rebuild ElasticMS Environments." { envs=(`docker exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:environment:list --no-debug`) @@ -244,11 +243,11 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" @test "[$TEST_FILE] Restore elasticms documents" { - run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:restore --no-debug --documents --documents-folder=/opt/src/configs/document --force + run ${BATS_CONTAINER_ENGINE} exec ems ${BATS_ELASTICMS_ADMIN_ENVIRONMENT} ems:admin:restore --no-debug --documents --documents-folder=/app/src/elasticms/configs/document --force } -@test "[$TEST_FILE] Login to Elasticms for web." { +@test "[$TEST_FILE] Login to ElasticMS for web." { run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:login ${BATS_ELASTICMS_ADMIN_USERNAME} ${BATS_ELASTICMS_ADMIN_PASSWORD} assert_output -r ".*\[OK\] Welcome ${BATS_ELASTICMS_ADMIN_USERNAME} on ${BATS_ELASTICMS_SKELETON_BACKEND_URL}" @@ -257,7 +256,7 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" @test "[$TEST_FILE] Upload web assets." { - run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:upload --filename=/opt/src/local/skeleton/template/asset_hash.twig + run ${BATS_CONTAINER_ENGINE} exec emsch ${BATS_ELASTICMS_SKELETON_ENVIRONMENT} emsch:local:upload --filename=/app/src/elasticms/local/skeleton/template/asset_hash.twig assert_output -r ".*\[OK\] Assets .* have been uploaded" } @@ -282,14 +281,14 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" } -@test "[$TEST_FILE] Check for Elasticms Default Index page response code 200" { +@test "[$TEST_FILE] Check for ElasticMS Default Index page response code 200" { retry 12 5 curl_container ems :9000/index.php -H "Host: default.localhost" -s -w %{http_code} -o /dev/null assert_output -l 0 $'200' } -@test "[$TEST_FILE] Check for Elasticms status page response code 200 for all configured domains" { +@test "[$TEST_FILE] Check for ElasticMS status page response code 200 for all configured domains" { for file in ${BATS_TEST_DIRNAME%/}/configs/elasticms/*.env ; do @@ -357,4 +356,12 @@ export BATS_CONTAINER_NETWORK_NAME="${CONTAINER_NETWORK_NAME:-docker_default}" @test "[$TEST_FILE] Stop all and delete test containers" { command ${BATS_CONTAINER_COMPOSE_ENGINE} -f ${BATS_TEST_DIRNAME%/}/docker-compose.yml down -v +} + +@test "[$TEST_FILE] Cleanup Docker external volumes (local)" { + command docker volume rm ${BATS_APP_ADMIN_TMP_VOLUME_NAME} + command docker volume rm ${BATS_APP_ADMIN_VAR_VOLUME_NAME} + command docker volume rm ${BATS_APP_ADMIN_ETC_VOLUME_NAME} + command docker volume rm ${BATS_APP_ADMIN_BIN_VOLUME_NAME} + command docker volume rm ${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME} } \ No newline at end of file From f7e5b22521fa165d46ca7ea4b97a4c41be5d8db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastian=20Molle?= Date: Mon, 3 Feb 2025 13:15:07 +0100 Subject: [PATCH 3/5] volume mount in privileged mode --- Dockerfiles/Builder.m4 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfiles/Builder.m4 b/Dockerfiles/Builder.m4 index af8a5c3..afbbefb 100644 --- a/Dockerfiles/Builder.m4 +++ b/Dockerfiles/Builder.m4 @@ -5,4 +5,5 @@ RUN set -x ; \ mkdir -p /app/src/elasticms ; \ curl -sSfLk ${ELASTICMS_DOWNLOAD_URL}/${ELASTICMS_VERSION}.tar.gz \ | tar -xzC /app/src/elasticms --strip-components=1 ; \ - COMPOSER_MEMORY_LIMIT=-1 composer -vvv install --no-interaction --no-suggest --no-scripts --working-dir /app/src/elasticms -o ; \ No newline at end of file + COMPOSER_MEMORY_LIMIT=-1 composer -vvv install --no-interaction --no-suggest --no-scripts --working-dir /app/src/elasticms -o ; \ + mkdir -p /app/src/elasticms/public/bundles /app/src/elasticms/var ; \ No newline at end of file From b7ff5635e119e1a1e4f30c12aea125bd5b943ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastian=20Molle?= Date: Mon, 3 Feb 2025 13:15:20 +0100 Subject: [PATCH 4/5] Running container in readonly --- test/docker-compose.yml | 27 +++++++++++++++++++++++++-- test/tests.bats | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 6d7a932..5b1d084 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -182,17 +182,40 @@ services: - METRICS_ENABLED=${BATS_METRICS_ENABLED} - VARNISH_ENABLED=${BATS_VARNISH_ENABLED} volumes: + - app_web_bin:/app/sbin + - app_web_var:/app/var + - app_web_etc:/app/etc + - app_web_tmp:/app/tmp + - app_web_ems_var:/app/src/elasticms/var + - app_web_ems_bundles:/app/src/elasticms/public/bundles - ./demo/dist:/app/src/elasticms/public/skeleton:ro - ./demo/skeleton:/app/src/elasticms/local/ems_promo_v2_preview - ./demo/skeleton:/app/src/elasticms/local/ems_promo_v2_live - ./demo/skeleton:/app/src/elasticms/local/skeleton -# - app_ems_bundles:/app/src/elasticms/public/bundles -# - app_ems_var:/app/src/elasticms/var mem_limit: 512m ports: - "8882:9000" + read_only: true volumes: + app_web_bin: + external: + name: ${BATS_APP_WEB_BIN_VOLUME_NAME} + app_web_var: + external: + name: ${BATS_APP_WEB_VAR_VOLUME_NAME} + app_web_ems_var: + external: + name: ${BATS_APP_WEB_EMS_VAR_VOLUME_NAME} + app_web_ems_bundles: + external: + name: ${BATS_APP_WEB_EMS_BUNDLES_VOLUME_NAME} + app_web_etc: + external: + name: ${BATS_APP_WEB_ETC_VOLUME_NAME} + app_web_tmp: + external: + name: ${BATS_APP_WEB_TMP_VOLUME_NAME} app_admin_bin: external: name: ${BATS_APP_ADMIN_BIN_VOLUME_NAME} diff --git a/test/tests.bats b/test/tests.bats index 1867940..e042547 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -66,6 +66,14 @@ export BATS_APP_ADMIN_ETC_VOLUME_NAME=${BATS_APP_ADMIN_ETC_VOLUME_NAME:-ems_admi export BATS_APP_ADMIN_BIN_VOLUME_NAME=${BATS_APP_ADMIN_BIN_VOLUME_NAME:-ems_admin_bin} export BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME=${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME:-ems_admin_ems_var} +export BATS_APP_WEB_TMP_VOLUME_NAME=${BATS_APP_WEB_TMP_VOLUME_NAME:-ems_web_tmp} +export BATS_APP_WEB_VAR_VOLUME_NAME=${BATS_APP_WEB_VAR_VOLUME_NAME:-ems_web_var} +export BATS_APP_WEB_ETC_VOLUME_NAME=${BATS_APP_WEB_ETC_VOLUME_NAME:-ems_web_etc} +export BATS_APP_WEB_BIN_VOLUME_NAME=${BATS_APP_WEB_BIN_VOLUME_NAME:-ems_web_bin} +export BATS_APP_WEB_EMS_VAR_VOLUME_NAME=${BATS_APP_WEB_EMS_VAR_VOLUME_NAME:-ems_web_ems_var} +export BATS_APP_WEB_EMS_BUNDLES_VOLUME_NAME=${BATS_APP_WEB_EMS_BUNDLES_VOLUME_NAME:-app_web_ems_bundles} + + @test "[$TEST_FILE] Prepare Skeleton [$BATS_EMS_VERSION]." { run git clone -b ${BATS_EMS_VERSION} git@github.com:ems-project/elasticms-demo.git ${BATS_TEST_DIRNAME%/}/demo @@ -77,11 +85,19 @@ export BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME=${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME:- } @test "[$TEST_FILE] Create Docker external volumes (local)" { + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_TMP_VOLUME_NAME} command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_VAR_VOLUME_NAME} command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_ETC_VOLUME_NAME} command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_BIN_VOLUME_NAME} command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_WEB_TMP_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_WEB_VAR_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_WEB_ETC_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_WEB_BIN_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_WEB_EMS_VAR_VOLUME_NAME} + command ${BATS_CONTAINER_ENGINE} volume create -d local ${BATS_APP_WEB_EMS_BUNDLES_VOLUME_NAME} + } @test "[$TEST_FILE] Starting Services (PostgreSQL, Elasticsearch, Redis, Minio, Tika)." { @@ -355,13 +371,23 @@ export BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME=${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME:- } @test "[$TEST_FILE] Stop all and delete test containers" { + command ${BATS_CONTAINER_COMPOSE_ENGINE} -f ${BATS_TEST_DIRNAME%/}/docker-compose.yml down -v + } @test "[$TEST_FILE] Cleanup Docker external volumes (local)" { + command docker volume rm ${BATS_APP_ADMIN_TMP_VOLUME_NAME} command docker volume rm ${BATS_APP_ADMIN_VAR_VOLUME_NAME} command docker volume rm ${BATS_APP_ADMIN_ETC_VOLUME_NAME} command docker volume rm ${BATS_APP_ADMIN_BIN_VOLUME_NAME} command docker volume rm ${BATS_APP_ADMIN_EMS_VAR_VOLUME_NAME} + command docker volume rm ${BATS_APP_WEB_EMS_BUNDLES_VOLUME_NAME} + command docker volume rm ${BATS_APP_WEB_TMP_VOLUME_NAME} + command docker volume rm ${BATS_APP_WEB_VAR_VOLUME_NAME} + command docker volume rm ${BATS_APP_WEB_ETC_VOLUME_NAME} + command docker volume rm ${BATS_APP_WEB_BIN_VOLUME_NAME} + command docker volume rm ${BATS_APP_WEB_EMS_VAR_VOLUME_NAME} + } \ No newline at end of file From 93e9983c789a73df83f91fd08cf2af5600c12f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastian=20Molle?= Date: Mon, 3 Feb 2025 13:39:06 +0100 Subject: [PATCH 5/5] Upgrade action --- .github/workflows/docker-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 88b7c13..e3760e1 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -156,7 +156,7 @@ jobs: docker image ls -a - name: Scan "${{ needs.init.outputs.docker-image-name }}:${{ needs.init.outputs.github-ci-sha-short }}-${{ matrix.image-variant }}" Docker image - uses: anchore/scan-action@v4 + uses: anchore/scan-action@v6 id: scan with: image: ${{ needs.init.outputs.docker-image-name }}:${{ needs.init.outputs.github-ci-sha-short }}-${{ matrix.image-variant }}