diff --git a/.conf/Dockerfile.full b/.conf/Dockerfile.full index c64a5540d..abf570fcb 100644 --- a/.conf/Dockerfile.full +++ b/.conf/Dockerfile.full @@ -29,7 +29,6 @@ FROM node:22-alpine as build-step ARG http_proxy=$http_proxy ARG https_proxy=$https_proxy ARG no_proxy=$no_proxy -RUN apk update && apk add --no-cache jq COPY . /app WORKDIR /app RUN yarn @@ -48,8 +47,6 @@ RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html # Add env variables inject script and mark as executable 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 # 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..b1b04e4f0 100644 --- a/.conf/Dockerfile.prebuilt +++ b/.conf/Dockerfile.prebuilt @@ -38,8 +38,6 @@ RUN ln -s /tmp/index.html /usr/share/nginx/html/index.html # Add env variables inject script and mark as executable 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 # 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 21e76bb30..d6bf70349 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 [#914](https://github.com/eclipse-tractusx/portal-frontend/pull/914) + ### Change - **Service Subscriptions** diff --git a/index.html b/index.html index ef42715e5..c0b7dec55 100644 --- a/index.html +++ b/index.html @@ -28,8 +28,26 @@
diff --git a/scripts/inject-dynamic-env.sh b/scripts/inject-dynamic-env.sh old mode 100644 new mode 100755 index dfa698eb2..cd33257b2 --- a/scripts/inject-dynamic-env.sh +++ b/scripts/inject-dynamic-env.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ############################################################### # Copyright (c) 2022 Contributors to the Eclipse Foundation @@ -19,13 +19,41 @@ # 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_REGISTRATION:"'$CLIENT_ID_REGISTRATION'",CLIENT_ID_SEMANTIC:"'$CLIENT_ID_SEMANTIC'",CLIENT_ID_BPDM:"'$CLIENT_ID_BPDM'",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_REGISTRATION:"Cl1-CX-Registration",CLIENT_ID_SEMANTIC:"Cl3-CX-Semantic",CLIENT_ID_BPDM:"Cl7-CX-BPDM",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 +source_file=/usr/share/nginx/html/index.html.reference +target_file=/tmp/index.html + +# these environment variables should be set and match the ones in index.html +# sequence is irrelevant +vars=" \ +REQUIRE_HTTPS_URL_PATTERN \ +CLEARINGHOUSE_CONNECT_DISABLED \ +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\"" + +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\"" + shift +done + +# execute the built replace command and write to target file +echo ${sed_command} | sh > ${target_file} diff --git a/src/services/EnvironmentService.ts b/src/services/EnvironmentService.ts index ef7debf74..af8b34c6b 100644 --- a/src/services/EnvironmentService.ts +++ b/src/services/EnvironmentService.ts @@ -19,10 +19,12 @@ declare const ENV: Record -// get the value of REQUIRE_HTTPS_URL_PATTERN environment variable, defaulting to 'true' if not set export const getRequireHttpsUrlPattern = () => ENV.REQUIRE_HTTPS_URL_PATTERN ?? 'true' +export const getClearinghouseConnectDisabled = () => + ENV.CLEARINGHOUSE_CONNECT_DISABLED ?? 'false' + export const getRealm = () => ENV.REALM ?? '' export const getClientId = () => ENV.CLIENT_ID ?? '' @@ -57,6 +59,7 @@ export const getSSICredentialBase = () => ENV.SSI_CREDENTIAL_URL ?? '' const EnvironmentService = { getRequireHttpsUrlPattern, + getClearinghouseConnectDisabled, getRealm, getClientId, getClientIdRegistration,