-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Matthias Mohr <[email protected]>
- Loading branch information
1 parent
f074ae1
commit bf87b3f
Showing
2 changed files
with
103 additions
and
6 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,21 +1,27 @@ | ||
FROM node:lts-alpine3.18 AS build-step | ||
|
||
ARG catalogURL | ||
ARG DYNAMIC_CONFIG=true | ||
|
||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
RUN npm run build -- --catalogUrl=$catalogURL | ||
RUN \[ "${DYNAMIC_CONFIG}" == "true" \] && sed -i 's/<!-- <script defer="defer" src=".\/config.js"><\/script> -->/<script defer="defer" src=".\/config.js"><\/script>/g' public/index.html | ||
RUN npm run build | ||
|
||
|
||
FROM nginx:1-alpine-slim | ||
|
||
FROM nginx:1-alpine | ||
COPY --from=build-step /app/dist /usr/share/nginx/html | ||
COPY ./config.schema.json /etc/nginx/conf.d/config.schema.json | ||
|
||
# change default port to 8080 | ||
RUN sed -i 's/\s*listen\s*80;/ listen 8080;/' /etc/nginx/conf.d/default.conf | ||
RUN apk add jq pcre-tools && \ | ||
sed -i 's/\s*listen\s*80;/ listen 8080;/' /etc/nginx/conf.d/default.conf && \ | ||
sed -i 's/\s*location \/ {/ location \/ {\n try_files $uri $uri\/ \/index.html;/' /etc/nginx/conf.d/default.conf | ||
|
||
EXPOSE 8080 | ||
|
||
STOPSIGNAL SIGTERM | ||
|
||
CMD ["nginx", "-g", "daemon off;"] | ||
# override entrypoint, which calls nginx-entrypoint underneath | ||
ADD docker/docker-entrypoint.sh /docker-entrypoint.d/40-stac-browser-entrypoint.sh |
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,91 @@ | ||
# echo a string, handling different types | ||
safe_echo() { | ||
local value="$1" | ||
if [ -z "$value" ]; then | ||
echo -n "null" | ||
elif printf '%s\n' "$value" | grep -qE '\n.+\n$'; then | ||
echo -n "\`$value\`" | ||
else | ||
echo -n "'$value'" | ||
fi | ||
} | ||
|
||
# handle boolean | ||
bool() { | ||
case "$1" in | ||
true | TRUE | yes | t | True) | ||
echo -n true ;; | ||
false | FALSE | no | n | False) | ||
echo -n false ;; | ||
*) | ||
echo "Err: Unknown boolean value \"$1\"" >&2 | ||
exit 1 ;; | ||
esac | ||
} | ||
|
||
# handle array values | ||
array() { | ||
local value="$1" | ||
local arraytype="$2" | ||
if [ -z "$value" ]; then | ||
echo -n "[]" | ||
else | ||
case "$arraytype" in | ||
string) | ||
echo -n "['$(echo "$value" | sed "s/,/', '/g")']" | ||
;; | ||
*) | ||
echo -n "[$value]" | ||
;; | ||
esac | ||
fi | ||
} | ||
|
||
# handle object values | ||
object() { | ||
local value="$1" | ||
if [ -z "$value" ]; then | ||
echo -n "null" | ||
else | ||
echo -n "$value" | ||
fi | ||
} | ||
|
||
config_schema=$(cat /etc/nginx/conf.d/config.schema.json) | ||
|
||
# Iterate over environment variables with "SB_" prefix | ||
env -0 | cut -f1 -d= | tr '\0' '\n' | grep "^SB_" | { | ||
echo "window.STAC_BROWSER_CONFIG = {" | ||
while IFS='=' read -r name; do | ||
# Strip the prefix | ||
argname="${name#SB_}" | ||
# Read the variable's value | ||
value="$(eval "echo \"\$$name\"")" | ||
|
||
# Get the argument type from the schema | ||
argtype="$(echo "$config_schema" | jq -r ".properties.$argname.type[0]")" | ||
arraytype="$(echo "$config_schema" | jq -r ".properties.$argname.items.type[0]")" | ||
|
||
# Encode key/value | ||
echo -n " $argname: " | ||
case "$argtype" in | ||
string) | ||
safe_echo "$value" | ||
;; | ||
boolean) | ||
bool "$value" | ||
;; | ||
integer | number) | ||
object "$value" | ||
;; | ||
array) | ||
array "$value" "$arraytype" | ||
;; | ||
*) | ||
safe_echo "$value" | ||
;; | ||
esac | ||
echo "," | ||
done | ||
echo "}" | ||
} > /usr/share/nginx/html/config.js |