chore: initial circleci config
This commit is contained in:
parent
b665dec740
commit
c7567f3838
30
bin/deploy
Executable file
30
bin/deploy
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Prelude - make bash behave sanely
|
||||||
|
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Beware of CDPATH gotchas causing cd not to work correctly when a user
|
||||||
|
# has set this in their environment
|
||||||
|
# https://bosker.wordpress.com/2012/02/12/bash-scripters-beware-of-the-cdpath/
|
||||||
|
unset CDPATH
|
||||||
|
|
||||||
|
readonly INCLUDE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
# shellcheck source=bin/setup-tools
|
||||||
|
. "${INCLUDE}"/setup-tools
|
||||||
|
|
||||||
|
echo ">> running triton deploy with docker-compose"
|
||||||
|
ensure_command triton
|
||||||
|
ensure_triton_cns_is_enabled
|
||||||
|
get_triton_details
|
||||||
|
write_env_file
|
||||||
|
|
||||||
|
export DOCKER_HOST=$_DOCKER_HOST
|
||||||
|
export DOCKER_CERT_PATH=$_DOCKER_CERT_PATH
|
||||||
|
# Do not TLS verify for now, incompatibilities between circleci and joyent
|
||||||
|
export DOCKER_TLS_VERIFY=
|
||||||
|
|
||||||
|
docker-compose pull
|
||||||
|
COMPOSE_PROJECT_NAME=${CIRCLE_BRANCH} docker-compose up -d
|
10
bin/docker-login
Executable file
10
bin/docker-login
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Prelude - make bash behave sanely
|
||||||
|
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo ">> Logging into $_DOCKER_REGISTRY"
|
||||||
|
docker login -e="." -u="$_DOCKER_LOGIN_USERNAME" -p="$_DOCKER_LOGIN_PASSWORD" "$_DOCKER_REGISTRY"
|
23
bin/setup
Executable file
23
bin/setup
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Prelude
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
# Beware of CDPATH gotchas causing cd not to work correctly when a user
|
||||||
|
# has set this in their environment
|
||||||
|
# https://bosker.wordpress.com/2012/02/12/bash-scripters-beware-of-the-cdpath/
|
||||||
|
unset CDPATH
|
||||||
|
|
||||||
|
readonly INCLUDE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
# shellcheck source=bin/setup-tools
|
||||||
|
. "${INCLUDE}"/setup-tools
|
||||||
|
|
||||||
|
#
|
||||||
|
# Main
|
||||||
|
#
|
||||||
|
ensure_prerequisites
|
||||||
|
get_triton_details
|
||||||
|
check_docker_config
|
||||||
|
write_env_file
|
105
bin/setup-tools
Executable file
105
bin/setup-tools
Executable file
@ -0,0 +1,105 @@
|
|||||||
|
#! /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}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get_triton_details() {
|
||||||
|
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_URL=$(triton profile get | awk -F' ' '/url:/{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
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_docker_config_matches_triton_config_and_capture_triton_details() {
|
||||||
|
local docker_user
|
||||||
|
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
|
||||||
|
[[ ! "$docker_user" = "$TRITON_USER" ]] || [[ ! "$docker_dc" = "$TRITON_DC" ]] && {
|
||||||
|
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 config does not match your Docker configuration."
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_triton_cns_is_enabled() {
|
||||||
|
local triton_cns_enabled
|
||||||
|
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() {
|
||||||
|
if [[ -f .env ]] ; then
|
||||||
|
echo "Env file already exists, not overwriting"
|
||||||
|
else
|
||||||
|
echo '# Consul discovery via Triton CNS' >> .env
|
||||||
|
[[ "${DOCKER_HOST:=unset}" == "*docker.joyent.com*" ]] || {
|
||||||
|
echo CONSUL="consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com" \
|
||||||
|
>> .env
|
||||||
|
}
|
||||||
|
echo SDC_KEY_ID=${TRITON_KEY} >> .env
|
||||||
|
echo SDC_ACCOUNT=${TRITON_ACCOUNT} >> .env
|
||||||
|
echo SDC_URL=${TRITON_URL} >> .env
|
||||||
|
echo >> .env
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_prerequisites() {
|
||||||
|
ensure_command docker
|
||||||
|
ensure_command docker-compose
|
||||||
|
ensure_command triton
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim: syntax=sh et ts=2 sts=2 sw=2
|
49
circle.yml
Normal file
49
circle.yml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# Customize the test machine
|
||||||
|
machine:
|
||||||
|
pre:
|
||||||
|
- git config --global user.email "circleci@joyent.zone"
|
||||||
|
- git config --global user.name "circlebot"
|
||||||
|
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
node:
|
||||||
|
version: 7.7.3
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
pre:
|
||||||
|
# install docker-compose
|
||||||
|
- sudo curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
|
||||||
|
- sudo chmod +x /usr/local/bin/docker-compose
|
||||||
|
# install and setup triton
|
||||||
|
- yarn global add triton@4.15.0 || cat /home/ubuntu/.yarn-config/global/yarn-error.log
|
||||||
|
- echo '{"url":"https://eu-ams-1.api.joyent.com","account":"'$SDC_ACCOUNT'","keyId":"c3:30:35:9b:85:48:73:44:31:cc:4b:2e:6a:00:16:e2","name":"eu-ams-1","curr":true}' | triton profile create -f -
|
||||||
|
- triton env --docker eu-ams-1
|
||||||
|
# setup tap report
|
||||||
|
- mkdir -p ${CIRCLE_TEST_REPORTS}/tap-xunit/
|
||||||
|
override:
|
||||||
|
# install dependencies
|
||||||
|
- yarn install --prefer-offline
|
||||||
|
|
||||||
|
test:
|
||||||
|
override:
|
||||||
|
# lint
|
||||||
|
- yarn run lint
|
||||||
|
# test
|
||||||
|
- yarn run test
|
||||||
|
|
||||||
|
# deployment:
|
||||||
|
# development:
|
||||||
|
# branch: master
|
||||||
|
# commands:
|
||||||
|
# - ./bin/docker-login
|
||||||
|
# - make -j2 build
|
||||||
|
# - make -j2 push
|
||||||
|
# - ./bin/deploy
|
||||||
|
# production:
|
||||||
|
# tag: /production-*/
|
||||||
|
# commands:
|
||||||
|
# - CIRCLE_BRANCH=staging ./bin/docker-login
|
||||||
|
# - CIRCLE_BRANCH=staging ./bin/on-changes-publish-ui
|
||||||
|
# - CIRCLE_BRANCH=staging make -j2 build
|
||||||
|
# - CIRCLE_BRANCH=staging make -j2 push
|
||||||
|
# - CIRCLE_BRANCH=staging ./bin/deploy
|
Loading…
Reference in New Issue
Block a user