Skip to content

Commit b626538

Browse files
update
1 parent 8f33c13 commit b626538

4 files changed

Lines changed: 65 additions & 5 deletions

File tree

chart/templates/configmap.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: dev-environment-entrypoint
5+
data:
6+
entrypoint.sh: |
7+
#!/bin/bash
8+
9+
echo "Ensuring SSH keys directory exists at /home/dev/ssh_keys."
10+
mkdir -p /home/dev/ssh_keys
11+
12+
# Generate keys if they do not exist
13+
if [ ! -f /home/dev/ssh_keys/ssh_host_rsa_key ]; then
14+
echo "Generating new SSH host RSA key."
15+
ssh-keygen -t rsa -f /home/dev/ssh_keys/ssh_host_rsa_key -N ''
16+
fi
17+
if [ ! -f /home/dev/ssh_keys/ssh_host_ecdsa_key ]; then
18+
echo "Generating new SSH host ECDSA key."
19+
ssh-keygen -t ecdsa -f /home/dev/ssh_keys/ssh_host_ecdsa_key -N ''
20+
fi
21+
if [ ! -f /home/dev/ssh_keys/ssh_host_ed25519_key ]; then
22+
echo "Generating new SSH host ED25519 key."
23+
ssh-keygen -t ed25519 -f /home/dev/ssh_keys/ssh_host_ed25519_key -N ''
24+
fi
25+
26+
# Correct permissions for SSH keys
27+
chmod 600 /home/dev/ssh_keys/ssh_host_*
28+
29+
# Ensure the run directory for the PID file exists and has the right permissions
30+
echo "Ensuring run directory exists at /home/dev/run."
31+
mkdir -p /home/dev/run
32+
chown dev:dev /home/dev/run
33+
34+
35+
echo "Starting SSH service with host keys from /home/dev/ssh_keys on port 2222."
36+
/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config \
37+
-o Port={{ .Values.service.targetPort }} \
38+
-o HostKey=/home/dev/ssh_keys/ssh_host_rsa_key \
39+
-o HostKey=/home/dev/ssh_keys/ssh_host_ecdsa_key \
40+
-o HostKey=/home/dev/ssh_keys/ssh_host_ed25519_key \
41+
-o PidFile=/home/dev/run/sshd.pid
42+
43+
if [ $? -ne 0 ]; then
44+
echo "Failed to start SSH service."
45+
else
46+
echo "SSH service started successfully."
47+
fi
48+
49+
# Keep the container running if no command is provided
50+
echo "No additional command provided, container will keep running."
51+
tail -f /dev/null

chart/templates/deployment.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
apiVersion: apps/v1
32
kind: Deployment
43
metadata:
@@ -13,14 +12,15 @@ spec:
1312
labels:
1413
app: {{ .Release.Name }}
1514
spec:
15+
securityContext:
16+
fsGroup: 1001
1617
containers:
1718
- name: {{ .Release.Name }}
1819
image: "{{ .Values.image.source }}"
1920
imagePullPolicy: {{ .Values.image.pullPolicy }}
2021
ports:
2122
- containerPort: {{ .Values.service.port }}
2223
securityContext:
23-
fsGroup: 1001
2424
runAsNonRoot: {{ .Values.securityContext.runAsNonRoot }}
2525
runAsUser: {{ .Values.securityContext.runAsUser }}
2626
allowPrivilegeEscalation: {{ .Values.securityContext.allowPrivilegeEscalation }}
@@ -32,9 +32,17 @@ spec:
3232
volumeMounts:
3333
- name: home-volume
3434
mountPath: /home/dev
35+
- name: entrypoint-script
36+
mountPath: /usr/local/bin/entrypoint.sh
37+
subPath: entrypoint.sh
38+
readOnly: true
3539
resources:
3640
{{ toYaml .Values.resources | indent 10 }}
3741
volumes:
42+
- name: entrypoint-script
43+
configMap:
44+
name: dev-environment-entrypoint
45+
defaultMode: 0755
3846
- name: home-volume
3947
persistentVolumeClaim:
4048
claimName: {{ .Release.Name }}-pvc

chart/templates/svc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ spec:
66
type: {{ .Values.service.type }}
77
ports:
88
- port: {{ .Values.service.port }}
9-
targetPort: 2222
9+
targetPort: {{ .Values.service.targetPort }}
1010
selector:
1111
app: {{ .Release.Name }}

chart/values.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
replicaCount: 1
22

33
image:
4-
source: ghcr.io/syntax3rror404/k8s-devmachine@sha256:81c192b30a053c37dfa6217be80aa5076ec35a314b9d3cc5c262928cad7e4578
4+
source: ghcr.io/syntax3rror404/k8s-devmachine@sha256:9d7bf6ca64f090c46c1bb85fe406a75111ef59207ca6548b72a10f3b5ff3f2a5
55
pullPolicy: IfNotPresent
66

77
service:
88
type: LoadBalancer
9-
port: 22
9+
port: 2222
10+
targetPort: 2222
1011

1112
persistence:
1213
enabled: true

0 commit comments

Comments
 (0)