From a50d89a9de784a4fe084c1c1ff7876679b8da96b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 2 Oct 2024 15:12:01 -0700 Subject: [PATCH] GUACAMOLE-374: Restore support for legacy Docker links. --- .../entrypoint.d/000-migrate-docker-links.sh | 94 +++++++++++++++++++ ...les.sh => 010-migrate-legacy-variables.sh} | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 guacamole-docker/entrypoint.d/000-migrate-docker-links.sh rename guacamole-docker/entrypoint.d/{000-migrate-legacy-variables.sh => 010-migrate-legacy-variables.sh} (99%) diff --git a/guacamole-docker/entrypoint.d/000-migrate-docker-links.sh b/guacamole-docker/entrypoint.d/000-migrate-docker-links.sh new file mode 100644 index 0000000000..800c7194c5 --- /dev/null +++ b/guacamole-docker/entrypoint.d/000-migrate-docker-links.sh @@ -0,0 +1,94 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +## +## @fn 000-migrate-docker-links.sh +## +## Checks for usage of any Docker links that were formerly supported +## but are now deprecated, warning when any deprecated Docker links are +## encountered. Until support for a deprecated variable is entirely removed, +## the values of environment variables that are injected by Docker for +## deprecated Docker links are automatically reassigned to currently supported +## variables. +## + +## +## Checks for usage of the given deprecated Docker link, automatically +## assigning the values of its associated environment variables to the given +## set of currently supported environment variables. If usage of the +## deprecated Docker link is found, a warning is printed to STDERR. +## +## @param LEGACY_LINK_NAME +## The name of the Docker link that's deprecated, as would be provided to +## the "docker" command with the "--link" option. +## +## @param LEGACY_LINK_PORT_NUMBER +## The TCP port number used by the service originally pointed to by the +## deprecated Docker link. This will be the port number exposed by the +## Docker image customarily used for that service. +## +## @param CURRENT_ADDR_VAR_NAME +## The name of the environment variable that is currently supported and +## represents the IP addresss or hostname of the service originally pointed +## to by the deprecated Docker link. +## +## @param CURRENT_PORT_VAR_NAME +## The name of the environment variable that is currently supported and +## represents the TCP port of the service originally pointed to by the +## deprecated Docker link. +## +deprecate_link() { + + local LEGACY_LINK_NAME="$1" + local LEGACY_LINK_PORT_NUMBER="$2" + local CURRENT_ADDR_VAR_NAME="$3" + local CURRENT_PORT_VAR_NAME="$4" + + # Determine names of environment variables injected by Docker for the link + # having the given name + local LEGACY_LINK_VAR_PREFIX="`echo "$LEGACY_LINK_NAME" | tr 'a-z' 'A-Z'`" + local LEGACY_ADDR_VAR_NAME="${LEGACY_LINK_VAR_PREFIX}_PORT_${LEGACY_LINK_PORT_NUMBER}_TCP_ADDR" + local LEGACY_PORT_VAR_NAME="${LEGACY_LINK_VAR_PREFIX}_PORT_${LEGACY_LINK_PORT_NUMBER}_TCP_PORT" + + # Docker will also inject a variable with a URL like "tcp://address:port" + # and a name that tends to collide with our own environment variables, so + # we must unset this variable if Docker links are found to be in use + local LEGACY_LINK_URL_VAR_NAME="${LEGACY_LINK_VAR_PREFIX}_PORT" + + if [ -n "${!LEGACY_ADDR_VAR_NAME}" -o -n "${!LEGACY_PORT_VAR_NAME}" ]; then + echo "WARNING: The \"$LEGACY_LINK_NAME\" Docker link has been deprecated in favor of the \"$CURRENT_ADDR_VAR_NAME\" and \"$CURRENT_PORT_VAR_NAME\" environment variables. Please migrate your configuration when possible, as Docker considers the linking feature to be legacy and support for Docker links may be removed in future releases. See: https://docs.docker.com/engine/network/links/" >&2 + export "$CURRENT_ADDR_VAR_NAME"="${!LEGACY_ADDR_VAR_NAME}" + export "$CURRENT_PORT_VAR_NAME"="${!LEGACY_PORT_VAR_NAME}" + unset "$LEGACY_LINK_URL_VAR_NAME" + fi + +} + +# Legacy Docker link support for connecting the webapp image with guacd +deprecate_link "guacd" 4822 "GUACD_HOSTNAME" "GUACD_PORT" + +# Legacy Docker link support for connecting the webapp image with the various +# supported databases +deprecate_link "mysql" 3306 "MYSQL_HOSTNAME" "MYSQL_PORT" +deprecate_link "postgres" 5432 "POSTGRESQL_HOSTNAME" "POSTGRESQL_PORT" +deprecate_link "sqlserver" 1433 "SQLSERVER_HOSTNAME" "SQLSERVER_PORT" + +# No other Docker links have been historically supported by the +# "guacamole/guacamole" image. + diff --git a/guacamole-docker/entrypoint.d/000-migrate-legacy-variables.sh b/guacamole-docker/entrypoint.d/010-migrate-legacy-variables.sh similarity index 99% rename from guacamole-docker/entrypoint.d/000-migrate-legacy-variables.sh rename to guacamole-docker/entrypoint.d/010-migrate-legacy-variables.sh index cb56c4c9ae..d57c87b19c 100644 --- a/guacamole-docker/entrypoint.d/000-migrate-legacy-variables.sh +++ b/guacamole-docker/entrypoint.d/010-migrate-legacy-variables.sh @@ -18,7 +18,7 @@ # ## -## @fn 000-migrate-legacy-variables.sh +## @fn 010-migrate-legacy-variables.sh ## ## Checks for usage of any environment variables that were formerly supported ## but are now deprecated, warning when any deprecated variables are