Skip to content

Commit

Permalink
added support for custom GDC dns
Browse files Browse the repository at this point in the history
add option for static ip on LS container
added option to LS container for GDC primary dns
  • Loading branch information
paulrobello committed Oct 9, 2023
1 parent 9c173cf commit 2f8afe9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
13 changes: 11 additions & 2 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 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
export USE_AUTH0_HOST # starts up auth0 mock container and forwards port from host. Use AUTH0_HOST_PORT to change default of 3001
Expand All @@ -94,8 +95,16 @@ export VISUAL=${VISUAL:=vi} # sets default editor in container. usually set to s
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
export DEVNET_NAME
export DEVNET_SUBNET


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

if [ -z "$GDC_DNS_SEC_IP" ]; then
export GDC_DNS_SEC_IP=8.8.4.4
fi

export DEVNET_GATEWAY

export USE_COLOR_PROMPT=${USE_COLOR_PROMPT:=yes} # enable colored bash prompt
Expand Down
2 changes: 1 addition & 1 deletion dc-ls-host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
- DEBUG=${DEBUG-}
# - LS_LOG=trace
# docker or docker-reuse
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-docker-reuse} # this is deprecated in V2 and will be removed.
# - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-docker-reuse} # this is deprecated in V2 and will be removed.
# remove idle lambdas
- LAMBDA_REMOVE_CONTAINERS=1
# how long to keep idle lambdas around
Expand Down
7 changes: 7 additions & 0 deletions dc-ls-static-ip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.8'

services:
localstack:
networks:
devnet:
ipv4_address: ${LOCALSTACK_STATIC_IP}
3 changes: 2 additions & 1 deletion dc-ls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- PROVIDER_OVERRIDE_S3=v3 # new LS native s3
- DEBUG=${DEBUG-}
# - LS_LOG=trace
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-docker-reuse} # this is deprecated in V2 and will be removed
# - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-docker-reuse} # this is deprecated in V2 and will be removed
# Tell Localstack to put Lambda containers on the same shared network
- LAMBDA_DOCKER_NETWORK=${DEVNET_NAME-devnet}
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY-}
Expand All @@ -36,3 +36,4 @@ networks:
devnet:
name: ${DEVNET_NAME-devnet}
external: true

