Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dependency_services): support bash 3.x #11434

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions scripts/dependency_services/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,44 @@ if [ $? -ne 0 ]; then
exit 1
fi

# [service_name_in_docker_compose]="env_var_name_1:port_1_in_docker_compose env_var_name_2:port_2_in_docker_compose"
declare -A ports=(
["postgres"]="PG_PORT:5432"
["redis"]="REDIS_PORT:6379 REDIS_SSL_PORT:6380"
["grpcbin"]="GRPCBIN_PORT:9000 GRPCBIN_SSL_PORT:9001"
["zipkin"]="ZIPKIN_PORT:9411"
# ["opentelemetry"]="OTELCOL_HTTP_PORT:4318 OTELCOL_ZPAGES_PORT:55679"
)
# Initialize parallel arrays for service names and port definitions
services=()
port_defs=()

# Add elements to the parallel arrays
services+=("postgres")
port_defs+=("PG_PORT:5432")

services+=("redis")
port_defs+=("REDIS_PORT:6379 REDIS_SSL_PORT:6380")

services+=("grpcbin")
port_defs+=("GRPCBIN_PORT:9000 GRPCBIN_SSL_PORT:9001")

services+=("zipkin")
port_defs+=("ZIPKIN_PORT:9411")

_kong_added_envs=""

# not all env variable needs all three prefix in all times, but we add all of them
# for simplicity: there's no side effect after all
# Not all env variables need all three prefixes, but we add all of them for simplicity
env_prefixes="KONG_ KONG_TEST_ KONG_SPEC_TEST_"

for svc in "${!ports[@]}"; do
for port_def in ${ports[$svc]}; do
for ((i = 0; i < ${#services[@]}; i++)); do
svc="${services[i]}"

for port_def in ${port_defs[i]}; do
env_name=$(echo $port_def |cut -d: -f1)
private_port=$(echo $port_def |cut -d: -f2)
exposed_port=$($DOCKER_COMPOSE port $svc $private_port | cut -d: -f2)
if [ -z $exposed_port ]; then
exposed_port="$($DOCKER_COMPOSE port "$svc" "$private_port" | cut -d: -f2)"

if [ -z "$exposed_port" ]; then
echo "Port $env_name for service $svc unknown"
continue
fi

for prefix in $env_prefixes; do
_kong_added_envs="$_kong_added_envs ${prefix}${env_name}"
echo "export ${prefix}${env_name}=$exposed_port" >> $KONG_SERVICE_ENV_FILE
echo "export ${prefix}${env_name}=$exposed_port" >> "$KONG_SERVICE_ENV_FILE"
done
done
done