Skip to content

Commit 977b74a

Browse files
committedJun 5, 2024··
ci: enhance CI workflow with SSH job and optimizations
- Remove an empty line in the jobs section - Reduce sleep duration from 5 seconds to 3 seconds - Add a new job `check-ssh-key` to the workflow - Add steps to create a new SSH server using Docker - Add steps to set environment variables for remote host and private key - Add a step to execute remote SSH commands using the `appleboy/ssh-action` GitHub Action Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent 0b0e770 commit 977b74a

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed
 

‎.github/workflows/ssh-server.yml

+41-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on: [push]
55
jobs:
66
default-user-name-password:
77
runs-on: ubuntu-latest
8-
98
steps:
109
- name: Checkout code
1110
uses: actions/checkout@v4
@@ -29,7 +28,7 @@ jobs:
2928
echo "======= container ip address ========="
3029
cat ip.txt
3130
echo "======================================"
32-
sleep 5
31+
sleep 3
3332
3433
- name: executing remote ssh commands using password (1.0.3)
3534
uses: appleboy/ssh-action@v1.0.3
@@ -39,3 +38,43 @@ jobs:
3938
password: password
4039
port: 2222
4140
script: whoami
41+
42+
check-ssh-key:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: create new ssh server
49+
run: |
50+
docker run -d \
51+
--name=openssh-server \
52+
--hostname=openssh-server \
53+
-p 2223:2222 \
54+
-e PUBLIC_KEY=$(cat testdata/.ssh/id_rsa.pub) \
55+
-e SUDO_ACCESS=false \
56+
-e PASSWORD_ACCESS=true \
57+
-e USER_PASSWORD=password \
58+
-e USER_NAME=linuxserver.io \
59+
--restart unless-stopped \
60+
lscr.io/linuxserver/openssh-server:latest
61+
docker exec openssh-server sh -c "hostname -i" > ip.txt
62+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
63+
cat ip.txt >> $GITHUB_ENV
64+
echo "EOF" >> $GITHUB_ENV
65+
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
66+
cat testdata/.ssh/id_rsa >> $GITHUB_ENV
67+
echo "EOF" >> $GITHUB_ENV
68+
echo "======= container ip address ========="
69+
cat ip.txt
70+
echo "======================================"
71+
sleep 3
72+
73+
- name: executing remote ssh commands using password (1.0.3)
74+
uses: appleboy/ssh-action@v1.0.3
75+
with:
76+
host: ${{ env.REMOTE_HOST }}
77+
username: linuxserver.io
78+
key: ${{ env.PRIVATE_KEY }}
79+
port: 2223
80+
script: whoami

0 commit comments

Comments
 (0)
Please sign in to comment.