Skip to content

Commit

Permalink
cplp-1874: inject env specific config into index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
evegufy committed Jan 19, 2023
1 parent fbdac72 commit 1a990af
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .conf/Dockerfile.full
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ RUN yarn build
FROM nginxinc/nginx-unprivileged:alpine
COPY .conf/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-step /app/cx-portal/build /usr/share/nginx/html
# Change to root user for renaming of index.html to index.html.reference, to be used by env variables inject script
USER root
RUN mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.reference
# 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 bash
# Make nginx owner of /usr/share/nginx/html/ and change to nginx user
RUN chown -R 101:101 /usr/share/nginx/html/
USER 101
10 changes: 10 additions & 0 deletions .conf/Dockerfile.prebuilt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@
FROM nginxinc/nginx-unprivileged:alpine
COPY .conf/nginx.conf /etc/nginx/conf.d/default.conf
COPY cx-portal/build /usr/share/nginx/html
# Change to root user for renaming of index.html to index.html.reference, to be used by env variables inject script
USER root
RUN mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.reference
# 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 bash
# Make nginx owner of /usr/share/nginx/html/ and change to nginx user
RUN chown -R 101:101 /usr/share/nginx/html/
USER 101
4 changes: 4 additions & 0 deletions cx-portal/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
</head>
<body>
<div id="app"></div>
<!-- Do NOT change 'ENV' without changing 'custom_env_vars_anchor' in scripts/inject-dynamic-env.sh as well -->
<script>
const ENV = {PORTAL_FRONTEND_URL:"https://portal.dev.demo.catena-x.net",PORTAL_BACKEND_URL:"https://portal-backend.dev.demo.catena-x.net",CENTRALIDP_URL:"https://centralidp.dev.demo.catena-x.net/auth",BPDM_API_URL:"https://partners-pool.dev.demo.catena-x.net/api",SEMANTICS_URL:"https://semantics.dev.demo.catena-x.net"}
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions scripts/inject-dynamic-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation

# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.

# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# SPDX-License-Identifier: Apache-2.0

custom_env_vars='{PORTAL_FRONTEND_URL:"'$PORTAL_FRONTEND_URL'",PORTAL_BACKEND_URL:"'$PORTAL_BACKEND_URL'",CENTRALIDP_URL:"'$CENTRALIDP_URL'",BPDM_API_URL:"'$BPDM_API_URL'",SEMANTICS_URL:"'$SEMANTICS_URL'"}'
custom_env_vars_anchor='{PORTAL_FRONTEND_URL:"https://portal.dev.demo.catena-x.net",PORTAL_BACKEND_URL:"https://portal-backend.dev.demo.catena-x.net",CENTRALIDP_URL:"https://centralidp.dev.demo.catena-x.net/auth",BPDM_API_URL:"https://partners-pool.dev.demo.catena-x.net/api",SEMANTICS_URL:"https://semantics.dev.demo.catena-x.net"}'
index_html_reference=`cat /usr/share/nginx/html/index.html.reference`
index_html=${index_html_reference//$custom_env_vars_anchor/$custom_env_vars}
echo "$index_html" > /usr/share/nginx/html/index.html

0 comments on commit 1a990af

Please # to comment.