Skip to content

Commit

Permalink
GUACAMOLE-374: Restore support for legacy Docker links.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-jumper committed Oct 2, 2024
1 parent 02138fb commit a50d89a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
94 changes: 94 additions & 0 deletions guacamole-docker/entrypoint.d/000-migrate-docker-links.sh
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a50d89a

Please sign in to comment.