Enable container environment variables for config.

Fixes #1
This commit is contained in:
Peter Morton 2023-10-18 17:51:49 -05:00
parent 101c202615
commit e7dd75bc2b
11 changed files with 70 additions and 13 deletions

View File

@ -1,2 +1,2 @@
VITE_EO_SERVICES_URL=http://localhost:3000 VITE_API_BASE_URL=http://localhost:3000
VITE_ROUTER_BASE=/ VITE_ROUTER_BASE=/

View File

@ -1,2 +1,2 @@
VITE_EO_SERVICES_URL=https://eo-services.mortons.site VITE_API_BASE_URL=VITE_API_BASE_URL
VITE_ROUTER_BASE=/eo-services VITE_ROUTER_BASE=VITE_ROUTER_BASE

37
40-envsub-on-vite.sh Normal file
View File

@ -0,0 +1,37 @@
#!/bin/sh
# @see https://stackoverflow.com/questions/18185305/storing-bash-output-into-a-variable-using-eval
set -e
ROOT_DIR=/app/eo-services
ME=$(basename $0)
entrypoint_log() {
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
echo "$@"
fi
}
auto_envsubst() {
# Replace env vars in JavaScript files
echo "Replacing env constants in JS"
keys="VITE_ROUTER_BASE
VITE_API_BASE_URL"
for file in $ROOT_DIR/assets/index*.js* ;
do
echo "Processing $file ...";
for key in $keys
do
value=$(eval echo \$$key)
echo "replace $key by $value"
sed -i 's#'"$key"'#'"$value"'#g' $file
done
done
}
auto_envsubst
exit 0

View File

@ -13,5 +13,10 @@ COPY --from=build-stage /app/dist /app/eo-services
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf.template /etc/nginx/templates/default.conf.template COPY default.conf.template /etc/nginx/templates/default.conf.template
COPY headers.js /etc/nginx/headers.js COPY headers.js /etc/nginx/headers.js
COPY ./40-envsub-on-vite.sh /docker-entrypoint.d
RUN chmod u+x /docker-entrypoint.d/40-envsub-on-vite.sh
EXPOSE 80 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

View File

@ -12,7 +12,7 @@ server {
location /mirror { location /mirror {
internal; internal;
proxy_pass ${AUTH_PROXY_PASS}; proxy_pass ${VITE_API_BASE_URL}/auth;
proxy_set_header X-Original-URI $request_uri; proxy_set_header X-Original-URI $request_uri;
} }

View File

@ -10,11 +10,16 @@ services:
image: registry.mortons.site/eo-services:latest image: registry.mortons.site/eo-services:latest
ports: ports:
- "3000:3000" - "3000:3000"
dns:
- "8.8.8.8"
eo-services-client: eo-services-client:
environment: environment:
TZ: America/Chicago TZ: America/Chicago
AUTH_PROXY_PASS: https://eo-services.mortons.site/api/auth VITE_API_BASE_URL: https://em28.verint.live/eo-services/api
VITE_ROUTER_BASE: /eo-services/
image: registry.mortons.site/eo-services-client:latest image: registry.mortons.site/eo-services-client:latest
ports: ports:
- "18080:80" - "18080:80"
dns:
- "8.8.8.8"

7
src/app.config.js Normal file
View File

@ -0,0 +1,7 @@
export const apiBaseUrl = import.meta.env.VITE_API_BASE_URL
export const routerBase = import.meta.env.VITE_ROUTER_BASE
export default {
apiBaseUrl,
routerBase,
}

View File

@ -1,3 +1,5 @@
import { apiBaseUrl } from '../app.config.js';
export function getAuthKeyFromProperties(props) { export function getAuthKeyFromProperties(props) {
var authKey; var authKey;
@ -27,9 +29,7 @@ export function getTenantProperty(key, props) {
var authKey = getAuthKeyFromProperties(props); var authKey = getAuthKeyFromProperties(props);
console.log(`Fetching TPS Property [${key}]`); console.log(`Fetching TPS Property [${key}]`);
fetch( fetch(
`${ `${apiBaseUrl}/tps?propertyName=${key}&authKey=${authKey}`,
import.meta.env.VITE_EO_SERVICES_URL
}/api/tps?propertyName=${key}&authKey=${authKey}`,
{ {
credentials: "include", // fetch won't send cookies unless you set credentials credentials: "include", // fetch won't send cookies unless you set credentials
} }

View File

@ -1,4 +1,5 @@
import { createRouter, createWebHistory } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
import { routerBase } from '../app.config.js';
import HomeView from "../views/HomeView.vue"; import HomeView from "../views/HomeView.vue";
import AboutView from "../views/AboutView.vue"; import AboutView from "../views/AboutView.vue";
import DebugFrameView from "../views/DebugFrameView.vue"; import DebugFrameView from "../views/DebugFrameView.vue";
@ -62,9 +63,11 @@ const routes = [
}, },
]; ];
console.log(`mounting router on ${routerBase}`)
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
base: `${import.meta.env.VITE_ROUTER_BASE}`, base: routerBase,
routes, routes,
}); });

View File

@ -1,4 +1,5 @@
<script setup> <script setup>
import { apiBaseUrl } from '../app.config.js';
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { getAuthKeyFromProperties } from "../helpers/index"; import { getAuthKeyFromProperties } from "../helpers/index";
@ -43,7 +44,7 @@ function fetchData() {
return; return;
} }
fetch( fetch(
`${import.meta.env.VITE_EO_SERVICES_URL}/api/interactions-flow?filter=${ `${apiBaseUrl}/interactions-flow?filter=${
multiSelected.value multiSelected.value
}&authKey=${authKey}`, }&authKey=${authKey}`,
{ {

View File

@ -1,4 +1,5 @@
<script setup> <script setup>
import { apiBaseUrl } from '../app.config.js';
import { ref } from "vue"; import { ref } from "vue";
import { getAuthKeyFromProperties } from "../helpers/index"; import { getAuthKeyFromProperties } from "../helpers/index";
@ -28,9 +29,7 @@ function fetchData() {
if (authKey) { if (authKey) {
fetch( fetch(
`${ `${apiBaseUrl}/unified-data-gateway?referenceId=${
import.meta.env.VITE_EO_SERVICES_URL
}/api/unified-data-gateway?referenceId=${
referenceId.value referenceId.value
}&authKey=${authKey}`, }&authKey=${authKey}`,
{ {