Permalink
3c9da0e Jul 15, 2016
2 contributors

Users who have contributed to this file

@VojtechVitek @stengaard
147 lines (121 sloc) 3.16 KB
# Supfile for "Example" Docker service
---
version: 0.4
env:
# Environment variables for all commands
NAME: example
REPO: github.com/pressly/sup
BRANCH: master
IMAGE: pressly/example
HOST_PORT: 8000
CONTAINER_PORT: 8000
networks:
# Groups of hosts
local:
hosts:
- localhost
dev:
env:
# Extra environment variable for dev hosts only
DOCKER_HOST: tcp://127.0.0.1:2375
hosts:
- docker@192.168.59.103
stg:
hosts:
- ubuntu@stg.example.com
prod:
inventory: for i in 1 2 3 4; do echo "ubuntu@prod$i.example.com"; done
commands:
# Named set of commands to be run remotely
ping:
desc: Print uname and current date/time.
run: uname -a; date
pre-build:
desc: Initialize directory
run: mkdir -p /tmp/$IMAGE
mytest:
run: echo $SUP_TIME
build:
desc: Build Docker image from current directory, push to Docker Hub
# local: sup $SUP_ENV -f ./builder/Supfile $SUP_NETWORK build
upload:
- src: ./
dst: /tmp/$IMAGE
script: ./scripts/docker-build.sh
once: true
pull:
desc: Pull latest Docker image
run: sudo docker pull $IMAGE
config:
desc: Upload/test config file.
upload:
- src: ./example.$SUP_NETWORK.cfg
dst: /tmp/
run: test -f /tmp/example.$SUP_NETWORK.cfg
stop:
desc: Stop Docker container
run: sudo docker stop $NAME || exit 0
rm:
desc: Remove Docker container
run: sudo docker rm $NAME || exit 0
start:
desc: Start a stopped Docker container
run: sudo docker start $NAME || exit 0
run:
desc: Run Docker container
run: >
sudo docker run -d \
-p $HOST_PORT:$CONTAINER_PORT \
-v /tmp/example.$SUP_NETWORK.cfg:/etc/example.cfg \
--restart=always \
--name $NAME $IMAGE
restart:
desc: Restart Docker container
run: sudo docker restart $NAME || exit 0
stop-rm-run:
desc: Rolling update (stop & remove old Docker container, run new one)
run: >
sudo docker stop $NAME || :; \
sudo docker rm $NAME || :; \
sudo docker run -d \
-p $HOST_PORT:$CONTAINER_PORT \
-v /tmp/example.$SUP_NETWORK.cfg:/etc/example.cfg \
--restart=always \
--name $NAME $IMAGE
serial: 1
ps:
desc: List running Docker containers
run: sudo docker ps | grep $NAME
logs:
desc: Docker logs
run: sudo docker logs $NAME
tail-logs:
desc: Tail Docker logs
run: sudo docker logs --tail=20 -f $NAME
health:
desc: Application health check
run: curl localhost:$HOST_PORT
slack-notify:
desc: Notify Slack about new deployment
local: >
curl -X POST --data-urlencode 'payload={"channel": "#_team_", "text": "['$SUP_NETWORK'] '$SUP_USER' deployed '$NAME'"}' \
https://hooks.slack.com/services/X/Y/Z
bash:
desc: Interactive shell on all hosts
stdin: true
run: bash
exec:
desc: Interactive docker exec on all hosts
stdin: true
run: sudo docker exec -i $NAME bash
targets: # Aliases to run multiple commands at once
deploy:
- pre-build
- build
- pull
- config
- stop-rm-run
- ps
- logs
- health
- slack-notify