Skip to content

Commit

Permalink
reworked handling of custom dns
Browse files Browse the repository at this point in the history
fixed LS v3 issues
  • Loading branch information
paulrobello committed Nov 21, 2023
1 parent ba0c51a commit cf3e196
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 20 deletions.
13 changes: 7 additions & 6 deletions .env-gdc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ if [ -z ${LOCALSTACK_HOST_DNS_PORT+x} ]; then
fi
export USE_LOCALSTACK_SHARED=${USE_LOCALSTACK_SHARED:=no} # mount shared volume in LS container under /shared
export LOCALSTACK_HOST_DNS_PORT
export LOCALSTACK_GATEWAY_LISTEN
export USE_LOCALSTACK_DNS=${USE_LOCALSTACK_DNS:=no} # set to yes to assign static ip to LS container and use it as primary DNS

export USE_AUTH0 # starts up auth0 mock container in container only mode
Expand All @@ -96,15 +97,15 @@ if [ -z ${SSH_KEYSCAN_HOSTS+x} ]; then
export SSH_KEYSCAN_HOSTS="gitlab.com github.com bitbucket.org" # copy ssh keys from these hosts to prevent unknown key prompts
fi


if [ -z "$GDC_DNS_PRI_IP" ]; then
export GDC_DNS_PRI_IP=8.8.8.8
fi

# default secondary dns to google secondary dns if not specified
if [ -z "$GDC_DNS_SEC_IP" ]; then
export GDC_DNS_SEC_IP=8.8.4.4
GDC_DNS_SEC_IP=8.8.4.4
fi

# these will only be used by the container if GDC_DNS_PRI_IP is defined
export GDC_DNS_PRI_IP
export GDC_DNS_SEC_IP

export DEVNET_GATEWAY

export USE_COLOR_PROMPT=${USE_COLOR_PROMPT:=yes} # enable colored bash prompt
Expand Down
7 changes: 7 additions & 0 deletions dc-dns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3.8"

services:
dev:
dns:
- ${GDC_DNS_PRI_IP}
- ${GDC_DNS_SEC_IP}
3 changes: 2 additions & 1 deletion dc-ls-host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ services:
- "443:443" # LocalStack HTTPS Gateway (required for Pro)
- "4571:4571" # elasticsearch service
environment:
- LOCALSTACK_HOST=${HOSTNAME_EXTERNAL-host.docker.internal}
# - LOCALSTACK_HOST=${LOCALSTACK_HOST-host.docker.internal:4566} # dont use this with LS 3.x
- GATEWAY_LISTEN=${LOCALSTACK_GATEWAY_LISTEN-0.0.0.0:4566,0.0.0.0:443}
2 changes: 0 additions & 2 deletions dc-ls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ services:
- EXTRA_CORS_ALLOWED_ORIGINS=http://host.docker.internal:4566
- DISABLE_CORS_CHECKS=1
- DEBUG=${DEBUG-}
- PROVIDER_OVERRIDE_S3=v3 # new LS native s3
# - LS_LOG=trace
# how long to keep idle lambdas around
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=15
# remove idle lambdas
- LAMBDA_REMOVE_CONTAINERS=1
# - LS_LOG=trace
# Tell Localstack to put Lambda containers on the same shared network
- LAMBDA_DOCKER_NETWORK=${DEVNET_NAME-devnet}
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY-}
Expand Down
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ services:
tty: true
networks:
devnet:
dns:
- ${GDC_DNS_PRI_IP}
- ${GDC_DNS_SEC_IP}
extra_hosts:
- "host.docker.internal:host-gateway"
build:
Expand Down Expand Up @@ -77,8 +74,8 @@ services:
- AWS_IDENTITY_ACCOUNT # used by AWS assume-role.sh script
- GIT_EMAIL # required for GIT if you don't have a .gitconfig in your home directory
- GIT_NAME # required for GIT if you don't have a .gitconfig in your home directory
- HOSTNAME_EXTERNAL # used by localstack
- LOCALSTACK_HOST # used by localstack
- LOCALSTACK_GATEWAY_LISTEN # used by localstack
- YARN_CACHE_FOLDER=/usr/local/share/.cache/yarn # cache yarn installs
- PIP_CACHE_DIR=/usr/local/share/.cache/pip # cache pip installs
- npm_config_cache=/usr/local/share/.cache/npm # case npm installs
Expand Down Expand Up @@ -114,7 +111,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.66 # used to detect if running inside dev container
- DEV_CONTAINER=1.9.7 # 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 @@ -203,6 +203,9 @@ if [ "$USE_LOCALSTACK" = "yes" ]; then
if [ -n "$LOCALSTACK_STATIC_IP" ]; then
echo "Localstack static ip: $LOCALSTACK_STATIC_IP"
fi
fi

