Skip to content

Commit

Permalink
runtime env substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Jan 10, 2024
1 parent 424bfb4 commit 465ea64
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/frontend-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
touch .env
echo VITE_APP_API_URL=${{ secrets.VITE_APP_API_URL }} >> .env
echo VITE_APP_FULL_URL=${{ secrets.VITE_APP_FULL_URL }} >> .env
echo VITE_OAUTH2_REDIRECT_URL=${{ secrets.VITE_OAUTH2_REDIRECT_URL }} >> .env
echo VITE_APP_BASE=${{ secrets.VITE_APP_BASE }} >> .env
cp .env ../.env
- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
dist
5 changes: 5 additions & 0 deletions app/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY --from=build-stage .env .env
COPY --from=build-stage /app/nginx.conf /etc/nginx/nginx.conf

# Allow substitution of env vars at runtime
COPY frontend/docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 5003
18 changes: 13 additions & 5 deletions app/frontend/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#!/bin/bash
#!/bin/sh
ROOT_DIR=/app
# Replace env vars in files served by NGINX
for file in $ROOT_DIR/assets/*.js $ROOT_DIR/index.html;
do
echo "Processing $file ...";
# LC_ALL=C sed -i "" 's|VITE_APP_API_URL_PLACEHOLDER|'${VITE_APP_API_URL}'|g' $file
sed -i 's|VITE_APP_API_URL_PLACEHOLDER|'${VITE_APP_API_URL}'|g' $file
sed -i 's|VITE_APP_FULL_URL_PLACEHOLDER|'${VITE_APP_FULL_URL}'|g' $file
sed -i 's|VITE_APP_BASE_PLACEHOLDER|'${VITE_APP_BASE}'|g' $file
done

npm i @vue/cli-service
npm install
npm run build
npm run serve -- --port 5003
echo "Starting Nginx"
nginx -g 'daemon off;'
7 changes: 3 additions & 4 deletions app/frontend/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export const APP_NAME = import.meta.env.VITE_APP_NAME || "";
export const APP_URL = import.meta.env.VITE_APP_FULL_URL || "";
export const APP_BASE = import.meta.env.VITE_APP_BASE || "";
export const APP_URL = import.meta.env.VITE_APP_FULL_URL || "VITE_APP_FULL_URL_PLACEHOLDER";
export const APP_BASE = import.meta.env.VITE_APP_BASE || "VITE_APP_BASE_PLACEHOLDER";

export const API_BASE = import.meta.env.VITE_APP_API_URL || "";
export const API_BASE = import.meta.env.VITE_APP_API_URL || "VITE_APP_API_URL_PLACEHOLDER";
export const ENDPOINTS = {
openapi: `${API_BASE}/openapi.json`,
authCuahsiAuthorize: `${API_BASE}/auth/front/authorize`,
Expand Down

0 comments on commit 465ea64

Please sign in to comment.