Skip to content

Commit

Permalink
static ip auto gen for localstack is now randomized to allow for pipe…
Browse files Browse the repository at this point in the history
…line concurrency
  • Loading branch information
paulrobello committed Nov 14, 2023
1 parent 7063545 commit abe015a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ services:
- PROXY_VOLUME_DIR # where to persist cert files. defaults to /tmp/mitproxy
- PROXY_URL # http(s) proxy to use. if USE_PROXY_HOST is enabled will be set to http://PROXY_CONTAINER_NAME:8080
- PROXY_AUTO_EXPORT_ENV # auto export HTTP_PROXY and HTTPS_PROXY vars equal to PROXY_URL
- DEV_CONTAINER=1.9.64 # used to detect if running inside dev container
- DEV_CONTAINER=1.9.65 # used to detect if running inside dev container
volumes:
- /var/run/docker.sock:/var/run/docker.sock # allow container to interact with host docker
- "${GDC_DIR}:/root/gdc-host" # mount gdc folder inside container to get access to compose files
Expand Down
3 changes: 3 additions & 0 deletions etc/skel/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ if [ "$USE_LOCALSTACK" = "yes" ]; then
alias awsl="aws --endpoint-url http://$LS_MAIN_CONTAINER_NAME:4566"
export LOCALSTACK_HOST=localstack:4566
fi
if [ -n "$LOCALSTACK_STATIC_IP" ]; then
echo "Localstack static ip: $LOCALSTACK_STATIC_IP"
fi
fi

if [ -n "$PULUMI_VERSION" ]; then
Expand Down
26 changes: 23 additions & 3 deletions run-dev-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,32 @@ if [ -r "./.env-gdc-local" ]; then
source ./.env-gdc-local
fi

# Function to convert a string to a number in the range 10-200
convert_string_to_number() {
local input_string=$1

# Compute a simple hash of the string
local hash_value=$(echo -n "$input_string" | md5sum | cut -d' ' -f1 | tr -cd '0-9' | cut -c 1-5)

# Ensure the hash value is treated as base-10
local numeric_value=$((10#$hash_value))

# Scale the hash value to the range 10-200
local scaled_value=$((10 + numeric_value % 191))

echo $scaled_value
}

if [ "$USE_LOCALSTACK_DNS" = "yes" ]; then
if [[ -n "$DEVNET_SUBNET" && -z "$LOCALSTACK_STATIC_IP" ]]; then
echo "ERROR: When USE_LOCALSTACK_DNS=yes and DEVNET_SUBNET is specified, you must also specify LOCALSTACK_STATIC_IP"
exit 1
fi
if [ -z "$DEVNET_SUBNET" ]; then
export DEVNET_SUBNET="172.21.0.0/16"
export LOCALSTACK_STATIC_IP=172.21.0.10
D=$(date)
OCTET=$(convert_string_to_number "$CI_JOB_TOKEN,$D")
export DEVNET_SUBNET="172.$OCTET.0.0/16"
export LOCALSTACK_STATIC_IP="172.$OCTET.0.10"
fi
export GDC_DNS_PRI_IP="$LOCALSTACK_STATIC_IP"
fi
Expand Down Expand Up @@ -544,7 +562,9 @@ echo "GDC_COMPOSE_FILES=$GDC_COMPOSE_FILES"
echo "SHARED_VOLUMES=$SHARED_VOLUMES"
echo "GDC_ENTRYPOINT=$GDC_ENTRYPOINT"
echo "COPY_CMD_TO_CLIPBOARD=$COPY_CMD_TO_CLIPBOARD"

if [ -n "$LOCALSTACK_STATIC_IP" ]; then
echo "LOCALSTACK_STATIC_IP=$LOCALSTACK_STATIC_IP"
fi
#exit ########### DEBUG #############

if [ "$GDC_RUN_MODE" = "stop" ]; then
Expand Down

0 comments on commit abe015a

Please sign in to comment.