2022-05-11 22:47:31 +00:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -e
|
2020-02-19 04:55:06 +00:00
|
|
|
|
|
|
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2020-05-21 06:11:19 +00:00
|
|
|
|
. "$DIR/.common.sh"
|
2020-02-19 04:55:06 +00:00
|
|
|
|
|
2022-05-11 22:47:31 +00:00
|
|
|
|
get_container_ip () {
|
|
|
|
|
local container_name=$1
|
|
|
|
|
local container
|
|
|
|
|
local ip
|
2023-04-11 11:26:09 +00:00
|
|
|
|
container=$(docker-compose ps --all -q "${container_name}" | tail -n1)
|
2022-05-11 22:47:31 +00:00
|
|
|
|
ip=$(docker inspect -f "{{.NetworkSettings.Networks.npmdev_default.IPAddress}}" "$container")
|
|
|
|
|
echo "$ip"
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 04:55:06 +00:00
|
|
|
|
# Ensure docker-compose exists
|
|
|
|
|
if hash docker-compose 2>/dev/null; then
|
|
|
|
|
cd "${DIR}/.."
|
|
|
|
|
echo -e "${BLUE}❯ ${CYAN}Starting Dev Stack ...${RESET}"
|
|
|
|
|
|
2022-05-11 22:47:31 +00:00
|
|
|
|
# Bring up a stack, in steps so we can inject IPs everywhere
|
2023-02-25 12:52:42 +00:00
|
|
|
|
docker-compose up -d npm-pdns npm-pdns-db
|
|
|
|
|
PDNS_IP=$(get_container_ip 'npm-pdns')
|
2022-05-11 22:47:31 +00:00
|
|
|
|
echo -e "${BLUE}❯ ${YELLOW}PDNS IP is ${PDNS_IP}${RESET}"
|
|
|
|
|
|
|
|
|
|
# adjust the dnsrouter config
|
|
|
|
|
LOCAL_DNSROUTER_CONFIG="$DIR/../docker/dev/dnsrouter-config.json"
|
|
|
|
|
rm -rf "$LOCAL_DNSROUTER_CONFIG.tmp"
|
|
|
|
|
# IMPORTANT: changes to dnsrouter-config.json will affect this line:
|
|
|
|
|
jq --arg a "$PDNS_IP" '.servers[0].upstreams[1].upstream = $a' "$LOCAL_DNSROUTER_CONFIG" > "$LOCAL_DNSROUTER_CONFIG.tmp"
|
|
|
|
|
|
|
|
|
|
# dnsrouter
|
2023-02-25 12:52:42 +00:00
|
|
|
|
docker-compose up -d npm-dnsrouter
|
|
|
|
|
DNSROUTER_IP=$(get_container_ip 'npm-dnsrouter')
|
2022-05-11 22:47:31 +00:00
|
|
|
|
echo -e "${BLUE}❯ ${YELLOW}DNS Router IP is ${DNSROUTER_IP}${RESET}"
|
|
|
|
|
|
|
|
|
|
# mount the resolver
|
|
|
|
|
LOCAL_RESOLVE="$DIR/../docker/dev/resolv.conf"
|
|
|
|
|
rm -rf "${LOCAL_RESOLVE}"
|
|
|
|
|
printf "nameserver %s\noptions ndots:0" "${DNSROUTER_IP}" > "${LOCAL_RESOLVE}"
|
2020-02-19 04:55:06 +00:00
|
|
|
|
|
2022-05-11 22:47:31 +00:00
|
|
|
|
# bring things up, but only what we haven't already created
|
2023-02-25 12:52:42 +00:00
|
|
|
|
docker-compose up -d --remove-orphans --force-recreate --build npm npm-pebble npm-stepca npm-swagger
|
2020-02-19 04:55:06 +00:00
|
|
|
|
|
|
|
|
|
if [ "$1" == "-f" ]; then
|
|
|
|
|
echo -e "${BLUE}❯ ${YELLOW}Following Backend Container:${RESET}"
|
2023-02-25 12:52:42 +00:00
|
|
|
|
docker logs -f npm.dev
|
2020-02-19 04:55:06 +00:00
|
|
|
|
else
|
2022-05-11 22:47:31 +00:00
|
|
|
|
echo -e "${YELLOW}Tip:${RESET} You can follow the output of some of the containers with:"
|
2023-02-25 12:52:42 +00:00
|
|
|
|
echo " docker logs -f npm.dev"
|
2022-05-11 22:47:31 +00:00
|
|
|
|
echo -e "${YELLOW}Tip:${RESET} Open a database terminal with:"
|
|
|
|
|
echo " ./scripts/sqlite"
|
2020-02-19 04:55:06 +00:00
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo -e "${RED}❯ docker-compose command is not available${RESET}"
|
|
|
|
|
fi
|