Skip to content

Commit a9f3d63

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

3 files changed

Lines changed: 156 additions & 47 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: 155 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,75 +24,185 @@ spec:
2424
2525
export KEY_FILE_PATH=~/.ssh/${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME};
2626
27-
mkdir -p "${KEY_FILE_PATH}";
28-
29-
echo "Env var KEY_FILE_PATH=[${KEY_FILE_PATH}] setup";
30-
31-
cat > ${KEY_FILE_PATH}/deploy <<EOF
32-
$SSH_PRIVATE_KEY
33-
EOF
34-
3527
chmod 600 ${KEY_FILE_PATH}/deploy;
3628
3729
export GIT_SSH_COMMAND="ssh -i $KEY_FILE_PATH/deploy";
3830
39-
ssh-keyscan "${SSH_REPOSITORY_HOST}" >> ~/.ssh/known_hosts
40-
4131
while :; do
4232
4333
echo "Loop Start......";
4434
45-
if [ ! -d /git/source/.git ]; then
4635
47-
export REPO_NAME_FULL="${SSH_REPOSITORY_HOST}:${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME}.git"
36+
cd /git;
4837
49-
echo "Env var REPO_NAME_FULL=[${REPO_NAME_FULL}] setup";
38+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
5039
51-
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
40+
echo "********************************************";
5241
53-
echo "Clonning repo";
42+
git status;
5443
55-
git clone -b master git@${REPO_NAME_FULL} /git/source;
44+
echo "********************************************";
45+
46+
echo "Checking for repo updates";
5647
57-
else
48+
git fetch -fpvt;
5849
59-
echo "Not Authenticated, check ssh key. RC=[${?}]";
50+
echo "Git reset....";
6051
61-
fi
52+
git reset --hard;
53+
54+
echo "Pulling any changes....";
55+
56+
git pull --rebase
6257
6358
else
6459
65-
cd /git/source;
60+
echo "Not Authenticated, check ssh key. RC=[${?}]";
61+
62+
fi
6663
67-
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
6864
69-
echo "********************************************";
7065
71-
git status;
66+
echo "Loop Finish.";
7267
73-
echo "********************************************";
74-
75-
echo "Checking for repo updates";
68+
sleep 300
7669
77-
git fetch -fpvt;
70+
done;
7871
79-
echo "Pulling any changes....";
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
8098

81-
git pull --rebase
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/
82110

83-
else
111+
- name: data
112+
mountPath: /root
113+
subPath: home
84114

85-
echo "Not Authenticated, check ssh key. RC=[${?}]";
115+
- mountPath: /var/dns-log
116+
name: data
117+
subPath: logs
86118

87-
fi
119+
initContainers:
120+
121+
- name: clone
122+
image: alpine:3.23.2
123+
command:
124+
- sh
125+
- -c
126+
- |
127+
echo "Start init";
128+
if [ ! -d /git/.git ]; then
129+
130+
131+
echo "Installing pre-reqs.....";
132+
133+
apk update;
134+
apk add git openssh-client-default;
135+
136+
export KEY_FILE_PATH=~/.ssh/${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME};
137+
138+
mkdir -p "${KEY_FILE_PATH}";
139+
140+
echo "Env var KEY_FILE_PATH=[${KEY_FILE_PATH}] setup";
141+
142+
echo "$SSH_PRIVATE_KEY" > ${KEY_FILE_PATH}/deploy
143+
144+
145+
chmod 600 ${KEY_FILE_PATH}/deploy;
146+
147+
export GIT_SSH_COMMAND="ssh -i $KEY_FILE_PATH/deploy";
148+
149+
ssh-keyscan "${SSH_REPOSITORY_HOST}" >> ~/.ssh/known_hosts
150+
151+
152+
export REPO_NAME_FULL="${SSH_REPOSITORY_HOST}:${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME}.git"
153+
154+
echo "Env var REPO_NAME_FULL=[${REPO_NAME_FULL}] setup";
155+
156+
157+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
158+
159+
echo "Clonning repo on branch=[${SSH_REPOSITORY_REF}]";
160+
161+
git clone -b "${SSH_REPOSITORY_REF}" git@${REPO_NAME_FULL} /git;
162+
163+
else
164+
165+
echo "Not Authenticated, check ssh key. RC=[${?}]";
166+
167+
exit 1;
88168
89169
fi
90170
91-
echo "Loop Finish.";
171+
else
92172
93-
sleep 300
94173
95-
done;
174+
cd /git;
175+
176+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
177+
178+
echo "********************************************";
179+
180+
git status;
181+
182+
echo "********************************************";
183+
184+
echo "Checking for repo updates";
185+
186+
git fetch -fpvt;
187+
188+
echo "Git reset....";
189+
190+
git reset --hard;
191+
192+
echo "Pulling any changes....";
193+
194+
git pull --rebase
195+
196+
else
197+
198+
echo "Not Authenticated, check ssh key. RC=[${?}]";
199+
200+
fi
201+
202+
203+
fi
204+
205+
echo "Finish init";
96206
97207
env:
98208
- name: SSH_PRIVATE_KEY
@@ -115,6 +225,11 @@ spec:
115225
secretKeyRef:
116226
name: bind-config
117227
key: SSH_REPOSITORY_NAME
228+
- name: SSH_REPOSITORY_REF
229+
valueFrom:
230+
secretKeyRef:
231+
name: bind-config
232+
key: SSH_REPOSITORY_REF
118233

119234
resources:
120235
limits:
@@ -123,11 +238,12 @@ spec:
123238
requests:
124239
cpu: 50m
125240
memory: 150Mi
241+
126242
volumeMounts:
127243
- name: data
128244
mountPath: /git
129-
subPath: git/
245+
subPath: git
130246

131-
- mountPath: /var/dns-log
132-
name: data
133-
subPath: logs
247+
- name: data
248+
mountPath: /root
249+
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)