contentmonster/.forgejo/workflows/test.yml
Kumi 930dd014fe
Some checks failed
Test! / test (push) Failing after 1m38s
feat: add delay for SSH server readiness in CI
Introduced a step in the CI test workflow to wait for the SSH server to start before proceeding with subsequent actions. This ensures that the server is fully operational and can accept connections before any attempts are made to copy the public key into the Docker container, avoiding potential race conditions where the server might not be ready in time, leading to failed CI runs. The addition of a simple loop with a timeout mechanism improves the reliability of the CI pipeline by making sure tests only run when all services are up and running.
2024-04-22 18:05:50 +02:00

53 lines
1.4 KiB
YAML

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: Install Docker
run: |
apt-get update
apt-get install -y docker.io
- name: Build and run SSH Server Docker Container
run: |
docker rm -f ssh-server || true
docker build -t my-ssh-server ./ci-tests/
docker run -d -p 2222:22 --name ssh-server my-ssh-server
- name: Wait for SSH server to start
run: |
for i in {1..10}; do
nc -z localhost 2222 && break
sleep 1
done
- 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: |
mkdir -p ~/.ssh
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 replication@localhost echo "SSH connection successful"