-
Notifications
You must be signed in to change notification settings - Fork 5
/
dandelion.yaml
173 lines (172 loc) · 4.58 KB
/
dandelion.yaml
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
kind: Namespace
apiVersion: v1
metadata:
name: dandelion
labels:
name: dandelion
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dandelion-deployment
namespace: dandelion
spec:
replicas: 1
selector:
matchLabels:
app: dandelion
template:
metadata:
labels:
app: dandelion
spec:
volumes:
- name: release
emptyDir: {}
- name: scripts
configMap:
name: dandelion-scripts-configmap
defaultMode: 0555 # +r, +x
# initContainers run first and must terminate without error for the rest to boot
initContainers:
- name: dandelion-bootstrap
image: erlang:25.0.2
env:
- name: AWS_REGION
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: aws_region
- name: BUCKET_NAME
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: bucket_name
- name: RELEASE
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: release
volumeMounts:
- name: release
mountPath: /release
- name: scripts
mountPath: /scripts
command:
- /scripts/init-latest.sh
# Regular containers run next
containers:
- name: dandelion-release
image: erlang:25.0.2
env:
- name: RELEASE
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: release
volumeMounts:
- name: release
mountPath: /release
- name: scripts
mountPath: /scripts
command:
- /scripts/boot-release.sh
ports:
- containerPort: 8080
hostPort: 8080
- name: dandelion-sidecar
image: erlang:25.0.2
env:
- name: AWS_REGION
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: aws_region
- name: BUCKET_NAME
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: bucket_name
- name: RELEASE
valueFrom:
configMapKeyRef:
name: dandelion-env-configmap
key: release
volumeMounts:
- name: release
mountPath: /release
- name: scripts
mountPath: /scripts
command:
- /scripts/update-loop.sh
---
apiVersion: v1
kind: ConfigMap
metadata:
name: dandelion-env-configmap
namespace: dandelion
data:
bucket_name: ferd-dandelion
aws_region: us-east-1
release: dandelion
---
apiVersion: v1
kind: ConfigMap
metadata:
name: dandelion-scripts-configmap
namespace: dandelion
data:
init-latest.sh: |
#!/usr/bin/env bash
set -euxo pipefail
RELDIR=${1:-/release}
S3_URL="https://${BUCKET_NAME}.s3.${AWS_REGION}.amazonaws.com"
TAG=$(curl "${S3_URL}/${RELEASE}-latest" -s)
wget -nv "${S3_URL}/${RELEASE}-${TAG}.tar.gz" -O "/tmp/${RELEASE}-${TAG}.tar.gz"
tar -xvf "/tmp/${RELEASE}-${TAG}.tar.gz" -C ${RELDIR}
rm "/tmp/${RELEASE}-${TAG}.tar.gz"
boot-release.sh: |
#!/usr/bin/env bash
set -euxo pipefail
RELDIR=${1:-/release}
exec ${RELDIR}/bin/${RELEASE} foreground
update-loop.sh: |
#!/usr/bin/env bash
set -euxo pipefail
SLEEP=${1:-60}
RELDIR=${2:-/release}
S3_URL="https://${BUCKET_NAME}.s3.${AWS_REGION}.amazonaws.com"
while true
do
sleep ${SLEEP}
# check if we're up
${RELDIR}/bin/${RELEASE} status
# Get the running version
CURRENT=$(${RELDIR}/bin/${RELEASE} versions | awk '$3=="permanent" && !vsn { vsn=$2 } $3=="current" { vsn=$2 } END { print vsn }')
TAG=$(curl "${S3_URL}/${RELEASE}-latest" -s)
if [[ "${CURRENT}" != "${TAG}" ]]; then
IS_UPGRADE=$(echo "$TAG $CURRENT" | awk -vFS='[. ]' '($1==$4 && $2>$5) || ($1==$4 && $2>=$5 && $3>$6) {print 1; exit} {print 0}')
if [[ $IS_UPGRADE -eq 1 ]]; then
wget -nv "${S3_URL}/${RELEASE}-${TAG}.tar.gz" -O "${RELDIR}/releases/${RELEASE}-${TAG}.tar.gz"
${RELDIR}/bin/${RELEASE} unpack ${TAG}
${RELDIR}/bin/${RELEASE} install ${TAG}
${RELDIR}/bin/${RELEASE} upgrade ${TAG}
fi
fi
done
---
apiVersion: v1
kind: Service
metadata:
name: dandelion-service
namespace: dandelion
labels:
app: dandelion
spec:
type: LoadBalancer
ports:
- port: 8080
targetPort: 8080
protocol: TCP
selector:
app: dandelion