Skip to content

Commit 10289a6

Browse files
committed
Inject API base URL at runtime via VALIDATION_SERVICE_BASE_URL env var
- globals.js reads baseUrl from window.__env?.baseUrl (set by env-config.js) - index.html loads /env-config.js before the app bundle - vite.config.js serves /env-config.js from VALIDATION_SERVICE_BASE_URL in dev - docker-entrypoint.sh writes env-config.js at container start - Dockerfile.staging: add entrypoint, make html dir writable, remove globals-staging.js copy - Delete globals-staging.js (no longer needed)
1 parent c0086cd commit 10289a6

6 files changed

Lines changed: 29 additions & 68 deletions

File tree

apps/deployment/Dockerfile.staging

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ COPY model_catalog/package-lock.json ./
1313
RUN npm ci --legacy-peer-deps
1414

1515
COPY model_catalog ./
16-
COPY model_catalog/src/globals-staging.js ./src/globals.js
1716
RUN node --max-old-space-size=4096 `which npm` run build
1817

1918
WORKDIR /curation-dashboard
@@ -28,16 +27,21 @@ RUN npm run build
2827
# production environment
2928
FROM docker-registry.ebrains.eu/model-catalog/nginx:stable-alpine
3029

31-
# Make nginx dirs writable for non-root user (UID 1001)
32-
RUN chown -R 1001:0 /var/cache/nginx /var/log/nginx /etc/nginx/conf.d && \
33-
chmod -R g+w /var/cache/nginx /var/log/nginx /etc/nginx/conf.d && \
34-
sed -i 's/^user nginx;/#user nginx;/' /etc/nginx/nginx.conf && \
30+
RUN sed -i 's/^user nginx;/#user nginx;/' /etc/nginx/nginx.conf && \
3531
sed -i 's|/var/run/nginx.pid|/tmp/nginx.pid|' /etc/nginx/nginx.conf
3632

3733
COPY deployment/nginx-app-staging.conf /etc/nginx/conf.d/default.conf
3834
COPY --from=build /model-catalog/dist /usr/share/nginx/html/model-catalog
3935
COPY --from=build /curation-dashboard/dist /usr/share/nginx/html/curation-dashboard
4036

37+
# Make nginx dirs writable for non-root user (UID 1001) — must come after COPY to preserve ownership
38+
RUN chown -R 1001:0 /var/cache/nginx /var/log/nginx /etc/nginx/conf.d /usr/share/nginx/html && \
39+
chmod -R g+w /var/cache/nginx /var/log/nginx /etc/nginx/conf.d /usr/share/nginx/html
40+
41+
COPY deployment/docker-entrypoint.sh /docker-entrypoint.sh
42+
RUN chmod +x /docker-entrypoint.sh
43+
4144
EXPOSE 8080
4245
USER 1001
46+
ENTRYPOINT ["/docker-entrypoint.sh"]
4347
CMD ["nginx", "-g", "daemon off;"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
cat > /usr/share/nginx/html/model-catalog/env-config.js <<EOF
5+
window.__env = { baseUrl: "${VALIDATION_SERVICE_BASE_URL:-https://model-validation-api.apps.ebrains.eu}" };
6+
EOF
7+
8+
exec "$@"

apps/model_catalog/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<body>
4848
<noscript>You need to enable JavaScript to run this app.</noscript>
4949
<div id="root"></div>
50+
<script src="/env-config.js"></script>
5051
<script type="module" src="/src/index.jsx"></script>
5152
</body>
5253
</html>

apps/model_catalog/src/globals-staging.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

apps/model_catalog/src/globals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// NOTE: dummy data (in 'dev_data' directory) for DevMode is from v1 APIs; needs to be updated for v2 usage
22
export const DevMode = false; // TODO: change to false for production
3-
export const baseUrl = "https://model-validation-api.apps.ebrains.eu";
3+
export const baseUrl = window.__env?.baseUrl ?? "https://model-validation-api.apps.ebrains.eu";
44
export const querySizeLimit = 1000000;
55
export const collaboratoryOrigin = "https://wiki.ebrains.eu";
66
export const hashChangedTopic = "/clb/community-app/hashchange";

apps/model_catalog/vite.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ export default defineConfig({
1111
react(),
1212
nodePolyfills(),
1313
commonjs(),
14+
{
15+
name: 'dev-env-config',
16+
configureServer(server) {
17+
server.middlewares.use('/env-config.js', (req, res) => {
18+
res.setHeader('Content-Type', 'application/javascript');
19+
const baseUrl = process.env.VALIDATION_SERVICE_BASE_URL || "https://model-validation-api.apps.dev-adacloud.ebrains.eu";
20+
res.end(`window.__env = { baseUrl: "${baseUrl}" };`);
21+
});
22+
},
23+
},
1424
{
1525
name: 'dev-cors-proxy',
1626
configureServer(server) {

0 commit comments

Comments
 (0)