feat: add ssh init

This commit is contained in:
Ravinou 2023-09-17 11:21:22 +02:00
parent 7e21c7b379
commit f4479bb2f8
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
2 changed files with 13 additions and 2 deletions

View file

@ -1,4 +1,4 @@
FROM node:18-buster-slim
FROM node:18-bookworm-slim
RUN apt-get update && \
apt-get install -y curl git jq borgbackup openssh-server && \
@ -9,6 +9,8 @@ RUN groupadd borgwarehouse
RUN useradd -m -g borgwarehouse borgwarehouse
RUN cp /etc/ssh/sshd_config /etc/ssh/moduli /home/borgwarehouse/
WORKDIR /home/borgwarehouse/app
COPY . .
@ -21,7 +23,7 @@ RUN npm ci --only=production
RUN npm run build
EXPOSE 3000
EXPOSE 3000 22
ENTRYPOINT ["./docker-bw-init.sh"]

View file

@ -6,6 +6,14 @@ SSH_DIR="/home/borgwarehouse/.ssh"
AUTHORIZED_KEYS_FILE="$SSH_DIR/authorized_keys"
REPOS_DIR="/home/borgwarehouse/repos"
init_ssh_server() {
if [ -z "$(ls -A /etc/ssh)" ]; then
echo "/etc/ssh is empty, generating SSH host keys..."
ssh-keygen -A
cp /home/borgwarehouse/sshd_config /home/borgwarehouse/moduli /etc/ssh/
fi
}
create_ssh_directory() {
if [ ! -d "$SSH_DIR" ]; then
echo "The .ssh directory does not exist, creating..."
@ -29,6 +37,7 @@ create_repos_directory() {
fi
}
init_ssh_server
create_ssh_directory
create_authorized_keys_file
create_repos_directory