Skip to content

Commit

Permalink
feat: use run time variables in dist
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapalakshmi committed Sep 22, 2024
1 parent 5dae083 commit 6aae2e8
Show file tree
Hide file tree
Showing 9 changed files with 14,163 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apps/workflows-dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ CMD ["npm", "run", "dev", "--host"]

FROM nginx:stable-alpine as prod

WORKDIR /app

COPY --from=dev /app/dist /usr/share/nginx/html

COPY --from=dev /app/entrypoint.sh /app/entrypoint.sh

COPY example.nginx.conf /etc/nginx/conf.d/default.conf

RUN chmod a+x /app/entrypoint.sh;

EXPOSE 80

ENTRYPOINT [ "/app/entrypoint.sh" ]

CMD ["nginx", "-g", "daemon off;"]
35 changes: 35 additions & 0 deletions apps/workflows-dashboard/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh

if [[ -z "$VITE_DOMAIN" ]]
then
VITE_DOMAIN="localhost:3000"
fi

if [[ -z "$MODE" ]]
then
MODE="development"
fi

if [[ -z "$VITE_IMAGE_LOGO_URL" ]]
then
VITE_IMAGE_LOGO_URL=
fi


if [[ -z "$VITE_ENVIRONMENT_NAME" ]]
then
VITE_ENVIRONMENT_NAME=local
fi


cat << EOF > /usr/share/nginx/html/config.js
globalThis.env = {
VITE_API_URL: "http://$VITE_DOMAIN/api/v1/",
VITE_ENVIRONMENT_NAME: "$VITE_ENVIRONMENT_NAME",
MODE: "$MODE",
VITE_IMAGE_LOGO_URL: "$VITE_IMAGE_LOGO_URL",
}
EOF

# Handle CMD command
exec "$@"
3 changes: 3 additions & 0 deletions apps/workflows-dashboard/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare global {
export var env: {[key: string]: any};
}
1 change: 1 addition & 0 deletions apps/workflows-dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="icon" type="image/png" sizes="16x16" href="/public/favicon-16x16.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Workflow Dashboard</title>
<script type="text/javascript" src="/config.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
Loading

0 comments on commit 6aae2e8

Please sign in to comment.