1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 14:10:04 +02:00

Make running the stack work locally (#55)

* Do not check triton config for local setup

* Log how to run stack locally

- If docker is unconfigured (default)

* Remove exports from setup-tools

- Don't pollute the environment with these functions.  This file is
sourced so they will still be available

* Fix linting errors and make code style consistent

* Fix docker check when DOCKER_HOST is set

* Make setup work whe triton env vars are not set

* Document setup step
This commit is contained in:
Raoul Millais 2016-11-01 12:13:47 +00:00 committed by Tom Gallacher
parent c2fca68f45
commit fa841e0cee
3 changed files with 43 additions and 20 deletions

View File

@ -1,5 +1,10 @@
# Joyent Dashboard # Joyent Dashboard
## Setup
```sh
./bin/setup
```
## Installation ## Installation
To run the stack locally: To run the stack locally:

View File

@ -18,6 +18,6 @@ readonly INCLUDE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Main # Main
# #
ensure_prerequisites ensure_prerequisites
ensure_docker_config_matches_triton_config_and_capture_triton_details get_triton_details
ensure_triton_cns_is_enabled check_docker_config
write_env_file write_env_file

View File

@ -16,7 +16,7 @@ IFS=$'\n\t'
# Utilities # Utilities
# #
die() { die() {
local msg="$@" local msg="$*"
[[ -z "${msg}" ]] || { [[ -z "${msg}" ]] || {
echo echo
tput setaf 1 # red tput setaf 1 # red
@ -37,51 +37,69 @@ ensure_command() {
die "Couldn't find required command: ${cmd}" die "Couldn't find required command: ${cmd}"
} }
} }
export -f ensure_command
get_triton_details() { get_triton_details() {
TRITON_USER=$(triton profile get | awk -F": " '/account:/{print $2}') TRITON_USER=$(triton profile get | awk -F": " '/account:/{print $2}')
TRITON_DC=$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}') TRITON_DC=$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}')
TRITON_URL=$(triton profile get | awk -F' ' '/url:/{print $2}')
TRITON_ACCOUNT=$(triton account get | awk -F": " '/id:/{print $2}') TRITON_ACCOUNT=$(triton account get | awk -F": " '/id:/{print $2}')
TRITON_KEY=$(triton profile get | awk -F' ' '/keyId:/{print $2}')
}
check_docker_config() {
[[ "${DOCKER_HOST:=unset}" == "unset" ]] && {
echo "Run \"docker-compose -f local-compose.yml\" up to run locally"
return 0
}
return 0
} }
export -f get_triton_details
ensure_docker_config_matches_triton_config_and_capture_triton_details() { ensure_docker_config_matches_triton_config_and_capture_triton_details() {
local docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}') local docker_user
local docker_dc=$(echo $DOCKER_HOST | awk -F"/" '{print $3}' | awk -F'.' '{print $1}') docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}')
local docker_dc
docker_dc="$(echo "${DOCKER_HOST}" | awk -F"/" '{print $3}' | awk -F'.' '{print $1}')"
get_triton_details get_triton_details
if [[ ! "$docker_user" = "$TRITON_USER" ]] || [[ ! "$docker_dc" = "$TRITON_DC" ]]; then [[ ! "$docker_user" = "$TRITON_USER" ]] || [[ ! "$docker_dc" = "$TRITON_DC" ]] && {
echo "Docker user: ${docker_user}" echo "Docker user: ${docker_user}"
echo "Triton user: ${TRITON_USER}" echo "Triton user: ${TRITON_USER}"
echo "Docker data center: ${docker_dc}" echo "Docker data center: ${docker_dc}"
echo "Triton data center: ${TRITON_DC}" echo "Triton data center: ${TRITON_DC}"
die "Your Triton configuration does not match your Docker configuration." die "Your Triton config does not match your Docker configuration."
fi }
return 0;
} }
export -f ensure_docker_config_matches_triton_config_and_capture_triton_details
ensure_triton_cns_is_enabled() { ensure_triton_cns_is_enabled() {
local triton_cns_enabled=$(triton account get | awk -F": " '/cns/{print $2}') local triton_cns_enabled
triton_cns_enabled=$(triton account get | awk -F": " '/cns/{print $2}')
[[ "$triton_cns_enabled" == "true" ]] || { [[ "$triton_cns_enabled" == "true" ]] || {
die "Triton CNS is required and not enabled." die "Triton CNS is required and not enabled."
} }
} }
export -f ensure_triton_cns_is_enabled
write_env_file() { write_env_file() {
[[ -f .env ]] || { if [[ -f .env ]] ; then
echo "Env file already exists, not overwriting"
else
echo '# Consul discovery via Triton CNS' >> .env echo '# Consul discovery via Triton CNS' >> .env
echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com >> .env [[ "${DOCKER_HOST:=unset}" == "*docker.joyent.com*" ]] || {
echo SDC_KEY_ID=${SDC_KEY_ID} >> .env echo CONSUL="consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com" \
echo SDC_ACCOUNT=${SDC_ACCOUNT} >> .env >> .env
echo SDC_URL=${SDC_URL} >> .env }
echo SDC_KEY_ID=${TRITON_KEY} >> .env
echo SDC_ACCOUNT=${TRITON_ACCOUNT} >> .env
echo SDC_URL=${TRITON_URL} >> .env
echo >> .env echo >> .env
fi
} }
}
export -f write_env_file
ensure_prerequisites() { ensure_prerequisites() {
ensure_command docker ensure_command docker
ensure_command docker-compose ensure_command docker-compose
ensure_command triton ensure_command triton
} }
# vim: syntax=sh et ts=2 sts=2 sw=2