-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Move to Docker multistage builds (#450)
- Loading branch information
Showing
4 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
FROM node:20 | ||
FROM node:20-alpine AS build | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
ENV NB_API_QUERY_URL="REPLACE_ME_NB_API_QUERY_URL_REPLACE_ME" | ||
ENV NB_ENABLE_AUTH="REPLACE_ME_NB_ENABLE_AUTH_REPLACE_ME" | ||
Check warning on line 8 in Dockerfile
|
||
ENV NB_QUERY_CLIENT_ID="REPLACE_ME_NB_QUERY_CLIENT_ID_REPLACE_ME" | ||
ENV NB_ENABLE_CHATBOT="REPLACE_ME_NB_ENABLE_CHATBOT_REPLACE_ME" | ||
ENV NB_QUERY_APP_BASE_PATH="REPLACE_ME_NB_QUERY_APP_BASE_PATH_REPLACE_ME" | ||
|
||
RUN npm ci | ||
|
||
EXPOSE 5173 | ||
RUN npm run build | ||
|
||
|
||
FROM nginx:alpine | ||
|
||
COPY --from=build /app/dist /usr/share/nginx/html | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
WORKDIR /usr/share/nginx/html | ||
|
||
EXPOSE 80 | ||
|
||
ENTRYPOINT [ "/entrypoint.sh" ] | ||
|
||
ENTRYPOINT npm run build && npm run preview | ||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/sh | ||
|
||
# This script is used to replace environment variables in the JS files | ||
# with the values provided in the environment variables. If no value is | ||
# provided, the default value is used. | ||
# | ||
# To add a new environment variable, add a new sed command to replace | ||
# the placeholder in the JS files with the value of the environment | ||
# variable and define a default value | ||
|
||
# Check that the required environment variables are set | ||
if [ -z "$NB_API_QUERY_URL" ]; then | ||
echo "NB_API_QUERY_URL is not set. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Find all .js and .html files and loop through them | ||
for file in $(find /usr/share/nginx/html -type f \( -name "*.js" -o -name "*.html" \)); do | ||
sed -i "s|REPLACE_ME_NB_API_QUERY_URL_REPLACE_ME|${NB_API_QUERY_URL}|g" "$file" | ||
sed -i "s|REPLACE_ME_NB_ENABLE_AUTH_REPLACE_ME|${NB_ENABLE_AUTH:-false}|g" "$file" | ||
sed -i "s|REPLACE_ME_NB_QUERY_CLIENT_ID_REPLACE_ME|${NB_QUERY_CLIENT_ID:-testclient1234}|g" "$file" | ||
sed -i "s|REPLACE_ME_NB_ENABLE_CHATBOT_REPLACE_ME|${NB_ENABLE_CHATBOT:-false}|g" "$file" | ||
sed -i "s|REPLACE_ME_NB_QUERY_APP_BASE_PATH_REPLACE_ME|${NB_QUERY_APP_BASE_PATH:-/}|g" "$file" | ||
sed -i "s|<!-- REPLACE_ME_NB_QUERY_HEADER_SCRIPT_REPLACE_ME -->|${NB_QUERY_HEADER_SCRIPT}|g" "$file" | ||
done | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters