Skip to content

Commit

Permalink
fix(dependency_services): support bash 3.x (#11434)
Browse files Browse the repository at this point in the history
macOS ships bash 3.x by default
  • Loading branch information
fffonion authored Aug 29, 2023
1 parent 4fe2a78 commit 081039a
Showing 1 changed file with 26 additions and 15 deletions.
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

1 comment on commit 081039a

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:081039aa4967f42da64b4fbe55b9c87670785fc1
Artifacts available https://github.com/Kong/kong/actions/runs/6010091127

Please sign in to comment.