From ca08f7edc19b1dcd4bf0eb661a0e55a7664fa04f Mon Sep 17 00:00:00 2001 From: Martin Rohrmeier Date: Tue, 9 Jul 2024 15:01:21 +0200 Subject: [PATCH 1/8] improve(env): more readable and typo resistant env inject --- .conf/Dockerfile.full | 4 ++-- .conf/Dockerfile.prebuilt | 4 ++-- CHANGELOG.md | 5 ++++ index.html | 23 ++++++++++++++++--- scripts/inject-dynamic-env.sh | 43 ++++++++++++++++++++++++++--------- 5 files changed, 61 insertions(+), 18 deletions(-) diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full index c64a5540d..d9f60b53c 100644 --- a/.conf/Dockerfile.full +++ b/.conf/Dockerfile.full @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2022 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -49,7 +49,7 @@ RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html COPY ./scripts/inject-dynamic-env.sh /docker-entrypoint.d/00-inject-dynamic-env.sh RUN chmod +x /docker-entrypoint.d/00-inject-dynamic-env.sh # Install bash for env variables inject script -RUN apk update && apk add --no-cache bash +RUN apk update && apk add --no-cache bash sed # Make nginx owner of /usr/share/nginx/html/ and change to nginx user RUN chown -R 101:101 /usr/share/nginx/html/ # Change to nginx user diff --git a/.conf/Dockerfile.prebuilt b/.conf/Dockerfile.prebuilt index 916451381..49d3b7ee7 100644 --- a/.conf/Dockerfile.prebuilt +++ b/.conf/Dockerfile.prebuilt @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2022 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -39,7 +39,7 @@ RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html COPY ./scripts/inject-dynamic-env.sh /docker-entrypoint.d/00-inject-dynamic-env.sh RUN chmod +x /docker-entrypoint.d/00-inject-dynamic-env.sh # Install bash for env variables inject script -RUN apk update && apk add --no-cache bash +RUN apk update && apk add --no-cache bash sed # Make nginx owner of /usr/share/nginx/html/ and change to nginx user RUN chown -R 101:101 /usr/share/nginx/html/ # Change to nginx user diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f1c3282..f485942bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,11 @@ - harmonization and standardization of page headers, added consistent headers and removed unused code - Use scroll to top button from shared components +### Change + +- **Others** + - More readable and typo resistant implementation to inject env vars + ## 2.0.0 ### Change diff --git a/index.html b/index.html index 1a72c3909..40aa26596 100644 --- a/index.html +++ b/index.html @@ -28,9 +28,26 @@
- \ No newline at end of file + diff --git a/scripts/inject-dynamic-env.sh b/scripts/inject-dynamic-env.sh index 84de178ba..17d4622cd 100644 --- a/scripts/inject-dynamic-env.sh +++ b/scripts/inject-dynamic-env.sh @@ -1,7 +1,7 @@ #!/bin/bash ############################################################### -# Copyright (c) 2022 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -19,13 +19,34 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -# Define custom variable -custom_env_vars='{REQUIRE_HTTPS_URL_PATTERN:"'$REQUIRE_HTTPS_URL_PATTERN'",PORTAL_ASSETS_URL:"'$PORTAL_ASSETS_URL'",PORTAL_BACKEND_URL:"'$PORTAL_BACKEND_URL'",CENTRALIDP_URL:"'$CENTRALIDP_URL'",SSI_CREDENTIAL_URL:"'$SSI_CREDENTIAL_URL'",BPDM_POOL_API_URL:"'$BPDM_POOL_API_URL'",BPDM_GATE_API_URL:"'$BPDM_GATE_API_URL'",SEMANTICS_URL:"'$SEMANTICS_URL'",MANAGED_IDENTITY_WALLETS_NEW_URL:"'$MANAGED_IDENTITY_WALLETS_NEW_URL'",REALM:"'$REALM'",CLIENT_ID:"'$CLIENT_ID'",CLIENT_ID_SEMANTIC:"'$CLIENT_ID_SEMANTIC'",CLIENT_ID_MIW:"'$CLIENT_ID_MIW'",CLIENT_ID_SSI_CREDENTIAL:"'$CLIENT_ID_SSI_CREDENTIAL'"}' -# Define anchor variable -custom_env_vars_anchor='{REQUIRE_HTTPS_URL_PATTERN:"true",PORTAL_ASSETS_URL:"http://localhost:3000/assets",PORTAL_BACKEND_URL:"https://portal-backend.example.org",CENTRALIDP_URL:"https://centralidp.example.org/auth",SSI_CREDENTIAL_URL:"https://ssi-credential-issuer.example.org",BPDM_POOL_API_URL:"https://business-partners.example.org/pool/v6",BPDM_GATE_API_URL:"https://business-partners.example.org/companies/test-company/v6",SEMANTICS_URL:"https://semantics.example.org",MANAGED_IDENTITY_WALLETS_NEW_URL:"https://managed-identity-wallets-new.example.org",REALM:"CX-Central",CLIENT_ID:"Cl2-CX-Portal",CLIENT_ID_SEMANTIC:"Cl3-CX-Semantic",CLIENT_ID_MIW:"Cl5-CX-Custodian",CLIENT_ID_SSI_CREDENTIAL:"Cl24-CX-SSI-CredentialIssuer"}' -# Read content of the reference index.html file into the index_html_reference variable -index_html_reference=`cat /usr/share/nginx/html/index.html.reference` -# Replace the anchor variable with the custom variable in the index.html file -index_html=${index_html_reference//$custom_env_vars_anchor/$custom_env_vars} -# Write the modified index.html to tmp (to enable readOnlyRootFilesystem) -echo "$index_html" > /tmp/index.html +src_file=/usr/share/nginx/html/index.html.reference +tgt_file=/tmp/index.html +# base sed command: output source file and remove javascript comments +sed_cmd="cat ${src_file} | sed -e \"s/^\\\s*\/\/.*//g\"" + +declare -a vars=( + "REQUIRE_HTTPS_URL_PATTERN" + "CENTRALIDP_URL" + "PORTAL_ASSETS_URL" + "PORTAL_BACKEND_URL" + "SEMANTICS_URL" + "BPDM_GATE_API_URL" + "BPDM_POOL_API_URL" + "SSI_CREDENTIAL_URL" + "MANAGED_IDENTITY_WALLETS_NEW_URL" + "REALM" + "CLIENT_ID" + "CLIENT_ID_REGISTRATION" + "CLIENT_ID_SEMANTIC" + "CLIENT_ID_BPDM" + "CLIENT_ID_MIW" + "CLIENT_ID_SSI_CREDENTIAL" +) + +for var in "${vars[@]}" +do + # add a replace expression for each variable + sed_cmd="${sed_cmd} -e \"s/${var}:\s*\\\".*\\\"/${var}: \\\"\${${var}}\\\"/g\"" +done + +echo ${sed_cmd} | bash > ${tgt_file} From 4fb44c6621051d1e8de39551a30009701c6e43bc Mon Sep 17 00:00:00 2001 From: Martin Rohrmeier Date: Wed, 10 Jul 2024 08:11:29 +0200 Subject: [PATCH 2/8] fix(env): remove bash --- .conf/Dockerfile.full | 2 +- .conf/Dockerfile.prebuilt | 2 +- scripts/inject-dynamic-env.sh | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/inject-dynamic-env.sh diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full index d9f60b53c..24052e84d 100644 --- a/.conf/Dockerfile.full +++ b/.conf/Dockerfile.full @@ -49,7 +49,7 @@ RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html COPY ./scripts/inject-dynamic-env.sh /docker-entrypoint.d/00-inject-dynamic-env.sh RUN chmod +x /docker-entrypoint.d/00-inject-dynamic-env.sh # Install bash for env variables inject script -RUN apk update && apk add --no-cache bash sed +RUN apk update && apk add --no-cache sed # Make nginx owner of /usr/share/nginx/html/ and change to nginx user RUN chown -R 101:101 /usr/share/nginx/html/ # Change to nginx user diff --git a/.conf/Dockerfile.prebuilt b/.conf/Dockerfile.prebuilt index 49d3b7ee7..372d1fe13 100644 --- a/.conf/Dockerfile.prebuilt +++ b/.conf/Dockerfile.prebuilt @@ -39,7 +39,7 @@ RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html COPY ./scripts/inject-dynamic-env.sh /docker-entrypoint.d/00-inject-dynamic-env.sh RUN chmod +x /docker-entrypoint.d/00-inject-dynamic-env.sh # Install bash for env variables inject script -RUN apk update && apk add --no-cache bash sed +RUN apk update && apk add --no-cache sed # Make nginx owner of /usr/share/nginx/html/ and change to nginx user RUN chown -R 101:101 /usr/share/nginx/html/ # Change to nginx user diff --git a/scripts/inject-dynamic-env.sh b/scripts/inject-dynamic-env.sh old mode 100644 new mode 100755 index 17d4622cd..47cdc1d2e --- a/scripts/inject-dynamic-env.sh +++ b/scripts/inject-dynamic-env.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ############################################################### # Copyright (c) 2024 Contributors to the Eclipse Foundation @@ -19,8 +19,10 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -src_file=/usr/share/nginx/html/index.html.reference -tgt_file=/tmp/index.html +#src_file=/usr/share/nginx/html/index.html.reference +#tgt_file=/tmp/index.html +src_file=index.html +tgt_file=i.html # base sed command: output source file and remove javascript comments sed_cmd="cat ${src_file} | sed -e \"s/^\\\s*\/\/.*//g\"" @@ -49,4 +51,4 @@ do sed_cmd="${sed_cmd} -e \"s/${var}:\s*\\\".*\\\"/${var}: \\\"\${${var}}\\\"/g\"" done -echo ${sed_cmd} | bash > ${tgt_file} +echo ${sed_cmd} | sh > ${tgt_file} From cae346f0749d89dc3eb4000ffe7b00dc6e29ed00 Mon Sep 17 00:00:00 2001 From: Martin Rohrmeier Date: Wed, 10 Jul 2024 08:34:50 +0200 Subject: [PATCH 3/8] fix(env): use correct source and target files --- scripts/inject-dynamic-env.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/inject-dynamic-env.sh b/scripts/inject-dynamic-env.sh index 47cdc1d2e..5a3e01a6a 100755 --- a/scripts/inject-dynamic-env.sh +++ b/scripts/inject-dynamic-env.sh @@ -19,12 +19,10 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################### -#src_file=/usr/share/nginx/html/index.html.reference -#tgt_file=/tmp/index.html -src_file=index.html -tgt_file=i.html +source_file=/usr/share/nginx/html/index.html.reference +target_file=/tmp/index.html # base sed command: output source file and remove javascript comments -sed_cmd="cat ${src_file} | sed -e \"s/^\\\s*\/\/.*//g\"" +sed_command="cat ${source_file} | sed -e \"s/^\\\s*\/\/.*//g\"" declare -a vars=( "REQUIRE_HTTPS_URL_PATTERN" @@ -48,7 +46,7 @@ declare -a vars=( for var in "${vars[@]}" do # add a replace expression for each variable - sed_cmd="${sed_cmd} -e \"s/${var}:\s*\\\".*\\\"/${var}: \\\"\${${var}}\\\"/g\"" + sed_command="${sed_command} -e \"s/${var}:\s*\\\".*\\\"/${var}: \\\"\${${var}}\\\"/g\"" done -echo ${sed_cmd} | sh > ${tgt_file} +echo ${sed_command} | sh > ${target_file} From 80fe1c291048ef24cd6cc944a3493d63134421f2 Mon Sep 17 00:00:00 2001 From: Martin Rohrmeier Date: Wed, 10 Jul 2024 10:31:27 +0200 Subject: [PATCH 4/8] fix(env): convert script to ash syntax --- scripts/inject-dynamic-env.sh | 47 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/scripts/inject-dynamic-env.sh b/scripts/inject-dynamic-env.sh index 5a3e01a6a..80f21e279 100755 --- a/scripts/inject-dynamic-env.sh +++ b/scripts/inject-dynamic-env.sh @@ -21,32 +21,35 @@ source_file=/usr/share/nginx/html/index.html.reference target_file=/tmp/index.html + +vars=" \ +REQUIRE_HTTPS_URL_PATTERN \ +CENTRALIDP_URL \ +PORTAL_ASSETS_URL \ +PORTAL_BACKEND_URL \ +SEMANTICS_URL \ +BPDM_GATE_API_URL \ +BPDM_POOL_API_URL \ +SSI_CREDENTIAL_URL \ +MANAGED_IDENTITY_WALLETS_NEW_URL \ +REALM \ +CLIENT_ID \ +CLIENT_ID_REGISTRATION \ +CLIENT_ID_SEMANTIC \ +CLIENT_ID_BPDM \ +CLIENT_ID_MIW \ +CLIENT_ID_SSI_CREDENTIAL \ +" + # base sed command: output source file and remove javascript comments sed_command="cat ${source_file} | sed -e \"s/^\\\s*\/\/.*//g\"" -declare -a vars=( - "REQUIRE_HTTPS_URL_PATTERN" - "CENTRALIDP_URL" - "PORTAL_ASSETS_URL" - "PORTAL_BACKEND_URL" - "SEMANTICS_URL" - "BPDM_GATE_API_URL" - "BPDM_POOL_API_URL" - "SSI_CREDENTIAL_URL" - "MANAGED_IDENTITY_WALLETS_NEW_URL" - "REALM" - "CLIENT_ID" - "CLIENT_ID_REGISTRATION" - "CLIENT_ID_SEMANTIC" - "CLIENT_ID_BPDM" - "CLIENT_ID_MIW" - "CLIENT_ID_SSI_CREDENTIAL" -) - -for var in "${vars[@]}" -do +set -- $vars +while [ -n "$1" ]; do + var=$1 # add a replace expression for each variable sed_command="${sed_command} -e \"s/${var}:\s*\\\".*\\\"/${var}: \\\"\${${var}}\\\"/g\"" -done + shift +done echo ${sed_command} | sh > ${target_file} From 91d3cb8b5c3fb65f29b265b5bd7a96b3e0a47467 Mon Sep 17 00:00:00 2001 From: Evelyn Gurschler Date: Wed, 9 Oct 2024 10:36:51 +0200 Subject: [PATCH 5/8] chore: adjust changelog --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 479e025cb..e007bb048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Technical Support + +- **Injection of environment variables to Docker image** + - refactored to a more readable and typo resistant implementation using sh - bash and jq are no longer required in image + ## 2.3.0-alpha.2 ### Change @@ -268,11 +273,6 @@ - Onboarding Service Provider Management Board - The user interface for the Onboarding Service Provider management board is not yet developed. -### Change - -- **Others** - - More readable and typo resistant implementation to inject env vars - ## 2.0.0 ### Change From 1a5e54c11a8e7c8d7465b780ca4e4c761e210f0c Mon Sep 17 00:00:00 2001 From: Evelyn Gurschler Date: Wed, 9 Oct 2024 10:38:33 +0200 Subject: [PATCH 6/8] docs: improve changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e007bb048..785b270a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Technical Support - **Injection of environment variables to Docker image** - - refactored to a more readable and typo resistant implementation using sh - bash and jq are no longer required in image + - refactored to a more readable and typo resistant implementation using sh - bash and jq are no longer required in image [#914](https://github.com/eclipse-tractusx/portal-frontend/pull/914) ## 2.3.0-alpha.2 From f730ea69fc02fec24b3af54659b4a5e142d75fb0 Mon Sep 17 00:00:00 2001 From: Evelyn Gurschler Date: Thu, 10 Oct 2024 08:59:27 +0200 Subject: [PATCH 7/8] chore: revert change of file header --- .conf/Dockerfile.full | 2 +- .conf/Dockerfile.prebuilt | 2 +- scripts/inject-dynamic-env.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full index dcca90bb5..abf570fcb 100644 --- a/.conf/Dockerfile.full +++ b/.conf/Dockerfile.full @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2022 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. diff --git a/.conf/Dockerfile.prebuilt b/.conf/Dockerfile.prebuilt index 0fd9a5c11..b1b04e4f0 100644 --- a/.conf/Dockerfile.prebuilt +++ b/.conf/Dockerfile.prebuilt @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2022 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. diff --git a/scripts/inject-dynamic-env.sh b/scripts/inject-dynamic-env.sh index 46a9f4ae3..18e99dde5 100755 --- a/scripts/inject-dynamic-env.sh +++ b/scripts/inject-dynamic-env.sh @@ -1,7 +1,7 @@ #!/bin/sh ############################################################### -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2022 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. From c595c024d40163c7fb1c274f3e2d41aca82abff4 Mon Sep 17 00:00:00 2001 From: Martin Rohrmeier Date: Fri, 11 Oct 2024 07:35:05 +0200 Subject: [PATCH 8/8] fix(env): inject all exported env vars into index.html --- index.html | 3 ++- scripts/inject-dynamic-env.sh | 4 ++++ src/services/EnvironmentService.ts | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 3fc747a40..c0b7dec55 100644 --- a/index.html +++ b/index.html @@ -28,9 +28,10 @@