From 1532d65a5b2f4a64d6bddd94ab1932b57b8d39c8 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 12 Jul 2023 08:16:09 +0100 Subject: [PATCH] [ACA-4715] provide support for Docker variables (#3329) * provide support for Docker variables * remove test code * update docs --- Dockerfile | 1 + .../30-sed-on-appconfig.sh | 112 ++++++++++++++++++ docker/run.sh | 5 +- docs/getting-started/docker.md | 32 +++++ 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100755 docker/docker-entrypoint.d/30-sed-on-appconfig.sh diff --git a/Dockerfile b/Dockerfile index 5445f2746d..f6b941ea9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ RUN apk update && apk upgrade USER 101 COPY docker/default.conf.template /etc/nginx/templates/ +COPY docker/docker-entrypoint.d/* /docker-entrypoint.d/ COPY dist/content-ce /usr/share/nginx/html/ COPY dist/content-ce/app.config.json /etc/nginx/templates/app.config.json.template diff --git a/docker/docker-entrypoint.d/30-sed-on-appconfig.sh b/docker/docker-entrypoint.d/30-sed-on-appconfig.sh new file mode 100755 index 0000000000..2fd0a52568 --- /dev/null +++ b/docker/docker-entrypoint.d/30-sed-on-appconfig.sh @@ -0,0 +1,112 @@ +#!/bin/sh + +set -e + +APP_CONFIG_FILE="${NGINX_ENVSUBST_OUTPUT_DIR}/app.config.json" + +if [ -n "${APP_CONFIG_AUTH_TYPE}" ]; then + echo "SET APP_CONFIG_AUTH_TYPE" + + sed -e "s/\"authType\": \".*\"/\"authType\": \"${APP_CONFIG_AUTH_TYPE}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_PROVIDER}" ]; then + echo "SET APP_CONFIG_PROVIDER" + + sed -e "s/\"providers\": \".*\"/\"providers\": \"${APP_CONFIG_PROVIDER}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_IDENTITY_HOST}" ]; then + echo "SET APP_CONFIG_IDENTITY_HOST" + + replace="\/" + encodedIdentity=${APP_CONFIG_IDENTITY_HOST//\//$replace} + sed -e "s/\"identityHost\": \".*\"/\"identityHost\": \"$encodedIdentity\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_HOST}" ]; then + echo "SET APP_CONFIG_OAUTH2_HOST" + + replace="\/" + encoded=${APP_CONFIG_OAUTH2_HOST//\//$replace} + sed -e "s/\"host\": \".*\"/\"host\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_CLIENTID}" ]; then + echo "SET APP_CONFIG_OAUTH2_CLIENTID" + + sed -e "s/\"clientId\": \".*\"/\"clientId\": \"${APP_CONFIG_OAUTH2_CLIENTID}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}" ]; then + echo "SET APP_CONFIG_OAUTH2_IMPLICIT_FLOW" + + sed -e "s/\"implicitFlow\": [^,]*/\"implicitFlow\": ${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_SILENT_LOGIN}" ]; then + echo "SET APP_CONFIG_OAUTH2_SILENT_LOGIN" + + sed -e "s/\"silentLogin\": [^,]*/\"silentLogin\": ${APP_CONFIG_OAUTH2_SILENT_LOGIN}/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI}" ]; then + echo "SET APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI" + + replace="\/" + encoded=${APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI//\//$replace} + sed -e "s/\"redirectSilentIframeUri\": \".*\"/\"redirectSilentIframeUri\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_LOGIN}" ]; then + echo "SET APP_CONFIG_OAUTH2_REDIRECT_LOGIN" + + replace="\/" + encoded=${APP_CONFIG_OAUTH2_REDIRECT_LOGIN//\//$replace} + sed -e "s/\"redirectUri\": \".*\"/\"redirectUri\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_CONFIG_OAUTH2_REDIRECT_LOGOUT}" ]; then + echo "SET APP_CONFIG_OAUTH2_REDIRECT_LOGOUT" + + replace="\/" + encoded=${APP_CONFIG_OAUTH2_REDIRECT_LOGOUT//\//$replace} + sed -e "s/\"redirectUriLogout\": \".*\"/\"redirectUriLogout\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [[ -n "${APP_CONFIG_BPM_HOST}" ]]; then + echo "SET APP_CONFIG_BPM_HOST" + + replace="\/" + encoded=${APP_CONFIG_BPM_HOST//\//$replace} + sed -e "s/\"bpmHost\": \".*\"/\"bpmHost\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [[ -n "${APP_CONFIG_ECM_HOST}" ]]; then + echo "SET APP_CONFIG_ECM_HOST" + + replace="\/" + encoded=${APP_CONFIG_ECM_HOST//\//$replace} + sed -e "s/\"ecmHost\": \".*\"/\"ecmHost\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi + +if [ -n "${APP_BASE_SHARE_URL}" ]; then + echo "SET APP_BASE_SHARE_URL" + + replace="\/" + encoded=${APP_BASE_SHARE_URL//\//$replace} + sed -e "s/\"baseShareUrl\": \".*\"/\"baseShareUrl\": \"${encoded}\"/g" \ + -i "$APP_CONFIG_FILE" +fi diff --git a/docker/run.sh b/docker/run.sh index 49429bfdc4..11bfc98ee0 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -8,4 +8,7 @@ docker rmi -f $DOCKER_IMAGE_REPO docker build -t $DOCKER_IMAGE_REPO . echo "http://localhost:${HOST_PORT}" -docker run --rm -it --user 1000:1000 --publish $HOST_PORT:$CONTAINER_PORT $DOCKER_IMAGE_REPO + +docker run --rm -it \ + --user 1000:1000 \ + --publish $HOST_PORT:$CONTAINER_PORT $DOCKER_IMAGE_REPO diff --git a/docs/getting-started/docker.md b/docs/getting-started/docker.md index 2fc42643c6..f9d115ed8f 100644 --- a/docs/getting-started/docker.md +++ b/docs/getting-started/docker.md @@ -46,3 +46,35 @@ docker run --rm -it --user 1000:1000 --publish 8081:8080 alfresco/alfresco-conte ``` Navigate to `http://localhost:8081`. + +## Docker Variables + +There is a number of environment variables that you can define to override the default configuration: + +**Example** + +```shell +docker run --rm -it \ + --env APP_CONFIG_AUTH_TYPE="OAUTH" \ + --env APP_CONFIG_ECM_HOST="https://some.host.com" \ + --user 1000:1000 \ + --publish 8081:8080 alfresco/alfresco-content-app +``` + +### Configuration Mapping + +| Name | Config Path | +|----------------------------------------------|----------------------------------| +| APP_CONFIG_AUTH_TYPE | `authType` | +| APP_CONFIG_PROVIDER | `providers` | +| APP_CONFIG_IDENTITY_HOST | `identityHost` | +| APP_CONFIG_BPM_HOST | `bpmHost` | +| APP_CONFIG_ECM_HOST | `ecmHost` | +| APP_BASE_SHARE_URL | `baseShareUrl` | +| APP_CONFIG_OAUTH2_HOST | `oauth2.host` | +| APP_CONFIG_OAUTH2_CLIENTID | `oauth2.clientId` | +| APP_CONFIG_OAUTH2_IMPLICIT_FLOW | `oauth2.implicitFlow` | +| APP_CONFIG_OAUTH2_SILENT_LOGIN | `oauth2.silentLogin` | +| APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI | `oauth2.redirectSilentIframeUri` | +| APP_CONFIG_OAUTH2_REDIRECT_LOGIN | `oauth2.redirectUri` | +| APP_CONFIG_OAUTH2_REDIRECT_LOGOUT | `oauth2.redirectUriLogout` |