if [ -n "$GDC_DNS_PRI_IP" ]; then
echo "GDC PRI DNS IP $GDC_DNS_PRI_IP"
echo "GDC SEC DNS IP $GDC_DNS_SEC_IP"
fi
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ These options control what packages / functionality are built into the container
`USE_` vars are **yes / no** values for toggling related options.

* GDC_NAME=<not set> - PROJECT_NAME will be set to this if no command line argument is specified for name.
* GDC_DNS_PRI_IP=8.8.8.8 - sets primary dns for GDC container. USE_LOCALSTACK_DNS=yes will override this.
* GDC_DNS_SEC_IP=8.8.4.4 - sets primary dns for GDC container. USE_LOCALSTACK_DNS=yes will override this.
* GDC_DNS_PRI_IP=<not set> - sets primary dns for GDC container. USE_LOCALSTACK_DNS=yes will override this.
* GDC_DNS_SEC_IP=8.8.4.4 - sets secondary dns for GDC container. This value is only used if GDC_DNS_PRI_IP is set.
* PROJECT_NAME=<set to 1st command line parameter when run-dev-container.sh is invoked> - used to suffix DEVNET_NAME, LOCALSTACK_VOLUME_DIR, DEV_CONTAINER_NAME.
* DEV_CONTAINER_NAME=dev-1 - sets the dev container name and is prepended with PROJECT_NAME.
* COMPOSE_BIN="docker compose" - sets method of execution for compose. Should be set to ether "docker compose" or "docker-compose"
Expand Down
14 changes: 10 additions & 4 deletions run-dev-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fi
export DEVNET_SUBNET
export LOCALSTACK_STATIC_IP


CACHE_VOLUMES_REQUIRED="pulumi pkg_cache"
SHARED_VOLUMES_REQUIRED="shared home_config"

Expand Down Expand Up @@ -193,6 +194,12 @@ fi

COMPOSE_FILES="-f docker-compose.yml"

if [ -n "$GDC_DNS_PRI_IP" ]; then
echo "Adding compose layer dc-dns.yml"
COMPOSE_FILES="$COMPOSE_FILES -f dc-dns.yml"
fi


if [ ! -d "./tmp" ]; then
mkdir ./tmp
fi
Expand All @@ -203,12 +210,11 @@ COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME//[ -]/_}"

export LS_MAIN_CONTAINER_NAME=${LS_MAIN_CONTAINER_NAME:="localstack_$COMPOSE_PROJECT_NAME"} # used by localstack to name main container
if [ "$USE_LOCALSTACK_HOST" = "yes" ]; then
export HOSTNAME_EXTERNAL=${HOSTNAME_EXTERNAL:=host.docker.internal}
export LOCALSTACK_HOST=${LOCALSTACK_HOST:=host.docker.internal:4566}
else
export HOSTNAME_EXTERNAL=${HOSTNAME_EXTERNAL:=$LS_MAIN_CONTAINER_NAME}
export LOCALSTACK_HOST=${LOCALSTACK_HOST:=$LS_MAIN_CONTAINER_NAME:4566}
fi
export LOCALSTACK_HOSTNAME="$HOSTNAME_EXTERNAL"

export LOCALSTACK_HOSTNAME=$(echo "$LOCALSTACK_HOST" | cut -d: -f1)

export DEVNET_NAME=${DEVNET_NAME:="devnet_$COMPOSE_PROJECT_NAME"}
if [ -z "$DEVNET_NAME" ]; then
Expand Down

0 comments on commit cf3e196

Please sign in to comment.