Skip to content

Commit f28110a

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

2 files changed

Lines changed: 124 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: 124 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,69 +24,44 @@ 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
46-
47-
export REPO_NAME_FULL="${SSH_REPOSITORY_HOST}:${SSH_REPOSITORY_OWNER}/${SSH_REPOSITORY_NAME}.git"
48-
49-
echo "Env var REPO_NAME_FULL=[${REPO_NAME_FULL}] setup";
5035
51-
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
36+
cd /git;
5237
53-
echo "Clonning repo";
38+
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
5439
55-
git clone -b master git@${REPO_NAME_FULL} /git/source;
40+
echo "********************************************";
5641
57-
else
42+
git status;
5843
59-
echo "Not Authenticated, check ssh key. RC=[${?}]";
44+
echo "********************************************";
45+
46+
echo "Checking for repo updates";
6047
61-
fi
48+
git fetch -fpvt;
6249
63-
else
64-
65-
cd /git/source;
66-
67-
if ssh -T "git@$SSH_REPOSITORY_HOST" -i $KEY_FILE_PATH/deploy; then
50+
echo "Git reset....";
6851
69-
echo "********************************************";
52+
git reset --hard;
7053
71-
git status;
54+
echo "Pulling any changes....";
7255
73-
echo "********************************************";
74-
75-
echo "Checking for repo updates";
56+
git pull --rebase
7657
77-
git fetch -fpvt;
78-
79-
echo "Pulling any changes....";
80-
81-
git pull --rebase
58+
else
8259
83-
else
60+
echo "Not Authenticated, check ssh key. RC=[${?}]";
8461
85-
echo "Not Authenticated, check ssh key. RC=[${?}]";
62+
fi
8663
87-
fi
8864
89-
fi
9065
9166
echo "Loop Finish.";
9267
@@ -115,6 +90,11 @@ spec:
11590
secretKeyRef:
11691
name: bind-config
11792
key: SSH_REPOSITORY_NAME
93+
- name: SSH_REPOSITORY_REF
94+
valueFrom:
95+
secretKeyRef:
96+
name: bind-config
97+
key: SSH_REPOSITORY_REF
11898

11999
resources:
120100
limits:
@@ -128,6 +108,110 @@ spec:
128108
mountPath: /git
129109
subPath: git/
130110

111+
- name: data
112+
mountPath: /root
113+
subPath: home
114+
131115
- mountPath: /var/dns-log
132116
name: data
133117
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+
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;
168+
169+
fi
170+
171+
fi
172+
173+
echo "Finish init";
174+
175+
env:
176+
- name: SSH_PRIVATE_KEY
177+
valueFrom:
178+
secretKeyRef:
179+
name: bind-config
180+
key: SSH_PRIVATE_KEY
181+
- name: SSH_REPOSITORY_HOST
182+
valueFrom:
183+
secretKeyRef:
184+
name: bind-config
185+
key: SSH_REPOSITORY_HOST
186+
- name: SSH_REPOSITORY_OWNER
187+
valueFrom:
188+
secretKeyRef:
189+
name: bind-config
190+
key: SSH_REPOSITORY_OWNER
191+
- name: SSH_REPOSITORY_NAME
192+
valueFrom:
193+
secretKeyRef:
194+
name: bind-config
195+
key: SSH_REPOSITORY_NAME
196+
- name: SSH_REPOSITORY_REF
197+
valueFrom:
198+
secretKeyRef:
199+
name: bind-config
200+
key: SSH_REPOSITORY_REF
201+
202+
resources:
203+
limits:
204+
cpu: 1
205+
memory: 500Mi
206+
requests:
207+
cpu: 50m
208+
memory: 150Mi
209+
210+
volumeMounts:
211+
- name: data
212+
mountPath: /git
213+
subPath: git
214+
215+
- name: data
216+
mountPath: /root
217+
subPath: home

0 commit comments

Comments
 (0)