mirror of
https://github.com/yldio/copilot.git
synced 2024-11-10 21:30:06 +02:00
bin: handle creation of .env file in a nicer way
This commit is contained in:
parent
1960e62757
commit
7f054437c8
15
bin/deploy
15
bin/deploy
@ -1,4 +1,17 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
#
|
||||
# Prelude - make bash behave sanely
|
||||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
INCLUDE=$(dirname $(readlink -f $0))
|
||||
. $INCLUDE/setup_tools
|
||||
|
||||
ensure_command triton
|
||||
ensure_triton_cns_is_enabled
|
||||
write_env_file
|
||||
triton env
|
||||
|
||||
docker-compose build
|
||||
@ -8,7 +21,5 @@ export DOCKER_HOST=$_DOCKER_HOST
|
||||
export DOCKER_CERT_PATH=$_DOCKER_CERT_PATH
|
||||
export DOCKER_TLS_VERIFY=$_DOCKER_TLS_VERIFY
|
||||
|
||||
./bin/setup
|
||||
|
||||
docker-compose pull
|
||||
docker-compose up -d
|
||||
|
74
bin/setup
74
bin/setup
@ -1,82 +1,14 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
# setup.sh - Checks that all the required tools are present and that they are
|
||||
# appropriately configured for deploying to Triton.
|
||||
#
|
||||
# Adapted from https://github.com/autopilotpattern/mysql/blob/master/setup.sh
|
||||
#
|
||||
|
||||
#
|
||||
# Prelude
|
||||
#
|
||||
INCLUDE=$(dirname $(readlink -f $0))
|
||||
. $INCLUDE/setup_tools
|
||||
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
#
|
||||
# Utilities
|
||||
#
|
||||
die() {
|
||||
local msg="$@"
|
||||
[[ -z "${msg}" ]] || {
|
||||
echo
|
||||
tput setaf 1 # red
|
||||
tput bold
|
||||
echo "${msg}"
|
||||
tput sgr0 # reset
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# Check functions
|
||||
#
|
||||
ensure_command() {
|
||||
local cmd="$1"
|
||||
|
||||
command -v "${cmd}" > /dev/null 2>&1 || {
|
||||
die "Couldn't find required command: ${cmd}"
|
||||
}
|
||||
}
|
||||
|
||||
ensure_docker_config_matches_triton_config_and_capture_triton_details() {
|
||||
local docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}')
|
||||
local docker_dc=$(echo $DOCKER_HOST | awk -F"/" '{print $3}' | awk -F'.' '{print $1}')
|
||||
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_ACCOUNT=$(triton account get | awk -F": " '/id:/{print $2}')
|
||||
if [[ ! "$docker_user" = "$TRITON_USER" ]] || [[ ! "$docker_dc" = "$TRITON_DC" ]]; then
|
||||
echo "Docker user: ${docker_user}"
|
||||
echo "Triton user: ${TRITON_USER}"
|
||||
echo "Docker data center: ${docker_dc}"
|
||||
echo "Triton data center: ${TRITON_DC}"
|
||||
die "Your Triton configuration does not match your Docker configuration."
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_triton_cns_is_enabled() {
|
||||
local triton_cns_enabled=$(triton account get | awk -F": " '/cns/{print $2}')
|
||||
[[ "$triton_cns_enabled" == "true" ]] || {
|
||||
die "Triton CNS is required and not enabled."
|
||||
}
|
||||
}
|
||||
|
||||
write_env_file() {
|
||||
[[ -f .env ]] || {
|
||||
echo '# Consul discovery via Triton CNS' >> .env
|
||||
echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com >> .env
|
||||
echo SDC_KEY_ID=${SDC_KEY_ID} >> .env
|
||||
echo SDC_ACCOUNT=${SDC_ACCOUNT} >> .env
|
||||
echo SDC_URL=${SDC_URL} >> .env
|
||||
echo >> .env
|
||||
}
|
||||
}
|
||||
|
||||
ensure_prerequisites() {
|
||||
ensure_command docker
|
||||
ensure_command docker-compose
|
||||
ensure_command triton
|
||||
}
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
|
82
bin/setup_tools
Normal file
82
bin/setup_tools
Normal file
@ -0,0 +1,82 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
# setup.sh - Checks that all the required tools are present and that they are
|
||||
# appropriately configured for deploying to Triton.
|
||||
#
|
||||
# Adapted from https://github.com/autopilotpattern/mysql/blob/master/setup.sh
|
||||
#
|
||||
|
||||
#
|
||||
# Prelude
|
||||
#
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
#
|
||||
# Utilities
|
||||
#
|
||||
die() {
|
||||
local msg="$@"
|
||||
[[ -z "${msg}" ]] || {
|
||||
echo
|
||||
tput setaf 1 # red
|
||||
tput bold
|
||||
echo "${msg}"
|
||||
tput sgr0 # reset
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# Check functions
|
||||
#
|
||||
ensure_command() {
|
||||
local cmd="$1"
|
||||
|
||||
command -v "${cmd}" > /dev/null 2>&1 || {
|
||||
die "Couldn't find required command: ${cmd}"
|
||||
}
|
||||
}
|
||||
export -f ensure_command
|
||||
|
||||
ensure_docker_config_matches_triton_config_and_capture_triton_details() {
|
||||
local docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}')
|
||||
local docker_dc=$(echo $DOCKER_HOST | awk -F"/" '{print $3}' | awk -F'.' '{print $1}')
|
||||
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_ACCOUNT=$(triton account get | awk -F": " '/id:/{print $2}')
|
||||
if [[ ! "$docker_user" = "$TRITON_USER" ]] || [[ ! "$docker_dc" = "$TRITON_DC" ]]; then
|
||||
echo "Docker user: ${docker_user}"
|
||||
echo "Triton user: ${TRITON_USER}"
|
||||
echo "Docker data center: ${docker_dc}"
|
||||
echo "Triton data center: ${TRITON_DC}"
|
||||
die "Your Triton configuration does not match your Docker configuration."
|
||||
fi
|
||||
}
|
||||
export -f ensure_docker_config_matches_triton_config_and_capture_triton_details
|
||||
|
||||
ensure_triton_cns_is_enabled() {
|
||||
local triton_cns_enabled=$(triton account get | awk -F": " '/cns/{print $2}')
|
||||
[[ "$triton_cns_enabled" == "true" ]] || {
|
||||
die "Triton CNS is required and not enabled."
|
||||
}
|
||||
}
|
||||
export -f ensure_triton_cns_is_enabled
|
||||
|
||||
write_env_file() {
|
||||
[[ -f .env ]] || {
|
||||
echo '# Consul discovery via Triton CNS' >> .env
|
||||
echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com >> .env
|
||||
echo SDC_KEY_ID=${SDC_KEY_ID} >> .env
|
||||
echo SDC_ACCOUNT=${SDC_ACCOUNT} >> .env
|
||||
echo SDC_URL=${SDC_URL} >> .env
|
||||
echo >> .env
|
||||
}
|
||||
}
|
||||
export -f write_env_file
|
||||
|
||||
ensure_prerequisites() {
|
||||
ensure_command docker
|
||||
ensure_command docker-compose
|
||||
ensure_command triton
|
||||
}
|
Loading…
Reference in New Issue
Block a user