Repository navigation
Expand file tree
/
Copy pathdevspace.yaml
More file actions
198 lines (189 loc) · 6.6 KB
/
Copy pathdevspace.yaml
File metadata and controls
198 lines (189 loc) · 6.6 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
version: v2beta1
vars:
THREADS_NAMESPACE: platform
E2E_IMAGE: ghcr.io/agynio/devcontainer-go:1
functions:
threads_deployment: |-
# The release name varies by install: the umbrella chart names it
# threads-threads, a standalone install just threads. Resolve it by label
# rather than guessing.
kubectl get deployment -n ${THREADS_NAMESPACE} \
-l app.kubernetes.io/name=threads \
-o jsonpath='{.items[0].metadata.name}'
patch_deployment: |-
echo "Patching threads deployment for DevSpace..."
kubectl patch deployment "$(threads_deployment)" -n ${THREADS_NAMESPACE} --type strategic --patch "$(cat <<'EOF'
spec:
template:
spec:
securityContext:
runAsUser: 1000
fsGroup: 1000
initContainers: []
volumes:
- name: data
emptyDir: {}
containers:
- name: threads
image: ghcr.io/agynio/devcontainer-go:1 # keep in sync with E2E_IMAGE
workingDir: /opt/app/data
# All three go. The container generates and compiles before it
# listens, so liveness would restart it mid-build -- and devspace
# will not start syncing until the pod is ready, so a readiness
# probe on the port deadlocks: no source, so no listener, so never
# ready, so no sync. The dev pipeline waits on port 50051 itself
# once the sync is through.
livenessProbe: null
startupProbe: null
readinessProbe: null
command:
- sh
- -c
- |
set -eu
# devspace only starts syncing once the pod is up, and waits
# for it to be ready first -- so exiting here restarts the
# container and the sync never lands. Wait for the whole set
# generation needs, not just go.mod, or buf runs on a half
# synced tree.
elapsed=0
until [ -f /opt/app/data/go.mod ] \
&& [ -f /opt/app/data/go.sum ] \
&& [ -f /opt/app/data/buf.gen.yaml ] \
&& [ -f /opt/app/data/buf.yaml ]; do
sleep 1; elapsed=$((elapsed + 1))
if [ "$elapsed" -ge 600 ]; then
echo "ERROR: sync timeout waiting for source files" >&2
ls -la /opt/app/data >&2 || true
exit 1
fi
done
buf generate buf.build/agynio/api --path agynio/api/threads/v1 --path agynio/api/notifications/v1 --path agynio/api/identity/v1 --path agynio/api/metering/v1 --path agynio/api/authorization/v1 --path agynio/api/agents/v1
exec go run ./cmd/threads
volumeMounts:
- name: data
mountPath: /opt/app/data
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: "2"
memory: 4Gi
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
readOnlyRootFilesystem: false
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
EOF
)"
deployments:
e2e-runner:
namespace: ${THREADS_NAMESPACE}
helm:
chart:
name: component-chart
repo: https://charts.devspace.sh
values:
containers:
- image: ${E2E_IMAGE}
env:
- name: THREADS_ADDRESS
value: "threads:50051"
labels:
app.kubernetes.io/name: threads-e2e
commands:
test-e2e: |-
devspace run-pipeline test-e2e $@
pipelines:
dev:
flags:
- name: watch
short: w
description: "Keep DevSpace running and stream logs"
run: |-
patch_deployment
if [ "$(get_flag "watch")" == "true" ]; then
start_dev --disable-pod-replace threads
else
start_dev --disable-pod-replace threads
echo "Waiting for threads to be healthy on :50051..."
healthy=false
for i in $(seq 1 60); do
if exec_container --label-selector=app.kubernetes.io/name=threads -n ${THREADS_NAMESPACE} -- bash -c 'nc -z localhost 50051 >/dev/null 2>&1 || (echo > /dev/tcp/localhost/50051) >/dev/null 2>&1'; then
healthy=true
break
fi
sleep 2
done
if [ "$healthy" != "true" ]; then
echo "ERROR: Threads did not become healthy within 120s" >&2
exit 1
fi
echo "Dev environment ready. Stopping dev session."
stop_dev threads
fi
test-e2e:
run: |-
create_deployments e2e-runner
start_dev e2e-runner &
sleep 5
exec_container \
--label-selector "app.kubernetes.io/name=threads-e2e" \
-n ${THREADS_NAMESPACE} \
-- bash -c 'cd /opt/app/data && buf generate buf.build/agynio/api --path agynio/api/threads/v1 --path agynio/api/notifications/v1 --path agynio/api/identity/v1 --path agynio/api/metering/v1 --path agynio/api/authorization/v1 --path agynio/api/agents/v1 && go test -v -count=1 -tags e2e ./test/e2e/'
EXIT_CODE=$?
stop_dev e2e-runner
purge_deployments e2e-runner
exit $EXIT_CODE
hooks:
dev:
threads:
namespace: ${THREADS_NAMESPACE}
# Name only: the instance label is the Helm release, which is threads for a
# standalone install and agyn-platform under the umbrella chart.
labelSelector:
app.kubernetes.io/name: threads
containers:
threads:
container: threads
sync:
- path: ./:/opt/app/data
excludePaths:
- .git/
- .devspace/
- /.gen/
- /tmp/
uploadExcludePaths:
- .git/
- .devspace/
- /.gen/
- /tmp/
downloadExcludePaths:
- .git/
- .devspace/
- /.gen/
- /tmp/
logs:
enabled: true
lastLines: 200
ports:
- port: "50051"
e2e-runner:
namespace: ${THREADS_NAMESPACE}
labelSelector:
app.kubernetes.io/name: threads-e2e
command: ["sleep", "infinity"]
workingDir: /opt/app/data
sync:
- path: ./:/opt/app/data
excludePaths:
- .git/
- .devspace/
- /.gen/
- /tmp/