11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ services:
tty: true
networks:
devnet:
dns:
- ${GDC_DNS_PRI_IP}
- ${GDC_DNS_SEC_IP}
extra_hosts:
- "host.docker.internal:host-gateway"
build:
context: .
dockerfile: Dockerfile
Expand All @@ -30,6 +35,8 @@ services:
- COMPOSE_PROJECT_NAME
- PROJECT_NAME=${COMPOSE_PROJECT_NAME}
- GDC_CONTAINER_NAME # name of GDC container running in docker
- GDC_DNS_PRI_IP # ip gdc should use for primary DNS. defaults to 8.8.8.8 but can be changed to localstack container or other source
- GDC_DNS_SEC_IP # ip gdc should use for secondary DNS. Cant be same as GDC_DNS_PRI_IP
- DOCKER_OS_PLATFORM # can be used to build containers for other arch's
- HOST_PROJECT_PATH # helps with volume mounts if you run containers from within dev container
- HOST_PROJECT_FOLDER_NAME # dirname $HOST_PROJECT_PATH
Expand All @@ -53,6 +60,7 @@ services:
- AUTH0_DEFAULT_PASSWORD # used to auto-populate auth0 mock login page
- LOCALSTACK_VOLUME_DIR # needed by LS v1.x. no effect when LS is not being used
- USE_LOCALSTACK # does not install or start localstack. Only sets up some helpers
- USE_LOCALSTACK_DNS # this will put LS container on static ip and set GDC to use its DNS. default no
- USE_LOCALSTACK_PERSISTENCE # toggle persistent storage for LS defaults to persistence enabled.
- USE_LOCALSTACK_HOST # forwards localstack ports to host if LS_VERSION is set
- LOCALSTACK_HOSTNAME # contains hostname of container or host depending on mode
Expand All @@ -61,6 +69,7 @@ services:
- LS_MAIN_CONTAINER_NAME # used by localstack
- LOCALSTACK_API_KEY # required if you want to use localstack pro
- LOCALSTACK_HOST_DNS_PORT # forward this port from host to localstack for DNS
- LOCALSTACK_STATIC_IP # set static container ip for LS. Useful for DNS
- PERSIST_BITWARDEN_SESSION # persist unlocked vault creds between container sessions
- USE_CDK # install cdk if set to yes
- USE_AWS_HOME # copy .aws folder from host home if exists and USE_HOST_HOME=yes
Expand Down Expand Up @@ -104,7 +113,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.2 # used to detect if running inside dev container
- DEV_CONTAINER=1.9.3 # 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
12 changes: 8 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ Running with no arguments or `-h` as first arguments will display help.
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_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.
* 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 All @@ -105,8 +107,8 @@ These options control what packages / functionality are built into the container
* USE_HOST_HOME=yes - mounts users home directory into container under /root/host-home. Required by some other options.
* USE_HOME_BIN=no - copy bin folder from host home directory if it exists. Enables USE_HOST_HOME.
* PULUMI_VERSION=latest - a version or "latest" must be specified for Pulumi to be installed.
* PHP_VERSION=<not set> - installs any of the following PHP versions 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2
* USE_DOT_NET=no - installs .NET SDK v6.x
* PHP_VERSION=<not set> - installs any of the following PHP versions 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2.
* USE_DOT_NET=no - installs .NET SDK v6.x.
* USE_JAVA=no - installs headless openjdk v11.x.
* PYTHON_VERSION=3.11 - installs Python v3.11, which is highest aws lambda supported python runtime
* USE_PRECOMMIT=no - installs git pre-commit hooks in repo if not already installed. Enables Python if not already enabled.
Expand All @@ -125,7 +127,9 @@ These options control what packages / functionality are built into the container
* LS_IMAGE=localstack/localstack - if LOCALSTACK_API_KEY is specified then defaults to localstack/localstack-pro. Can override with custom image location. Still uses LS_VERSION to create final image location.
* LS_VERSION=<not set> - starts a localstack container running specified version.
* USE_LOCALSTACK_HOST=yes - forwards localstack ports to host if LS_VERSION is set.
* USE_LOCALSTACK_SHARED=no - mount gdc shared volume in LS container under /shared
* USE_LOCALSTACK_SHARED=no - mount gdc shared volume in LS container under /shared.
* USE_LOCALSTACK_DNS=no - assigns static ip to LS container and sets GDC to use its dns.
* LOCALSTACK_STATIC_IP=<not set> - sets a static ip for LS container if set. Will be auto set if not specified and USE_LOCALSTACK_DNS=yes.
* LOCALSTACK_HOST_DNS_PORT=53 - when LocalStack is running in host mode forward this port from host to localstack. Set to blank string to disable localstack DNS forward.
* USE_AUTH0=no - starts an auth0 mock authentication server. Can be accessed via name auth0_mock inside containers. [Auth0 Mock docs](./docs/auth0/readme.md).
* USE_AUTH0_HOST=yes - starts an auth0 mock authentication server with host port forward.
Expand Down
3 changes: 3 additions & 0 deletions root/bin/ls/start-ls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ else
COMPOSE_FILES="-f dc-ls-host.yml"
fi

if [ -n "$LOCALSTACK_STATIC_IP" ]; then
COMPOSE_FILES="$COMPOSE_FILES -f dc-ls-static-ip.yml"
fi
if [ -n "$LOCALSTACK_HOST_DNS_PORT" ]; then
COMPOSE_FILES="$COMPOSE_FILES -f dc-ls-host-dns.yml"
fi
Expand Down
19 changes: 19 additions & 0 deletions run-dev-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ if [ -r "./.env-gdc-local" ]; then
source ./.env-gdc-local
fi

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.20.0.0/16"
export LOCALSTACK_STATIC_IP=172.20.0.10
fi
export GDC_DNS_PRI_IP="$LOCALSTACK_STATIC_IP"
fi

export DEVNET_SUBNET
export LOCALSTACK_STATIC_IP

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

Expand Down Expand Up @@ -319,6 +334,10 @@ if [ -n "$LS_VERSION" ]; then
docker pull "$LS_IMAGE"
fi
export USE_LOCALSTACK=yes

if [ -n "$LOCALSTACK_STATIC_IP" ]; then
COMPOSE_FILES="$COMPOSE_FILES -f dc-ls-static-ip.yml"
fi
if [ "$USE_LOCALSTACK_HOST" = "yes" ]; then
echo "Adding compose layer dc-ls-host.yml"
COMPOSE_FILES="$COMPOSE_FILES -f dc-ls-host.yml"
Expand Down

0 comments on commit 2f8afe9

Please sign in to comment.