Skip to content

Commit e362640

Browse files
authored
Merge pull request #92 from tawoe/prestart
Prestart
2 parents 0f7c12d + 13ec4b1 commit e362640

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

Dockerfiles/frontend_build.env

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
VITE_OBP_API_HOST=VITE_OBP_API_HOST
22
VITE_OBP_API_PORTAL_HOST=VITE_OBP_API_PORTAL_HOST
33
VITE_OBP_API_MANAGER_HOST=VITE_OBP_API_MANAGER_HOST
4-
VITE_OBP_API_VERSION=v5.1.0
5-
4+
VITE_OBP_LOGO_URL=VITE_OBP_LOGO_URL
5+
VITE_OBP_API_VERSION=VITE_OBP_API_VERSION
6+
VITE_OBP_LINKS_COLOR=VITE_OBP_LINKS_COLOR
7+
VITE_OBP_HEADER_LINKS_COLOR=VITE_OBP_HEADER_LINKS_COLOR
8+
VITE_OBP_HEADER_LINKS_HOVER_COLOR=VITE_OBP_HEADER_LINKS_HOVER_COLOR
9+
VITE_OBP_HEADER_LINKS_BACKGROUND_COLOR=VITE_OBP_HEADER_LINKS_BACKGROUND_COLOR
10+
VITE_OBP_API_DEFAULT_RESOURCE_DOC_VERSION=VITE_OBP_API_DEFAULT_RESOURCE_DOC_VERSION
11+
VITE_CHATBOT_ENABLED=VITE_CHATBOT_ENABLED
12+
VITE_CHATBOT_URL=VITE_CHATBOT_URL

Dockerfiles/prestart.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,35 @@ import (
77
"path/filepath"
88
"regexp"
99
"strings"
10+
"fmt"
1011
)
1112

13+
// As the frontend environment is read at build time, we need to reprocess the values
14+
// at container runtime.
15+
// This app will search and replace the values set at build time from this build environment: Dockerfiles/frontend_build.env
16+
// with values taken from the container environment.
17+
1218
func main() {
13-
// Define the host env variables to be replaced at build time
14-
config := []string{"VITE_OBP_API_HOST", "VITE_OBP_API_MANAGER_HOST", "VITE_OBP_API_PORTAL_HOST"}
19+
// Define the build env variables to be replaced at container run time
20+
// url config variables are expected to be a valid URL in the container environment
21+
url_config := []string{"VITE_OBP_API_HOST", "VITE_OBP_API_MANAGER_HOST", "VITE_OBP_API_PORTAL_HOST", "VITE_OBP_LOGO_URL"}
22+
// DANGERZONE: The following strings will be replaced by container environment variables without any checking of whatever!!!
23+
config := []string{"VITE_OBP_API_VERSION", "VITE_OBP_LINKS_COLOR", "VITE_OBP_HEADER_LINKS_COLOR", "VITE_OBP_HEADER_LINKS_HOVER_COLOR", "VITE_OBP_HEADER_LINKS_BACKGROUND_COLOR", "VITE_OBP_API_DEFAULT_RESOURCE_DOC_VERSION", "VITE_CHATBOT_ENABLED", "VITE_CHATBOT_URL"}
1524
configMap := make(map[string]string)
1625

1726
for _, key := range config {
27+
value := os.Getenv(key)
28+
if value == "" {
29+
fmt.Printf("Skipping: Environment variable %s is not set\n", key)
30+
continue
31+
}
32+
configMap[key] = value
33+
}
34+
35+
for _, key := range url_config {
1836
rawURL := os.Getenv(key)
1937
if rawURL == "" {
38+
fmt.Printf("Skipping: Environment variable %s is not set\n", key)
2039
continue
2140
}
2241
cleanURL := checkURL(rawURL)

0 commit comments

Comments
 (0)