Skip to content

Commit

Permalink
Added: Config Loader
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Oct 18, 2024
1 parent c68841d commit 20bab42
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.github
.idea
.gitignore
dist
node_modules
6 changes: 0 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
STANDALONE_SINGLE_SPA=false
VUE_APP_KEYCLOAK_URL=https://login.verbis.dkfz.de/
VUE_APP_KEYCLOAK_REALM=test-realm-01
VUE_APP_KEYCLOAK_CLIENT_ID=bridgehead-test
VUE_APP_KEYCLOAK_REFRESH_TOKEN_TIME_IN_MINUTES=5
VUE_APP_PROJECT_MANAGER_BACKEND_URL=http://localhost:8097
VUE_APP_PUBLIC_PATH=/
6 changes: 0 additions & 6 deletions .env.standalone
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
STANDALONE_SINGLE_SPA=true
VUE_APP_KEYCLOAK_URL=https://login.verbis.dkfz.de/
VUE_APP_KEYCLOAK_REALM=test-realm-01
VUE_APP_KEYCLOAK_CLIENT_ID=bridgehead-test
VUE_APP_KEYCLOAK_REFRESH_TOKEN_TIME_IN_MINUTES=5
VUE_APP_PROJECT_MANAGER_BACKEND_URL=http://localhost:8097
VUE_APP_PUBLIC_PATH=/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Github CI
- VUE_APP_PUBLIC_PATH
- Nginx conf
- Config Loader
18 changes: 14 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@ RUN npm install

# Copy the rest of your application code
COPY . .
COPY docker/.env.template ./.env
COPY docker/.env.standalone.template ./.env.standalone

# Build the Vue application
RUN npm run build:standalone

# Stage 2: Serve the application with Nginx
FROM nginx:alpine

WORKDIR /usr/share/nginx/html

# Copy the built Vue application from the previous stage
COPY --from=build /app/dist /usr/share/nginx/html
COPY --from=build /app/dist .

# Copy custom Nginx configuration if needed
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf

# Expose port 80 for the Nginx server
EXPOSE 80

# Nginx will run automatically
CMD ["nginx", "-g", "daemon off;"]
ADD docker/start.sh /samply/
RUN chmod +x /samply/start.sh

COPY docker/keycloak.json .
COPY docker/config.json .


CMD ["/samply/start.sh"]
1 change: 1 addition & 0 deletions docker/.env.standalone.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STANDALONE_SINGLE_SPA=true
1 change: 1 addition & 0 deletions docker/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STANDALONE_SINGLE_SPA=false
3 changes: 3 additions & 0 deletions docker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"VUE_APP_PROJECT_MANAGER_BACKEND_URL" : "${VUE_APP_PROJECT_MANAGER_BACKEND_URL}"
}
8 changes: 8 additions & 0 deletions docker/keycloak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"realm": "${VUE_APP_KEYCLOAK_REALM}",
"auth-server-url": "${VUE_APP_KEYCLOAK_URL}",
"ssl-required": "external",
"resource": "${VUE_APP_KEYCLOAK_CLIENT_ID}",
"public-client": true,
"confidential-port": 0
}
File renamed without changes.
12 changes: 12 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

envsubst < /usr/share/nginx/html/keycloak.json > /usr/share/nginx/html/keycloak.temp.json
mv /usr/share/nginx/html/keycloak.temp.json /usr/share/nginx/html/keycloak.json

envsubst < /usr/share/nginx/html/config.json > /usr/share/nginx/html/config.temp.json
mv /usr/share/nginx/html/config.temp.json /usr/share/nginx/html/config.json

#envsubst '${TEILER_DASHBOARD_SERVER_NAME} ${TEILER_ORCHESTRATOR_URL}'< /etc/nginx/nginx.template.conf > /etc/nginx/nginx.conf

echo 'Start Teiler Dashboard in NGINX in foreground (non-daemon-mode)'
exec nginx -g 'daemon off;'
3 changes: 3 additions & 0 deletions public/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"VUE_APP_PROJECT_MANAGER_BACKEND_URL" : "http://localhost:8097"
}
11 changes: 0 additions & 11 deletions public/projects.json

This file was deleted.

30 changes: 30 additions & 0 deletions src/services/configLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// configLoader.ts
let config: any = null;
let isLoading = false; // Track whether the config is being loaded

const loadConfig = async () => {
if (!isLoading) {
isLoading = true; // Prevent multiple concurrent loads
try {
const response = await fetch('/config.json');
config = await response.json();
} catch (error) {
console.error('Failed to load config.json:', error);
throw new Error('Configuration loading failed');
} finally {
isLoading = false; // Reset loading state
}
}

// Wait until config is loaded
while (config === null) {
await new Promise(resolve => setTimeout(resolve, 100)); // Polling
}
};

export const getConfig = async () => {
if (config === null) {
await loadConfig(); // Load the config if it's not already loaded
}
return config;
};
2 changes: 1 addition & 1 deletion src/services/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const refreshToken = () => {
};

// Set up timer to refresh token periodically
const tokenRefreshInterval = setInterval(refreshToken, process.env.VUE_APP_KEYCLOAK_REFRESH_TOKEN_TIME_IN_MINUTES * 60 * 1000); // Refresh token every 5 minutes
const tokenRefreshInterval = setInterval(refreshToken, 5 * 60 * 1000); // Refresh token every 5 minutes

const KeyCloakService = {
getToken: () => keycloakInstance.token,
Expand Down
5 changes: 3 additions & 2 deletions src/services/projetManagerBackendService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// projetManagerBackendService.ts
//projectManagerBackendService.ts
import axios, {AxiosRequestConfig, AxiosResponse} from 'axios';
import axiosRetry from "axios-retry";
import KeyCloakService from "@/services/keycloak";
import {getConfig} from "@/services/configLoader";


const baseURL = process.env.VUE_APP_PROJECT_MANAGER_BACKEND_URL
const baseURL = (await getConfig()).VUE_APP_PROJECT_MANAGER_BACKEND_URL;

const bridgeheadParam = 'bridgehead'
const projectCodeParam = 'project-code'
Expand Down
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const dotenv = require('dotenv').config();

module.exports = {
publicPath: process.env.VUE_APP_PUBLIC_PATH || './', // Fallback to './' if not set
// publicPath: process.env.VUE_APP_PUBLIC_PATH || './', // Fallback to './' if not set
configureWebpack: {
output: {
libraryTarget: "system",
Expand Down

0 comments on commit 20bab42

Please sign in to comment.