feat: Introduce automated SSH testing flow
Implemented a new CI pipeline configured to automatically test SSH connectivity as part of the project's testing phase. This involves creating and configuring a Docker container to serve as an SSH server, generating an SSH key pair for secure connection, and ensuring the build environment can establish an SSH connection to the container without manual intervention. The setup aims to automate and streamline testing of SSH-related functionalities, enhancing the reliability of code changes affecting remote server interactions. - A Dockerfile was added to set up an SSH server in a container. - The CI pipeline (`test.yml`) was configured to build this container, generate SSH keys, copy the public key to the container, and attempt an SSH connection. This enhancement supports more robust testing processes, particularly for features that interact with remote servers via SSH.
This commit is contained in:
parent
e82ccb2701
commit
d1bf34ab1f
2 changed files with 48 additions and 0 deletions
38
.forgejo/workflows/test.yml
Normal file
38
.forgejo/workflows/test.yml
Normal file
|
@ -0,0 +1,38 @@
|
|||
name: Test!
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Generate SSH key pair
|
||||
run: |
|
||||
ssh-keygen -t rsa -b 4096 -f my_ssh_key -N ""
|
||||
|
||||
- name: Build and run SSH Server Docker Container
|
||||
run: |
|
||||
docker build -t my-ssh-server ./ci-tests/Dockerfile
|
||||
docker run -d -p 2222:22 --name ssh-server my-ssh-server
|
||||
|
||||
- name: Copy public key to Docker container
|
||||
run: |
|
||||
docker cp my_ssh_key.pub ssh-server:/home/replication/.ssh/authorized_keys
|
||||
docker exec ssh-server chown replication:replication /home/replication/.ssh/authorized_keys
|
||||
docker exec ssh-server chmod 600 /home/replication/.ssh/authorized_keys
|
||||
|
||||
- name: Trust SSH server's host key (to prevent interactive prompt)
|
||||
run: |
|
||||
ssh-keyscan -p 2222 -H localhost >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Connect to SSH server using SSH key
|
||||
run: |
|
||||
ssh -i my_ssh_key -p 2222 root@localhost echo "SSH connection successful"
|
10
ci-tests/Dockerfile
Normal file
10
ci-tests/Dockerfile
Normal file
|
@ -0,0 +1,10 @@
|
|||
FROM debian:latest
|
||||
RUN apt-get update && apt-get install -y openssh-server
|
||||
|
||||
RUN useradd -m replication && mkdir -p /home/replication/.ssh && chown -R replication:replication /home/replication/.ssh
|
||||
|
||||
RUN mkdir /var/run/sshd
|
||||
|
||||
EXPOSE 22
|
||||
|
||||
CMD ["/usr/sbin/sshd", "-D"]
|
Loading…
Reference in a new issue