Skip to content

Commit 9e1865d

Browse files
author
Marcel Zapf
committed
update
1 parent f19d963 commit 9e1865d

6 files changed

Lines changed: 111 additions & 41 deletions

File tree

Dockerfile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2828
&& apt-get clean && rm -rf /var/lib/apt/lists/*
2929

3030
# Install Terraform CLI
31-
ARG TERRAFORM_VERSION=1.9.5
31+
ARG TERRAFORM_VERSION=1.12.1
3232
RUN curl -L "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip && \
3333
unzip -o terraform.zip -d /usr/local/bin/ && \
3434
rm terraform.zip
3535

3636
# Install Packer
37-
ARG PACKER_VERSION=1.11.2
37+
ARG PACKER_VERSION=1.13.1
3838
RUN curl -L "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" -o packer.zip && \
3939
unzip -o packer.zip -d /usr/local/bin/ && \
4040
rm packer.zip
@@ -45,13 +45,12 @@ RUN git clone -b ${TFHELPER_VERSION} https://github.com/hashicorp-community/tf-h
4545
cp /usr/local/tf-helper/tfh/bin/tfh /usr/local/bin/ && \
4646
rm -rf /usr/local/tf-helper
4747

48-
# Set up Python environment in /usr/local/venv
49-
COPY ./requirements.txt /tmp/requirements.txt
50-
RUN python3 -m venv /usr/local/venv && \
51-
/usr/local/venv/bin/pip install --upgrade pip && \
52-
/usr/local/venv/bin/pip install -r /tmp/requirements.txt && \
48+
# Set up Python environment
49+
RUN pip3 install --upgrade pip && \
50+
pip3 install -r /tmp/requirements.txt && \
5351
rm /tmp/requirements.txt
5452

53+
5554
# Install MinIO Client
5655
RUN curl -L -o /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc && \
5756
chmod +x /usr/local/bin/mc
@@ -76,10 +75,6 @@ USER dev
7675
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
7776
RUN chmod 755 /usr/local/bin/entrypoint.sh
7877

79-
# Set environment variables, including PATH to specific directories
80-
ENV VIRTUAL_ENV="/usr/local/venv"
81-
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
82-
8378
# Expose SSH port
8479
EXPOSE 2222
8580

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Release.Name }}-bash-profile
5+
data:
6+
.bash_profile: |
7+
if [ -f ~/.bashrc ]; then
8+
. ~/.bashrc
9+
fi

chart/templates/cm-bashrc.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Release.Name }}-bashrc
5+
data:
6+
.bashrc: |
7+
# ~/.bashrc for dev user
8+
9+
export PATH="$HOME/.local/bin:/usr/local/venv/bin:$PATH"
10+
export PYTHONUSERBASE="$HOME/.local"
11+
12+
# Colors
13+
export LS_OPTIONS='--color=auto'
14+
eval "$(dircolors)"
15+
alias ls='ls $LS_OPTIONS'
16+
alias ll='ls $LS_OPTIONS -l'
17+
alias la='ls $LS_OPTIONS -la'
18+
19+
# Prompt
20+
PS1='\u@\h:\w\$ '

chart/templates/cm-entrypoint.yaml

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,74 @@ metadata:
55
data:
66
entrypoint.sh: |
77
#!/bin/bash
8+
set -euo pipefail
89
9-
echo "Ensuring SSH keys directory exists at /home/dev/ssh_keys."
10-
mkdir -p /home/dev/ssh_keys
10+
SSH_KEYS_DIR=/home/dev/ssh_keys
11+
RUN_DIR=/home/dev/run
12+
PID_FILE=$RUN_DIR/sshd.pid
13+
PORT=2222
1114
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
15+
echo "Ensuring SSH keys directory exists at $SSH_KEYS_DIR."
16+
mkdir -p "$SSH_KEYS_DIR"
17+
18+
# Generate keys if missing
19+
for keytype in rsa ecdsa ed25519; do
20+
keyfile="$SSH_KEYS_DIR/ssh_host_${keytype}_key"
21+
if [ ! -f "$keyfile" ]; then
22+
echo "Generating new SSH host $keytype key."
23+
ssh-keygen -t "$keytype" -f "$keyfile" -N '' >/dev/null
24+
fi
25+
done
2526
26-
chmod 600 /home/dev/ssh_keys/ssh_host_*
27+
chmod 600 "$SSH_KEYS_DIR"/ssh_host_*
2728
28-
echo "Ensuring run directory exists at /home/dev/run."
29-
mkdir -p /home/dev/run
29+
echo "Ensuring run directory exists at $RUN_DIR."
30+
mkdir -p "$RUN_DIR"
3031
3132
echo "Currently running sshd processes:"
32-
ps aux | grep sshd
33+
pgrep sshd || echo "No sshd processes found."
3334
3435
echo "Killing any existing sshd processes..."
35-
for pid in $(ps aux | grep sshd | grep -v grep | awk '{print $2}'); do
36-
echo "Killing sshd pid $pid"
37-
kill $pid
38-
done
36+
pids=$(pgrep sshd || true)
37+
if [ -n "$pids" ]; then
38+
echo "Found sshd PIDs: $pids"
39+
kill $pids
40+
# Wait max 5s for sshd to stop
41+
timeout=5
42+
while pgrep sshd >/dev/null && [ $timeout -gt 0 ]; do
43+
sleep 1
44+
timeout=$((timeout-1))
45+
done
46+
if pgrep sshd >/dev/null; then
47+
echo "sshd still running, sending SIGKILL"
48+
pkill -9 sshd
49+
fi
50+
else
51+
echo "No sshd processes to kill."
52+
fi
3953
4054
echo "Removing stale PID file if exists..."
41-
rm -f /home/dev/run/sshd.pid
55+
rm -f "$PID_FILE"
56+
57+
# Check if port is free (requires netstat or ss)
58+
if command -v ss >/dev/null; then
59+
if ss -tuln | grep -q ":$PORT "; then
60+
echo "ERROR: Port $PORT is still in use, aborting start."
61+
exit 1
62+
fi
63+
elif command -v netstat >/dev/null; then
64+
if netstat -tuln | grep -q ":$PORT "; then
65+
echo "ERROR: Port $PORT is still in use, aborting start."
66+
exit 1
67+
fi
68+
else
69+
echo "WARNING: Could not check port usage (no ss/netstat found)."
70+
fi
4271
43-
echo "Starting SSH service..."
72+
echo "Starting SSH service on port $PORT..."
4473
exec /usr/sbin/sshd -D -f /etc/ssh/sshd_config \
45-
-o Port=2222 \
46-
-o HostKey=/home/dev/ssh_keys/ssh_host_ed25519_key \
47-
-o HostKey=/home/dev/ssh_keys/ssh_host_rsa_key \
48-
-o HostKey=/home/dev/ssh_keys/ssh_host_ecdsa_key \
49-
-o PidFile=/home/dev/run/sshd.pid
74+
-o Port=$PORT \
75+
-o HostKey=$SSH_KEYS_DIR/ssh_host_ed25519_key \
76+
-o HostKey=$SSH_KEYS_DIR/ssh_host_rsa_key \
77+
-o HostKey=$SSH_KEYS_DIR/ssh_host_ecdsa_key \
78+
-o PidFile=$PID_FILE

chart/templates/statefulset.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ spec:
5353
mountPath: /etc/pam.d/sshd
5454
subPath: sshd
5555
readOnly: true
56+
- name: bashrc
57+
mountPath: /home/dev/.bashrc
58+
subPath: .bashrc
59+
readOnly: true
60+
- name: bash-profile
61+
mountPath: /home/dev/.bash_profile
62+
subPath: .bash_profile
63+
readOnly: true
5664
resources: {{ toYaml .Values.resources | indent 10 }}
5765
volumes:
5866
- name: entrypoint-script
@@ -71,6 +79,14 @@ spec:
7179
configMap:
7280
name: {{ .Release.Name }}-pam-config
7381
defaultMode: 0755
82+
- name: bashrc
83+
configMap:
84+
name: {{ .Release.Name }}-bashrc
85+
defaultMode: 0644
86+
- name: bash-profile
87+
configMap:
88+
name: {{ .Release.Name }}-bash-profile
89+
defaultMode: 0644
7490
volumeClaimTemplates:
7591
- metadata:
7692
name: home-volume

chart/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ssh:
2020
authorizedKeys: |
2121
# Place auth keys here ...
2222
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu...
23+
2324
securityContext:
2425
runAsNonRoot: true
2526
runAsUser: 1001

0 commit comments

Comments
 (0)