Made cogen react ui to use runtime environment variables (#807)
Signed-off-by: jaswanth8888 <karani.jaswanth@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -4,21 +4,18 @@
|
||||
# Use node 20.11.1 as the base image
|
||||
FROM node:20.11.1 as vite-app
|
||||
|
||||
COPY . /usr/app
|
||||
COPY react /usr/app/react
|
||||
WORKDIR /usr/app/react
|
||||
|
||||
ARG BACKEND_SERVICE_ENDPOINT
|
||||
ENV VITE_CODE_GEN_URL=$BACKEND_SERVICE_ENDPOINT
|
||||
|
||||
RUN ["npm", "install"]
|
||||
RUN ["npm", "run", "build"]
|
||||
|
||||
|
||||
FROM nginx:alpine
|
||||
EXPOSE 80
|
||||
|
||||
|
||||
COPY --from=vite-app /usr/app/react/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=vite-app /usr/app/react/dist /usr/share/nginx/html
|
||||
COPY ./react/env.sh /docker-entrypoint.d/env.sh
|
||||
|
||||
ENTRYPOINT ["nginx", "-g", "daemon off;"]
|
||||
COPY ./react/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
RUN chmod +x /docker-entrypoint.d/env.sh
|
||||
1
CodeGen/ui/react/.env.production
Normal file
1
CodeGen/ui/react/.env.production
Normal file
@@ -0,0 +1 @@
|
||||
VITE_CODE_GEN_URL=APP_CODE_GEN_URL
|
||||
13
CodeGen/ui/react/env.sh
Normal file
13
CodeGen/ui/react/env.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2024 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
for i in $(env | grep APP_) #// Make sure to use the prefix APP_ if you have any other prefix in env.production file variable name replace it with APP_
|
||||
do
|
||||
key=$(echo $i | cut -d '=' -f 1)
|
||||
value=$(echo $i | cut -d '=' -f 2-)
|
||||
echo $key=$value
|
||||
|
||||
# sed JS and CSS only
|
||||
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' +
|
||||
done
|
||||
Reference in New Issue
Block a user