Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (107 sloc) 4.94 KB
version: 2
jobs:
build:
docker:
- image: golang:alpine
working_directory: /go/src/github.com/danackerson/bender-slackbot
steps:
- checkout
- run:
name: "Fetch dependencies and build bender app"
command: |
apk add -U --no-cache curl build-base git libc6-compat
go get -t -d -v ./...
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build bender.go
- setup_remote_docker
- run:
name: "Install Docker CE"
command: |
VER="18.06.1"
curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-$VER-ce.tgz && tar --strip-components=1 -xvzf docker-$VER-ce.tgz -C /usr/local/bin
rm docker-$VER-ce.tgz
- run:
name: "Build, run, test & push docker image"
command: |
docker build --compress -t danackerson/bender:vc$CIRCLE_BUILD_NUM --build-arg vpnc_gateway=$VPNC_GATEWAY --build-arg vpnc_id=$VPNC_ID --build-arg vpnc_secret=$VPNC_SECRET --build-arg vpnc_username=$VPNC_USERNAME --build-arg vpnc_password=$VPNC_PASSWORD .
docker run -d -e slackToken=$(echo $slackTokenEncoded | base64 -d) -e raspberryPIIP=$raspberryPIIP -e slackReportChannel=$slackReportChannel -e piUser=$piUser -e piPass=$piPass -e digitalOceanToken=$digitalOceanToken --name bender danackerson/bender:vc$CIRCLE_BUILD_NUM
echo `docker logs bender`
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker tag danackerson/bender:vc$CIRCLE_BUILD_NUM danackerson/bender:latest
docker push danackerson/bender:vc$CIRCLE_BUILD_NUM
docker push danackerson/bender:latest
echo vc$CIRCLE_BUILD_NUM > last_docker_push
- persist_to_workspace:
root: /go/src/github.com/danackerson/bender-slackbot
paths:
- last_docker_push
deploy:
docker:
- image: alpine
steps:
- add-ssh-keys:
fingerprints:
- "93:c4:61:21:a6:82:d8:6d:4f:73:11:79:37:23:83:07"
- run:
name: Start ssh-agent
command: |
apk add -U jq curl openssh-client
ssh-agent -s > ~/.ssh_agent_conf
source ~/.ssh_agent_conf
for _k in $(ls ${HOME}/.ssh/id_*); do
ssh-add ${_k} || true
done
- run:
name: Disable Digital Ocean firewall for deploy
command: |
curl -s https://raw.githubusercontent.com/danackerson/digitalocean/master/utils/disableFW.sh | sh
- attach_workspace:
at: /tmp
- run:
name: "deploy to DigitalOcean Droplet"
command: |
source ~/.ssh_agent_conf
export DEPLOY_SERVER=deploy.ackerson.de
if [ $DEPLOY_SERVER_IP ]; then
export DEPLOY_SERVER=$DEPLOY_SERVER_IP
fi
echo "Deploy to $DEPLOY_SERVER"
export DEPLOY_CONNECT="ssh -o StrictHostKeyChecking=no ackersond@$DEPLOY_SERVER"
if [ -f /tmp/last_docker_push ]; then
export LAST_DOCKER_PUSH=`cat /tmp/last_docker_push`
else
export LAST_DOCKER_PUSH=latest
fi
$DEPLOY_CONNECT docker login -u $DOCKER_USER -p $DOCKER_PASS
$DEPLOY_CONNECT docker pull danackerson/bender:$LAST_DOCKER_PUSH
$DEPLOY_CONNECT docker rm -f bender || true
# not all Env vars are created equal - some have ':' or '{}' or <shudder> '\/'s
# in this case we base64 encode the parameter: `base64 <<< [string in question]`
# taking the result and pasting it into the environment variable of this CircleCI project
# above is an example how to decode this on the fly (e.g. slackToken)
$DEPLOY_CONNECT docker run -d --restart=always --privileged=true \
--volumes-from homepage -v /home/ackersond/algo_vpn:/algo_vpn:ro \
-e doFirewallID=$doFirewallID -e doFloatingIP=$doFloatingIP \
-e officeIP=$officeIP -e homeDomain=$homeDomain \
-e circleAPIToken=$CIRCLE_API_TOKEN -e raspberryPIIP=$raspberryPIIP \
-e slackReportChannel=$slackReportChannel -e piUser=$piUser -e piPass=$piPass \
-e digitalOceanToken=$digitalOceanToken -e CIRCLE_BUILD_NUM=$LAST_DOCKER_PUSH \
-e slackToken=$(echo $slackTokenEncoded | base64 -d) \
--name bender danackerson/bender:$LAST_DOCKER_PUSH
if [ $DEPLOY_SERVER_IP ]; then
$DEPLOY_CONNECT docker restart traefik
fi
- run:
name: Reenable Digital Ocean firewall
command: |
if [ -z $DEPLOY_SERVER_IP ]; then
curl -s https://raw.githubusercontent.com/danackerson/digitalocean/master/utils/reenableFW.sh | sh
fi
when: always
workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build