Skip to content

Commit

Permalink
#26: Ensure the same style is used consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
tlex committed Feb 6, 2021
1 parent 2aa583f commit bb71cee
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,37 @@ xEOF
echo " - \"$PORT\"" >> ${COMPOSE_FILE}
done
fi
if [ -n "${LAUNCH_NETWORKS}" ] || [ -n "${LAUNCH_EXT_NETWORKS}" ]; then

##
# The three major network variables:
# LAUNCH_NETWORKS
# LAUNCH_EXT_NETWORKS
# LAUNCH_EXT_NETWORKS_IPV4
#
# 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
# LAUNCH_NETWORKS are networks that get created on the fly, at start
echo " networks:" >> ${COMPOSE_FILE}
for NETWORK in ${LAUNCH_NETWORKS}; do
echo " ${NETWORK}:" >> ${COMPOSE_FILE}
done
# LAUNCH_EXT_NETWORKS are existing attachable networks
for NETWORK in ${LAUNCH_EXT_NETWORKS}; do
echo " ${NETWORK}:" >> ${COMPOSE_FILE}
if [ -n "${LAUNCH_EXT_NETWORKS_IPV4}" ]; then
for NETWORK_IPV4 in ${LAUNCH_EXT_NETWORKS_IPV4}; do
if [ "${NETWORK_IPV4%%:*}" = "${NETWORK}" ]; then
echo " ipv4_address: ${NETWORK_IPV4##*:}" >> ${COMPOSE_FILE}
break
fi
done
fi
done
# LAUNCH_EXT_NETWORKS_IPV4 are existing attachable networks, where the IP is manually assigned
# The format is `network1:ip1 network2:ip2 ... networkN:ipN`
if [ -n "${LAUNCH_EXT_NETWORKS_IPV4}" ]; then
read -ra ARR <<<"${LAUNCH_EXT_NETWORKS_IPV4}"
for NETWORK in "${ARR[@]}"; do
IFS=':' read -r NETWORK IPV4 <<< "${NETWORK}"
{
echo " ${NETWORK}:"
echo " ipv4_address: ${IPV4}"
} >> ${COMPOSE_FILE}
done
fi
echo "networks:" >> ${COMPOSE_FILE}
for NETWORK in ${LAUNCH_NETWORKS}; do
{
Expand All @@ -281,6 +296,12 @@ xEOF
echo " external: true";
} >> ${COMPOSE_FILE}
done
for NETWORK in ${LAUNCH_EXT_NETWORKS_IPV4}; do
{
echo " ${NETWORK}:";
echo " external: true";
} >> ${COMPOSE_FILE}
done
fi
fi
fi
Expand Down

0 comments on commit bb71cee

Please sign in to comment.