From bb15924c95bd01e103fada441c7544115a6c5d8c Mon Sep 17 00:00:00 2001 From: "mathieu.brunot" Date: Mon, 8 Feb 2021 13:25:42 +0100 Subject: [PATCH] :whale: Frontend configuration on env var Signed-off-by: mathieu.brunot --- docker/images/Dockerfile.frontend | 1 + docker/images/files/config.js | 9 +++ docker/images/files/nginx-entrypoint.sh | 87 +++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 docker/images/files/config.js diff --git a/docker/images/Dockerfile.frontend b/docker/images/Dockerfile.frontend index b9c083348..43c46e53c 100644 --- a/docker/images/Dockerfile.frontend +++ b/docker/images/Dockerfile.frontend @@ -2,6 +2,7 @@ FROM nginx:latest LABEL maintainer="Andrey Antukh " ADD ./bundle/frontend /var/www/app/ +ADD ./files/config.js /var/www/app/js/config.js ADD ./files/nginx.conf /etc/nginx/nginx.conf ADD ./files/nginx-entrypoint.sh /entrypoint.sh diff --git a/docker/images/files/config.js b/docker/images/files/config.js new file mode 100644 index 000000000..621108073 --- /dev/null +++ b/docker/images/files/config.js @@ -0,0 +1,9 @@ +// Frontend configuration + +//var penpotPublicURI = "https://penpot.example.com"; +//var penpotDemoWarning = ; +//var penpotAllowDemoUsers = ; +//var penpotGoogleClientID = ""; +//var penpotGitlabClientID = ""; +//var penpotGithubClientID = ""; +//var penpotLoginWithLDAP = ; diff --git a/docker/images/files/nginx-entrypoint.sh b/docker/images/files/nginx-entrypoint.sh index e2fce2c44..6c0a428f5 100644 --- a/docker/images/files/nginx-entrypoint.sh +++ b/docker/images/files/nginx-entrypoint.sh @@ -1,3 +1,90 @@ #!/usr/bin/env bash +log() { + echo "[$(date +%Y-%m-%dT%H:%M:%S%:z)] $*" +} + + +######################################### +## App Frontend config +######################################### + + +update_public_uri() { + if [ -n "$PENPOT_PUBLIC_URI" ]; then + log "Updating Public URI: $PENPOT_PUBLIC_URI" + sed -i \ + -e "s|^//var penpotPublicURI = \".*\";|var penpotPublicURI = \"$PENPOT_PUBLIC_URI\";|g" \ + "$1" + fi +} + + +update_demo_warning() { + if [ -n "$PENPOT_DEMO_WARNING" ]; then + log "Updating Demo Warning: $PENPOT_DEMO_WARNING" + sed -i \ + -e "s|^//var penpotDemoWarning = .*;|var penpotDemoWarning = $PENPOT_DEMO_WARNING;|g" \ + "$1" + fi +} + + +update_allow_demo_users() { + if [ -n "$PENPOT_ALLOW_DEMO_USERS" ]; then + log "Updating Allow Demo Users: $PENPOT_ALLOW_DEMO_USERS" + sed -i \ + -e "s|^//var penpotAllowDemoUsers = .*;|var penpotAllowDemoUsers = $PENPOT_ALLOW_DEMO_USERS;|g" \ + "$1" + fi +} + + +update_google_client_id() { + if [ -n "$PENPOT_GOOGLE_CLIENT_ID" ]; then + log "Updating Google Client Id: $PENPOT_GOOGLE_CLIENT_ID" + sed -i \ + -e "s|^//var penpotGoogleClientID = \".*\";|var penpotGoogleClientID = \"$PENPOT_GOOGLE_CLIENT_ID\";|g" \ + "$1" + fi +} + + +update_gitlab_client_id() { + if [ -n "$PENPOT_GITLAB_CLIENT_ID" ]; then + log "Updating GitLab Client Id: $PENPOT_GITLAB_CLIENT_ID" + sed -i \ + -e "s|^//var penpotGitlabClientID = \".*\";|var penpotGitlabClientID = \"$PENPOT_GITLAB_CLIENT_ID\";|g" \ + "$1" + fi +} + + +update_github_client_id() { + if [ -n "$PENPOT_GITHUB_CLIENT_ID" ]; then + log "Updating GitHub Client Id: $PENPOT_GITHUB_CLIENT_ID" + sed -i \ + -e "s|^//var penpotGithubClientID = \".*\";|var penpotGithubClientID = \"$PENPOT_GITHUB_CLIENT_ID\";|g" \ + "$1" + fi +} + + +update_login_with_ldap() { + if [ -n "$PENPOT_LOGIN_WITH_LDAP" ]; then + log "Updating Login with LDAP: $PENPOT_LOGIN_WITH_LDAP" + sed -i \ + -e "s|^//var penpotLoginWithLDAP = .*;|var penpotLoginWithLDAP = $PENPOT_LOGIN_WITH_LDAP;|g" \ + "$1" + fi +} + +update_public_uri /var/www/app/js/config.js +update_demo_warning /var/www/app/js/config.js +update_allow_demo_users /var/www/app/js/config.js +update_google_client_id /var/www/app/js/config.js +update_gitlab_client_id /var/www/app/js/config.js +update_github_client_id /var/www/app/js/config.js +update_login_with_ldap /var/www/app/js/config.js + exec "$@";