-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevspace.yaml
More file actions
180 lines (176 loc) · 6.5 KB
/
Copy pathdevspace.yaml
File metadata and controls
180 lines (176 loc) · 6.5 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
version: v2beta1
vars:
ORGANIZATIONS_NAMESPACE: platform
functions:
disable_argocd_sync: |-
if kubectl get application organizations -n argocd >/dev/null 2>&1; then
echo "Disabling ArgoCD auto-sync for organizations..."
kubectl patch application organizations -n argocd \
--type merge \
-p '{"spec":{"syncPolicy":{"automated":null}}}'
echo "ArgoCD auto-sync disabled."
else
echo "WARNING: ArgoCD Application 'organizations' not found in argocd namespace."
fi
restore_argocd_sync: &restore_argocd_sync |-
if kubectl get application organizations -n argocd >/dev/null 2>&1; then
echo "Re-enabling ArgoCD auto-sync for organizations..."
kubectl patch application organizations -n argocd \
--type merge \
-p '{"spec":{"syncPolicy":{"automated":{"prune":true,"selfHeal":true}}}}'
echo "ArgoCD auto-sync restored."
else
echo "WARNING: ArgoCD Application 'organizations' not found in argocd namespace."
fi
patch_deployment: |-
echo "Patching organizations deployment for DevSpace..."
kubectl patch deployment organizations -n ${ORGANIZATIONS_NAMESPACE} --type strategic --patch "$(cat <<'EOF'
spec:
template:
spec:
securityContext:
runAsUser: 1000
fsGroup: 1000
initContainers: []
volumes:
- name: data
emptyDir: {}
containers:
- name: organizations
image: ghcr.io/agynio/devcontainer-go:1
workingDir: /opt/app/data
command:
- sh
- -c
- |
set -eu
echo "Organizations DevSpace container ready."
tail -f /dev/null
volumeMounts:
- name: data
mountPath: /opt/app/data
livenessProbe: null
readinessProbe: null
startupProbe: null
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
)"
pipelines:
dev:
flags:
- name: watch
short: w
description: "Keep DevSpace running and stream logs"
run: |-
disable_argocd_sync
patch_deployment
if [ "$(get_flag "watch")" == "true" ]; then
start_dev --disable-pod-replace organizations
else
start_dev --disable-pod-replace organizations
echo "Starting organizations service from synced source..."
set +e
exec_container --label-selector=app.kubernetes.io/name=organizations -n ${ORGANIZATIONS_NAMESPACE} -- bash -lc 'set -euo pipefail
cd /opt/app/data
elapsed=0
while [ ! -f go.mod ] || [ ! -f buf.gen.yaml ] || [ ! -f cmd/organizations-service/main.go ]; do
sleep 1
elapsed=$((elapsed + 1))
[ "$elapsed" -ge 300 ] && { echo "ERROR: sync timeout waiting for source files" >&2; ls -la >&2; exit 1; }
done
echo "Files synced, generating protobuf types..."
buf generate buf.build/agynio/api --path agynio/api/authorization/v1 --path agynio/api/identity/v1 --path agynio/api/organizations/v1 --path agynio/api/users/v1
echo "buf generate complete, starting organizations..."
export GOTOOLCHAIN=local
if [ -x /usr/local/go/bin/go ]; then
GO_BIN=/usr/local/go/bin/go
elif command -v go >/dev/null 2>&1; then
GO_BIN=$(command -v go)
else
echo "ERROR: go binary not found" >&2
find /usr/local /root /home /go -path "*/bin/go" -type f 2>/dev/null >&2 || true
exit 1
fi
echo "Using go: ${GO_BIN}"
nohup "${GO_BIN}" run ./cmd/organizations-service >/tmp/organizations-service.log 2>&1 &
'
start_status=$?
set -e
if [ "$start_status" -ne 0 ]; then
kubectl logs -n ${ORGANIZATIONS_NAMESPACE} -l app.kubernetes.io/name=organizations --tail=200 >&2 || true
exec_container --label-selector=app.kubernetes.io/name=organizations -n ${ORGANIZATIONS_NAMESPACE} -- bash -lc 'cat /tmp/organizations-service.log >&2' || true
echo "ERROR: Failed to start organizations service from synced source" >&2
exit "$start_status"
fi
echo "Waiting for organizations to be healthy on :50051..."
healthy=false
for i in $(seq 1 150); do
if exec_container --label-selector=app.kubernetes.io/name=organizations -n ${ORGANIZATIONS_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
kubectl logs -n ${ORGANIZATIONS_NAMESPACE} -l app.kubernetes.io/name=organizations --tail=200 >&2 || true
exec_container --label-selector=app.kubernetes.io/name=organizations -n ${ORGANIZATIONS_NAMESPACE} -- bash -lc 'cat /tmp/organizations-service.log >&2' || true
echo "ERROR: Organizations did not become healthy within 300s" >&2
exit 1
fi
echo "Dev environment ready. Stopping dev session."
stop_dev organizations
fi
hooks:
- name: restore-argocd-auto-sync
events:
- after:dev:organizations
command: bash
args:
- -c
- *restore_argocd_sync
dev:
organizations:
namespace: ${ORGANIZATIONS_NAMESPACE}
labelSelector:
app.kubernetes.io/name: organizations
containers:
organizations:
container: organizations
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"