Skip to content

Commit f809d7b

Browse files
committed
refactor(bind9): git-ops to contain init cont
ref: #21
1 parent af6a9b4 commit f809d7b

3 files changed

Lines changed: 154 additions & 43 deletions

File tree

manifests/bind9/base/Deployment.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,10 @@ spec:
6767
name: data
6868
subPath: logs
6969

70-
- mountPath: /root
71-
name: home
72-
7370
priorityClassName: cluster-low
7471
tolerations: []
7572
volumes:
7673

7774
- name: data
7875
persistentVolumeClaim:
7976
claimName: bind
80-
81-
- name: home
82-
emptyDir:
83-
medium: Memory

manifests/bind9/components/git-ops/Deployment.yaml

Lines changed: 153 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,116 @@ spec:
1717
- sh
1818
- -c
1919
- |
20+
echo "Installing pre-reqs.....";
21+
22+
apk update;
23+
apk add git openssh-client-default;
24+
25+
export KEY_FILE_PATH=~/.ssh/${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME};
26+
27+
chmod 600 ${KEY_FILE_PATH}/deploy;
28+
29+
export GIT_SSH_COMMAND="ssh -i $KEY_FILE_PATH/deploy";
30+
31+
while :; do
32+
33+
echo "Loop Start......";
34+
35+
36+
cd /git;
37+
38+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
39+
40+
echo "********************************************";
41+
42+
git status;
43+
44+
echo "********************************************";
45+
46+
echo "Checking for repo updates";
47+
48+
git fetch -fpvt;
49+
50+
echo "Git reset....";
51+
52+
git reset --hard;
53+
54+
echo "Pulling any changes....";
55+
56+
git pull --rebase
57+
58+
else
59+
60+
echo "Not Authenticated, check ssh key. RC=[${?}]";
61+
62+
fi
63+
64+
65+
66+
echo "Loop Finish.";
67+
68+
sleep 300
69+
70+
done;
71+
72+
env:
73+
- name: SSH_PRIVATE_KEY
74+
valueFrom:
75+
secretKeyRef:
76+
name: bind-config
77+
key: SSH_PRIVATE_KEY
78+
- name: SSH_REPOSITORY_HOST
79+
valueFrom:
80+
secretKeyRef:
81+
name: bind-config
82+
key: SSH_REPOSITORY_HOST
83+
- name: SSH_REPOSITORY_OWNER
84+
valueFrom:
85+
secretKeyRef:
86+
name: bind-config
87+
key: SSH_REPOSITORY_OWNER
88+
- name: SSH_REPOSITORY_NAME
89+
valueFrom:
90+
secretKeyRef:
91+
name: bind-config
92+
key: SSH_REPOSITORY_NAME
93+
- name: SSH_REPOSITORY_REF
94+
valueFrom:
95+
secretKeyRef:
96+
name: bind-config
97+
key: SSH_REPOSITORY_REF
98+
99+
resources:
100+
limits:
101+
cpu: 1
102+
memory: 500Mi
103+
requests:
104+
cpu: 50m
105+
memory: 150Mi
106+
volumeMounts:
107+
- name: data
108+
mountPath: /git
109+
subPath: git/
110+
111+
- name: data
112+
mountPath: /root
113+
subPath: home
114+
115+
- mountPath: /var/dns-log
116+
name: data
117+
subPath: logs
118+
119+
initContainers:
120+
121+
- name: clone
122+
image: alpine:3.23.2
123+
command:
124+
- sh
125+
- -c
126+
- |
127+
echo "Start init";
128+
129+
20130
echo "Installing pre-reqs.....";
21131
22132
apk update;
@@ -28,71 +138,73 @@ spec:
28138
29139
echo "Env var KEY_FILE_PATH=[${KEY_FILE_PATH}] setup";
30140
31-
cat > ${KEY_FILE_PATH}/deploy <<EOF
32-
$SSH_PRIVATE_KEY
33-
EOF
141+
echo "$SSH_PRIVATE_KEY" > ${KEY_FILE_PATH}/deploy
142+
34143
35144
chmod 600 ${KEY_FILE_PATH}/deploy;
36145
37146
export GIT_SSH_COMMAND="ssh -i $KEY_FILE_PATH/deploy";
38147
39148
ssh-keyscan "${SSH_REPOSITORY_HOST}" >> ~/.ssh/known_hosts
40149
41-
while :; do
42150
43-
echo "Loop Start......";
151+
export REPO_NAME_FULL="${SSH_REPOSITORY_HOST}:${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME}.git"
152+
153+
echo "Env var REPO_NAME_FULL=[${REPO_NAME_FULL}] setup";
44154
45-
if [ ! -d /git/source/.git ]; then
46155
47-
export REPO_NAME_FULL="${SSH_REPOSITORY_HOST}:${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME}.git"
156+
if [ ! -d /git/.git ]; then
48157
49-
echo "Env var REPO_NAME_FULL=[${REPO_NAME_FULL}] setup";
50158
51-
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
159+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
52160
53-
echo "Clonning repo";
161+
echo "Clonning repo on branch=[${SSH_REPOSITORY_REF}]";
54162
55-
git clone -b master git@${REPO_NAME_FULL} /git/source;
163+
git clone -b "${SSH_REPOSITORY_REF}" git@${REPO_NAME_FULL} /git;
56164
57-
else
165+
else
58166
59-
echo "Not Authenticated, check ssh key. RC=[${?}]";
167+
echo "Not Authenticated, check ssh key. RC=[${?}]";
60168
61-
fi
169+
exit 1;
170+
171+
fi
172+
173+
else
62174
63-
else
64175
65-
cd /git/source;
176+
cd /git;
66177
67-
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
178+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
68179
69-
echo "********************************************";
180+
echo "********************************************";
70181
71-
git status;
182+
git status;
72183
73-
echo "********************************************";
74-
75-
echo "Checking for repo updates";
184+
echo "********************************************";
185+
186+
echo "Checking for repo updates";
76187
77-
git fetch -fpvt;
188+
git fetch -fpvt;
78189
79-
echo "Pulling any changes....";
190+
echo "Git reset....";
80191
81-
git pull --rebase
192+
git reset --hard;
82193
83-
else
194+
echo "Pulling any changes....";
84195
85-
echo "Not Authenticated, check ssh key. RC=[${?}]";
196+
git pull --rebase
86197
87-
fi
198+
else
199+
200+
echo "Not Authenticated, check ssh key. RC=[${?}]";
88201
89202
fi
90203
91-
echo "Loop Finish.";
92204
93-
sleep 300
205+
fi
94206
95-
done;
207+
echo "Finish init";
96208
97209
env:
98210
- name: SSH_PRIVATE_KEY
@@ -115,6 +227,11 @@ spec:
115227
secretKeyRef:
116228
name: bind-config
117229
key: SSH_REPOSITORY_NAME
230+
- name: SSH_REPOSITORY_REF
231+
valueFrom:
232+
secretKeyRef:
233+
name: bind-config
234+
key: SSH_REPOSITORY_REF
118235

119236
resources:
120237
limits:
@@ -123,11 +240,12 @@ spec:
123240
requests:
124241
cpu: 50m
125242
memory: 150Mi
243+
126244
volumeMounts:
127245
- name: data
128246
mountPath: /git
129-
subPath: git/
247+
subPath: git
130248

131-
- mountPath: /var/dns-log
132-
name: data
133-
subPath: logs
249+
- name: data
250+
mountPath: /root
251+
subPath: home

manifests/bind9/overlays/production/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ namespace: dns
1414
images:
1515
- name: nofusscomputing/bind
1616
newName: harbor.earth.nww/docker/nofusscomputing/bind
17-
newTag: '1.0.0-rc2'
17+
newTag: '1.0.0-rc3'

0 commit comments

Comments
 (0)