-
Notifications
You must be signed in to change notification settings - Fork 178
/
Supfile
149 lines (123 loc) · 3.32 KB
/
Supfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 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:
stg:
hosts:
prod:
inventory: for i in 1 2 3 4; do echo "ubuntu@prod$i.example.com"; done
k8s:
inventory: for i in $(kubectl get nodes -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].address}); do echo "ubuntu@$i"; 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