Skip to content

Commit

Permalink
#32: Add support for LAUNCH_EXT_NETWORKS_IPV6 and LAUNCH_EXT_NETWORKS…
Browse files Browse the repository at this point in the history
…_MIXED
  • Loading branch information
tlex committed Feb 2, 2023
1 parent 0ec6d1b commit ce528f7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ The following environment variables are important if you don't supply a `/docker
| `LAUNCH_NETWORKS` | - | NO | Space separated list of project networks to create. All networks are created with `attachable: true` |
| `LAUNCH_EXT_NETWORKS` | - | NO | Space separated list of external networks to attach to |
| `LAUNCH_EXT_NETWORKS_IPV4` | - | NO | Similar to `LAUNCH_EXT_NETWORKS`, this is a space separated list of ExistingExternalNetworkName:Ipv4Address |
| `LAUNCH_EXT_NETWORKS_IPV6` | - | NO | Similar to `LAUNCH_EXT_NETWORKS`, this is a space separated list of ExistingExternalNetworkName-Ipv6Address |
| `LAUNCH_EXT_NETWORKS_MIXED` | - | NO | Similar to `LAUNCH_EXT_NETWORKS`, this is a space separated list of ExistingExternalNetworkName-Ipv4Address-Ipv6Address |
| `LAUNCH_CAP_ADD` | - | NO | Space separated list of capabilities to add |
| `LAUNCH_CAP_DROP` | - | NO | Space separated list of capabilities to drop |
| `LAUNCH_SECURITY_OPT` | - | NO | Space separated list of security options to add |
Expand Down
42 changes: 39 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ if [ -f "${COMPOSE_FILE}" ]; then
'LAUNCH_NETWORKS'
'LAUNCH_EXT_NETWORKS'
'LAUNCH_EXT_NETWORKS_IPV4'
'LAUNCH_EXT_NETWORKS_IPV6'
'LAUNCH_EXT_NETWORKS_MIXED'
'LAUNCH_CAP_ADD'
'LAUNCH_CAP_DROP'
'LAUNCH_SECURITY_OPT'
Expand Down Expand Up @@ -292,14 +294,22 @@ xEOF
fi

##
# The three major network variables:
# The four major network variables:
# LAUNCH_NETWORKS
# LAUNCH_EXT_NETWORKS
# LAUNCH_EXT_NETWORKS_IPV4
# LAUNCH_EXT_NETWORKS_IPV6
# LAUNCH_EXT_NETWORKS_MIXED
#
# Keep them separated for better readability and easier treoubleshooting, at the cost of code duplication
##
if [ -n "${LAUNCH_NETWORKS}" ] || [ -n "${LAUNCH_EXT_NETWORKS}" ] || [ -n "${LAUNCH_EXT_NETWORKS_IPV4}" ]; then
if \
[ -n "${LAUNCH_NETWORKS}" ] || \
[ -n "${LAUNCH_EXT_NETWORKS}" ] || \
[ -n "${LAUNCH_EXT_NETWORKS_IPV4}" ] || \
[ -n "${LAUNCH_EXT_NETWORKS_IPV6}" ] || \
[ -n "${LAUNCH_EXT_NETWORKS_MIXED}" ] \
; then
# LAUNCH_NETWORKS are networks that get created on the fly, at start
echo " networks:" >> "${COMPOSE_FILE}"
for NETWORK in ${LAUNCH_NETWORKS}; do
Expand All @@ -317,7 +327,33 @@ xEOF
IFS=':' read -r NETWORK IPV4 <<< "${NETWORK}"
{
echo " ${NETWORK}:"
echo " ipv4_address: ${IPV4}"
echo " ipv4_address: '${IPV4}'"
} >> "${COMPOSE_FILE}"
done
fi
# LAUNCH_EXT_NETWORKS_IPV6 are existing attachable networks, where the IP is manually assigned
# The format is `network1-ip1 network2-ip2 ... networkN-ipN`
if [ -n "${LAUNCH_EXT_NETWORKS_IPV6}" ]; then
read -ra ARR <<<"${LAUNCH_EXT_NETWORKS_IPV6}"
for NETWORK in "${ARR[@]}"; do
IFS=':' read -r NETWORK IPV6 <<< "${NETWORK}"
{
echo " ${NETWORK}:"
echo " ipv6_address: '${IPV6}'"
} >> "${COMPOSE_FILE}"
done
fi
# LAUNCH_EXT_NETWORKS_MIXED are existing attachable networks, where the IP is manually assigned
# This assumes both IPv4 and IPv6 addresses are manually assigned
# The format is `network1-ipv4-ipv6 network2-ipv4-ipv6 ... networkN-ipv4-ipv6`
if [ -n "${LAUNCH_EXT_NETWORKS_MIXED}" ]; then
read -ra ARR <<<"${LAUNCH_EXT_NETWORKS_MIXED}"
for NETWORK in "${ARR[@]}"; do
IFS='-' read -r NETWORK IPV4 IPV6 <<< "${NETWORK}"
{
echo " ${NETWORK}:"
echo " ipv4_address: '${IPV4}'"
echo " ipv6_address: '${IPV6}'"
} >> "${COMPOSE_FILE}"
done
fi
Expand Down

0 comments on commit ce528f7

Please sign in to comment.