Skip to content

Commit

Permalink
feat: make complete domain configurable for multi-channel setup (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Mar 12, 2020
1 parent 6b113a7 commit c8d6eb5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
23 changes: 13 additions & 10 deletions nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In the latter case you will also have to supply the files `server.key` and `serv

Setup at least one PWA channel configuration:

- use mandatory `PWA_X_SUBDOMAIN` for the channel sub domain
- use mandatory `PWA_X_SUBDOMAIN`, `PWA_X_TOPLEVELDOMAIN` or `PWA_X_DOMAIN` for the channel domain
- use mandatory `PWA_X_CHANNEL` for the channel name
- use optional `PWA_X_APPLICATION` for the application name
- use optional `PWA_X_LANG` for the default locale in the form of `lang_COUNTRY`
Expand All @@ -46,19 +46,22 @@ docker run -d --name "my-awesome-nginx" \
--restart always \
-p 4199:80 \
-e UPSTREAM_PWA=http://192.168.0.10:4200 \
-e PWA_1_SUBDOMAIN=b2b \
-e PWA_1_CHANNEL=inSPIRED-inTRONICS_Business-Site \
-e PWA_1_FEATURES=quoting,recently,compare \
-e PWA_2_SUBDOMAIN=b2c \
-e PWA_1_TOPLEVELDOMAIN=net \
-e PWA_1_CHANNEL=inSPIRED-inTRONICS-Site \
-e PWA_1_LANG=en_US \
-e PWA_2_TOPLEVELDOMAIN=de \
-e PWA_2_CHANNEL=inSPIRED-inTRONICS-Site \
-e PWA_3_SUBDOMAIN=de \
-e PWA_3_CHANNEL=inSPIRED-inTRONICS-Site \
-e PWA_3_LANG=de_DE \
-e PWA_3_FEATURES=none \
-e PWA_4_SUBDOMAIN=smb \
-e PWA_2_LANG=de_DE \
-e PWA_3_TOPLEVELDOMAIN=com \
-e PWA_3_CHANNEL=inSPIRED-inTRONICS_Business-Site \
-e PWA_3_FEATURES=quoting,recently,compare,businessCustomerRegistration,advancedVariationHandling \
-e PWA_3_THEME="blue|688dc3" \
-e PWA_4_TOPLEVELDOMAIN=fr \
-e PWA_4_LANG=en_US \
-e PWA_4_CHANNEL=inSPIRED-inTRONICS-Site \
-e PWA_4_APPLICATION=smb-responsive \
-e PWA_4_FEATURES=quoting \
-e PWA_4_THEME="blue|688dc3" \
my_awesome_nginx
```

Expand Down
4 changes: 2 additions & 2 deletions nginx/channel.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
server_name ~^$SUBDOMAIN\..+$;
server_name ~^$DOMAIN$;
include /etc/nginx/conf.d/listen.conf;

# let ICM handle everything ICM related
Expand Down Expand Up @@ -42,7 +42,7 @@ server {
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;

add_header X-icm-subdomain $SUBDOMAIN always;
add_header X-icm-domain $DOMAIN always;
add_header X-icm-channel $CHANNEL always;
add_header X-icm-application $APPLICATION always;
add_header X-icm-features $FEATURES always;
Expand Down
23 changes: 20 additions & 3 deletions nginx/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,24 @@ i=1
while true
do
eval "export SUBDOMAIN=\$PWA_${i}_SUBDOMAIN"
[ -z "$SUBDOMAIN" ] && break
eval "export TOPLEVELDOMAIN=\$PWA_${i}_TOPLEVELDOMAIN"
eval "export DOMAIN=\$PWA_${i}_DOMAIN"

if [ ! -z "$DOMAIN" ]
then
[ ! -z "$SUBDOMAIN" ] && echo "ignoring PWA_${i}_SUBDOMAIN as PWA_${i}_DOMAIN is set"
[ ! -z "$TOPLEVELDOMAIN" ] && echo "ignoring PWA_${i}_TOPLEVELDOMAIN as PWA_${i}_DOMAIN is set"
else
if [ ! -z "$SUBDOMAIN" ]
then
[ ! -z "$TOPLEVELDOMAIN" ] && echo "ignoring PWA_${i}_TOPLEVELDOMAIN as PWA_${i}_SUBDOMAIN is set"
export DOMAIN="$SUBDOMAIN\..+"
else
[ ! -z "$TOPLEVELDOMAIN" ] && export DOMAIN=".+\.$TOPLEVELDOMAIN"
fi
fi

[ -z "$DOMAIN" ] && break

eval "export CHANNEL=\$PWA_${i}_CHANNEL"
[ -z "$CHANNEL" ] && echo "PWA_${i}_CHANNEL must be set" && exit 1
Expand All @@ -38,9 +55,9 @@ do
eval "export FEATURES=\${PWA_${i}_FEATURES:-'default'}"
eval "export THEME=\${PWA_${i}_THEME:-''}"

echo "$i SUBDOMAIN=$SUBDOMAIN CHANNEL=$CHANNEL APPLICATION=$APPLICATION LANG=$LANG FEATURES=$FEATURES"
echo "$i DOMAIN=$DOMAIN CHANNEL=$CHANNEL APPLICATION=$APPLICATION LANG=$LANG FEATURES=$FEATURES THEME=$THEME"

envsubst '$UPSTREAM_PWA,$SUBDOMAIN,$CHANNEL,$APPLICATION,$LANG,$FEATURES,$THEME' </etc/nginx/conf.d/channel.conf.tmpl >/etc/nginx/conf.d/channel$i.conf
envsubst '$UPSTREAM_PWA,$DOMAIN,$CHANNEL,$APPLICATION,$LANG,$FEATURES,$THEME' </etc/nginx/conf.d/channel.conf.tmpl >/etc/nginx/conf.d/channel$i.conf

i=$((i+1))
done
Expand Down

0 comments on commit c8d6eb5

Please sign in to comment.