feat: replace environment variables in config.json5 during docker image start
ADD
.dockerignore
+/cypress/
+/dist/
+/docu/
+/node_modules/
+
+/.angular/
+/.cache/
+/.idea/
+/.run/

MODIFY
.gitignore
.gitignore
@@ -47,3 +47,6 @@ Thumbs.db
# Cache
.cache
+
+# Local config
+src/assets/local-config.json5

RENAME
.prettierrc
.prettierrc.json
MODIFY
Dockerfile
Dockerfile
@@ -20,7 +20,10 @@ EXPOSE 80 443
# one of pas-service|pas-app|database|xuml-service|python-service|other
LABEL com.scheer-pas.container-type="pas-app"
+# copy files in the ngninx server folder
COPY --from=base /usr/src/app/dist/devportal /usr/share/nginx/html
+# copy config to different folder to run envsubst before starting
+COPY --from=base /usr/src/app/dist/devportal/assets/config.json5 /usr/share/devportal/assets/config.json5
#copy ssl keys
COPY docker/tls.crt /etc/ssl/certs/tls.crt

MODIFY
README.md
README.md
-# Dev Portal v2
+# Apiman Developer Portal
## Diagram of Components
![Diagram](./docu/component-diagram.svg)
+
+
+## Local Development
+
+* You have to create a copy of the `src/assets/config.json5` called `src/assets/local-config.json5`
+* Adapt the `endpoint` and `auth.url` to match you apiman and keycloak setup
+* Execute `npm run start`
+
+E.g
+
+```bash
+cp src/assets/config.json5 src/assets/local-config.json5
+npm run start
+```

MODIFY
docker/start-nginx-with-devportal.sh
docker/start-nginx-with-devportal.sh
#!/bin/sh
-# Check if a prefix exists
+#
+# Copyright 2022 Scheer PAS Schweiz AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://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
+# imitations under the License.
+#
+
+
+# check if a variable exists
if [ -n "$BASE_PATH" ]
then
- # If a prefix is set we will replace the base path in index.html before starting the application
- # Replace existing base tag with base tag containing system prefix src e.g. "/pas/devportal/"
+ # replace existing base tag with base tag containing system prefix src e.g. "/pas/devportal/"
sed -i "s|<base.*>|<base href=\"$BASE_PATH\">|g" "/usr/share/nginx/html/index.html"
fi
# replace all occurrences of placeholders with environment variables
-# see https://blog.codecentric.de/en/2019/03/docker-angular-dockerize-app-easily/
+envsubst < /usr/share/devportal/assets/config.json5 > /tmp/config.json5.tmp
+cp /tmp/config.json5.tmp /usr/share/nginx/html/assets/config.json5
-#for mainFileName in /usr/share/nginx/html/main*.js
-#do
-# envsubst "\$KEYCLOAK_REALM \$API_MGMT_UI_REST_URL \$KEYCLOAK_AUTH_URL \$LOGO_FILE_URL \$ABOUT_LOGO_FILE_URL \$FIRST_LINK \$FIRST_LINK_LABEL \$SECOND_LINK \$SECOND_LINK_LABEL" < "$mainFileName" > main.tmp
-# mv main.tmp "${mainFileName}"
-#done
-
-printf "Starting developer portal:\n"
# start nginx
+printf "Starting developer portal:\n"
nginx -g 'daemon off;'

MODIFY
src/app/services/config/config.service.ts
src/app/services/config/config.service.ts
@@ -26,6 +26,7 @@ import {
import { HttpClient } from '@angular/common/http';
import * as JSON5 from 'json5';
import { firstValueFrom } from 'rxjs';
+import { environment } from '../../../environments/environment';
@Injectable({
providedIn: 'root'
@@ -37,7 +38,7 @@ export class ConfigService {
async readAndEvaluateConfig(): Promise<IConfig> {
const configAsJson5String = await firstValueFrom(
- this.http.get('assets/config.json5', { responseType: 'text' })
+ this.http.get(environment.configFilePath, { responseType: 'text' })
);
try {

MODIFY
src/environments/environment.prod.ts
src/environments/environment.prod.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
export const environment = {
- production: true
+ production: true,
+ configFilePath: 'assets/config.json5'
};

MODIFY
src/environments/environment.ts
src/environments/environment.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// The list of file replacements can be found in `angular.json`.
export const environment = {
- production: false
+ production: false,
+ configFilePath: 'assets/local-config.json5'
};
/*

feat: replace environment variables in config.json5 during docker image start