Skip to content

Commit 43895f2

Browse files
committedJun 5, 2024··
ci: refactor SSH testing workflows and job configurations
- Rename workflow from "remote ssh command" to "testing main branch" - Remove environment variables `FOO` and `BAR` - Rename job `testing01` to `default-user-name-password` - Rename step "checkout" to "Checkout code" - Replace step "correct password but wrong key" with "create new ssh server" using Docker - Update SSH connection details to use environment variables for host, username, password, and port - Add new job `check-ssh-key` with steps to add public key to environment and create a new SSH server - Add new job `support-key-passphrase` with steps to add public key to environment and create a new SSH server - Add new job `multiple-server` to create and manage multiple SSH servers - Add new job `support-ed25519-key` with steps to add public key to environment and create a new SSH server - Add new job `testing-with-env` with steps to add public key to environment and create a new SSH server - Remove jobs `testing02`, `testing03`, `testing04`, and `testing05` - Rename workflow in `ssh-server.yml` from "openssh-server" to "testing stable version" Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent b6941ae commit 43895f2

File tree

2 files changed

+348
-158
lines changed

2 files changed

+348
-158
lines changed
 

‎.github/workflows/ci.yml

+347-157
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,405 @@
1-
name: remote ssh command
2-
on: [push]
1+
name: testing main branch
32

4-
env:
5-
FOO: "BAR"
6-
BAR: "FOO"
3+
on: [push]
74

85
jobs:
9-
testing01:
10-
name: default flag testing
6+
default-user-name-password:
117
runs-on: ubuntu-latest
128
steps:
13-
- name: checkout
9+
- name: Checkout code
1410
uses: actions/checkout@v4
1511

16-
- name: correct password but wrong key
17-
uses: ./
18-
with:
19-
host: ${{ secrets.HOST }}
20-
username: ${{ secrets.USERNAME }}
21-
password: ${{ secrets.PASSWORD }}
22-
key: "1234"
23-
port: ${{ secrets.PORT }}
24-
script: whoami
12+
- name: create new ssh server
13+
run: |
14+
docker run -d \
15+
--name=openssh-server \
16+
--hostname=openssh-server \
17+
-p 2222:2222 \
18+
-e SUDO_ACCESS=false \
19+
-e PASSWORD_ACCESS=true \
20+
-e USER_PASSWORD=password \
21+
-e USER_NAME=linuxserver.io \
22+
--restart unless-stopped \
23+
lscr.io/linuxserver/openssh-server:latest
24+
docker exec openssh-server sh -c "hostname -i" > ip.txt
25+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
26+
cat ip.txt >> $GITHUB_ENV
27+
echo "EOF" >> $GITHUB_ENV
28+
echo "======= container ip address ========="
29+
cat ip.txt
30+
echo "======================================"
31+
sleep 2
2532
26-
- name: wrong password but correct key
33+
- name: ssh by username and password
2734
uses: ./
2835
with:
29-
host: ${{ secrets.HOST }}
30-
username: ${{ secrets.USERNAME }}
31-
password: "abcdef"
32-
key: ${{ secrets.KEY }}
33-
port: ${{ secrets.PORT }}
36+
host: ${{ env.REMOTE_HOST }}
37+
username: linuxserver.io
38+
password: password
39+
port: 2222
3440
script: whoami
3541

36-
- name: executing remote ssh commands using password
42+
check-ssh-key:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: add public key to env
49+
run: |
50+
echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
51+
cat testdata/.ssh/id_rsa.pub >> $GITHUB_ENV
52+
echo "EOF" >> $GITHUB_ENV
53+
echo "======= public key ========="
54+
cat testdata/.ssh/id_rsa.pub
55+
echo "============================"
56+
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
57+
cat testdata/.ssh/id_rsa >> $GITHUB_ENV
58+
echo "EOF" >> $GITHUB_ENV
59+
echo "======= private key ========="
60+
cat testdata/.ssh/id_rsa
61+
echo "============================"
62+
63+
- name: create new ssh server
64+
run: |
65+
docker run -d \
66+
--name=openssh-server \
67+
--hostname=openssh-server \
68+
-p 2222:2222 \
69+
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
70+
-e SUDO_ACCESS=false \
71+
-e PASSWORD_ACCESS=true \
72+
-e USER_PASSWORD=password \
73+
-e USER_NAME=linuxserver.io \
74+
--restart unless-stopped \
75+
lscr.io/linuxserver/openssh-server:latest
76+
docker exec openssh-server sh -c "hostname -i" > ip.txt
77+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
78+
cat ip.txt >> $GITHUB_ENV
79+
echo "EOF" >> $GITHUB_ENV
80+
echo "======= container ip address ========="
81+
cat ip.txt
82+
echo "======================================"
83+
sleep 2
84+
85+
- name: ssh by private key
3786
uses: ./
3887
with:
39-
host: ${{ secrets.HOST }}
40-
username: ${{ secrets.USERNAME }}
41-
password: ${{ secrets.PASSWORD }}
42-
port: ${{ secrets.PORT }}
88+
host: ${{ env.REMOTE_HOST }}
89+
username: linuxserver.io
90+
key: ${{ env.PRIVATE_KEY }}
91+
port: 2222
4392
script: whoami
4493

45-
- name: executing remote ssh commands using ssh key
94+
- name: wrong password but correct key
4695
uses: ./
4796
with:
48-
host: ${{ secrets.HOST }}
49-
username: ${{ secrets.USERNAME }}
50-
key: ${{ secrets.KEY }}
51-
port: ${{ secrets.PORT }}
97+
host: ${{ env.REMOTE_HOST }}
98+
username: linuxserver.io
99+
password: "abcdef"
100+
key: ${{ env.PRIVATE_KEY }}
101+
port: 2222
52102
script: whoami
53103

54-
- name: multiple command
104+
- name: correct password but wrong key
55105
uses: ./
56106
with:
57-
host: ${{ secrets.HOST }}
58-
username: ${{ secrets.USERNAME }}
59-
key: ${{ secrets.KEY }}
60-
port: ${{ secrets.PORT }}
61-
script: |
62-
whoami
63-
ls -al
107+
host: ${{ env.REMOTE_HOST }}
108+
username: linuxserver.io
109+
password: password
110+
key: password
111+
port: 2222
112+
script: whoami
64113

65114
- name: stop script if command error
66115
uses: ./
67116
continue-on-error: true
68117
with:
69-
host: ${{ secrets.HOST }}
70-
username: ${{ secrets.USERNAME }}
71-
key: ${{ secrets.KEY }}
72-
port: ${{ secrets.PORT }}
118+
host: ${{ env.REMOTE_HOST }}
119+
username: linuxserver.io
120+
password: password
121+
key: password
122+
port: 2222
73123
script_stop: true
74124
sync: true
75125
debug: true
76126
script: |
77127
mkdir abc/def
78128
ls -al
79129
130+
support-key-passphrase:
131+
runs-on: ubuntu-latest
132+
steps:
133+
- name: Checkout code
134+
uses: actions/checkout@v4
135+
136+
- name: add public key to env
137+
run: |
138+
echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
139+
cat testdata/.ssh/id_passphrase.pub >> $GITHUB_ENV
140+
echo "EOF" >> $GITHUB_ENV
141+
echo "======= public key ========="
142+
cat testdata/.ssh/id_passphrase.pub
143+
echo "============================"
144+
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
145+
cat testdata/.ssh/id_passphrase >> $GITHUB_ENV
146+
echo "EOF" >> $GITHUB_ENV
147+
echo "======= private key ========="
148+
cat testdata/.ssh/id_passphrase
149+
echo "============================"
150+
151+
- name: create new ssh server
152+
run: |
153+
docker run -d \
154+
--name=openssh-server \
155+
--hostname=openssh-server \
156+
-p 2222:2222 \
157+
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
158+
-e SUDO_ACCESS=false \
159+
-e PASSWORD_ACCESS=true \
160+
-e USER_PASSWORD=password \
161+
-e USER_NAME=linuxserver.io \
162+
--restart unless-stopped \
163+
lscr.io/linuxserver/openssh-server:latest
164+
docker exec openssh-server sh -c "hostname -i" > ip.txt
165+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
166+
cat ip.txt >> $GITHUB_ENV
167+
echo "EOF" >> $GITHUB_ENV
168+
echo "======= container ip address ========="
169+
cat ip.txt
170+
echo "======================================"
171+
sleep 2
172+
80173
- name: ssh key passphrase
81174
uses: ./
82175
with:
83-
host: ${{ secrets.HOST }}
84-
username: ${{ secrets.USERNAME }}
85-
key: ${{ secrets.SSH2 }}
86-
port: ${{ secrets.PORT }}
87-
passphrase: ${{ secrets.PASSPHRASE }}
176+
host: ${{ env.REMOTE_HOST }}
177+
username: linuxserver.io
178+
key: ${{ env.PRIVATE_KEY }}
179+
port: 2222
180+
passphrase: 1234
88181
script: |
89182
whoami
90183
ls -al
91184
92-
- name: use insecure cipher
185+
- name: missing ssh key passphrase
93186
uses: ./
187+
continue-on-error: true
94188
with:
95-
host: ${{ secrets.HOST }}
96-
username: ${{ secrets.USERNAME }}
97-
password: ${{ secrets.PASSWORD }}
98-
port: ${{ secrets.PORT }}
189+
host: ${{ env.REMOTE_HOST }}
190+
username: linuxserver.io
191+
key: ${{ env.PRIVATE_KEY }}
192+
port: 2222
99193
script: |
100-
ls \
101-
-lah
102-
use_insecure_cipher: true
194+
whoami
195+
ls -al
103196
104197
# https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
105198
- name: Multiline SSH commands interpreted as single lines
106199
uses: ./
107200
with:
108-
host: ${{ secrets.HOST }}
109-
username: ${{ secrets.USERNAME }}
110-
password: ${{ secrets.PASSWORD }}
111-
port: ${{ secrets.PORT }}
201+
host: ${{ env.REMOTE_HOST }}
202+
username: linuxserver.io
203+
key: ${{ env.PRIVATE_KEY }}
204+
port: 2222
205+
passphrase: 1234
112206
script_stop: true
113207
script: |
114208
ls \
115209
-lah
116210
use_insecure_cipher: true
117211

212+
multiple-server:
213+
runs-on: ubuntu-latest
214+
steps:
215+
- name: Checkout code
216+
uses: actions/checkout@v4
217+
218+
- name: add public key to env
219+
run: |
220+
echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
221+
cat testdata/.ssh/id_passphrase.pub >> $GITHUB_ENV
222+
echo "EOF" >> $GITHUB_ENV
223+
echo "======= public key ========="
224+
cat testdata/.ssh/id_passphrase.pub
225+
echo "============================"
226+
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
227+
cat testdata/.ssh/id_passphrase >> $GITHUB_ENV
228+
echo "EOF" >> $GITHUB_ENV
229+
echo "======= private key ========="
230+
cat testdata/.ssh/id_passphrase
231+
echo "============================"
232+
233+
- name: create new ssh server
234+
run: |
235+
docker run -d \
236+
--name=openssh-server-01 \
237+
--hostname=openssh-server-01 \
238+
-p 2222:2222 \
239+
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
240+
-e SUDO_ACCESS=false \
241+
-e PASSWORD_ACCESS=true \
242+
-e USER_PASSWORD=password \
243+
-e USER_NAME=linuxserver.io \
244+
--restart unless-stopped \
245+
lscr.io/linuxserver/openssh-server:latest
246+
docker exec openssh-server-01 sh -c "hostname -i" > ip01.txt
247+
echo "REMOTE_HOST_01<<EOF" >> $GITHUB_ENV
248+
cat ip01.txt >> $GITHUB_ENV
249+
echo "EOF" >> $GITHUB_ENV
250+
echo "======= container ip address ========="
251+
cat ip01.txt
252+
echo "======================================"
253+
254+
docker run -d \
255+
--name=openssh-server-02 \
256+
--hostname=openssh-server-02 \
257+
-p 2223:2222 \
258+
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
259+
-e SUDO_ACCESS=false \
260+
-e PASSWORD_ACCESS=true \
261+
-e USER_PASSWORD=password \
262+
-e USER_NAME=linuxserver.io \
263+
--restart unless-stopped \
264+
lscr.io/linuxserver/openssh-server:latest
265+
docker exec openssh-server-02 sh -c "hostname -i" > ip02.txt
266+
echo "REMOTE_HOST_02<<EOF" >> $GITHUB_ENV
267+
cat ip02.txt >> $GITHUB_ENV
268+
echo "EOF" >> $GITHUB_ENV
269+
echo "======= container ip address ========="
270+
cat ip02.txt
271+
echo "======================================"
272+
273+
sleep 2
274+
118275
# https://github.com/appleboy/ssh-action/issues/85
119276
- name: Deployment to multiple hosts with different ports
120277
uses: ./
121278
with:
122-
host: "${{ secrets.HOST }}:${{ secrets.PORT }}"
123-
username: ${{ secrets.USERNAME }}
124-
password: ${{ secrets.PASSWORD }}
125-
port: 1024
279+
host: "${{ env.REMOTE_HOST_01 }}:2222,${{ env.REMOTE_HOST_02 }}:2222"
280+
username: linuxserver.io
281+
key: ${{ env.PRIVATE_KEY }}
282+
passphrase: 1234
126283
script_stop: true
127284
script: |
128-
ls \
129-
-lah
130-
use_insecure_cipher: true
285+
whoami
131286
132-
# - name: SSH ED25519 Private Key
133-
# uses: ./
134-
# with:
135-
# host: ${{ secrets.TUNNEL_HOST }}
136-
# username: ${{ secrets.TUNNEL_USERNAME }}
137-
# key: ${{ secrets.ID_ED25519 }}
138-
# port: ${{ secrets.TUNNEL_PORT }}
139-
# script: whoami
140-
141-
testing02:
142-
name: testing with envs
287+
support-ed25519-key:
143288
runs-on: ubuntu-latest
144289
steps:
145-
- name: checkout
290+
- name: Checkout code
146291
uses: actions/checkout@v4
147292

293+
- name: add public key to env
294+
run: |
295+
echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
296+
cat testdata/.ssh/id_ed25519.pub >> $GITHUB_ENV
297+
echo "EOF" >> $GITHUB_ENV
298+
echo "======= public key ========="
299+
cat testdata/.ssh/id_ed25519.pub
300+
echo "============================"
301+
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
302+
cat testdata/.ssh/id_ed25519 >> $GITHUB_ENV
303+
echo "EOF" >> $GITHUB_ENV
304+
echo "======= private key ========="
305+
cat testdata/.ssh/id_ed25519
306+
echo "============================"
307+
308+
- name: create new ssh server
309+
run: |
310+
docker run -d \
311+
--name=openssh-server \
312+
--hostname=openssh-server \
313+
-p 2222:2222 \
314+
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
315+
-e SUDO_ACCESS=false \
316+
-e PASSWORD_ACCESS=true \
317+
-e USER_PASSWORD=password \
318+
-e USER_NAME=linuxserver.io \
319+
--restart unless-stopped \
320+
lscr.io/linuxserver/openssh-server:latest
321+
docker exec openssh-server sh -c "hostname -i" > ip.txt
322+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
323+
cat ip.txt >> $GITHUB_ENV
324+
echo "EOF" >> $GITHUB_ENV
325+
echo "======= container ip address ========="
326+
cat ip.txt
327+
echo "======================================"
328+
sleep 2
329+
330+
- name: testing id_ed25519 key
331+
uses: ./
332+
with:
333+
host: ${{ env.REMOTE_HOST }}
334+
username: linuxserver.io
335+
key: ${{ env.PRIVATE_KEY }}
336+
port: 2222
337+
script: |
338+
whoami
339+
ls -al
340+
341+
testing-with-env:
342+
runs-on: ubuntu-latest
343+
steps:
344+
- name: Checkout code
345+
uses: actions/checkout@v4
346+
347+
- name: add public key to env
348+
run: |
349+
echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
350+
cat testdata/.ssh/id_ed25519.pub >> $GITHUB_ENV
351+
echo "EOF" >> $GITHUB_ENV
352+
echo "======= public key ========="
353+
cat testdata/.ssh/id_ed25519.pub
354+
echo "============================"
355+
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
356+
cat testdata/.ssh/id_ed25519 >> $GITHUB_ENV
357+
echo "EOF" >> $GITHUB_ENV
358+
echo "======= private key ========="
359+
cat testdata/.ssh/id_ed25519
360+
echo "============================"
361+
362+
- name: create new ssh server
363+
run: |
364+
docker run -d \
365+
--name=openssh-server \
366+
--hostname=openssh-server \
367+
-p 2222:2222 \
368+
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
369+
-e SUDO_ACCESS=true \
370+
-e PASSWORD_ACCESS=true \
371+
-e USER_NAME=linuxserver.io \
372+
--restart unless-stopped \
373+
lscr.io/linuxserver/openssh-server:latest
374+
docker exec openssh-server sh -c "hostname -i" > ip.txt
375+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
376+
cat ip.txt >> $GITHUB_ENV
377+
echo "EOF" >> $GITHUB_ENV
378+
echo "======= container ip address ========="
379+
cat ip.txt
380+
echo "======================================"
381+
sleep 2
382+
383+
- name: testing id_ed25519 key
384+
uses: ./
385+
with:
386+
host: ${{ env.REMOTE_HOST }}
387+
username: linuxserver.io
388+
key: ${{ env.PRIVATE_KEY }}
389+
port: 2222
390+
script: |
391+
whoami
392+
ls -al
393+
148394
- name: pass environment
149395
uses: ./
150396
env:
151397
FOO: "BAR"
152398
with:
153-
host: ${{ secrets.HOST }}
154-
username: ${{ secrets.USERNAME }}
155-
key: ${{ secrets.KEY }}
156-
port: ${{ secrets.PORT }}
399+
host: ${{ env.REMOTE_HOST }}
400+
username: linuxserver.io
401+
key: ${{ env.PRIVATE_KEY }}
402+
port: 2222
157403
envs: FOO
158404
script: |
159405
echo "I am $FOO, thanks"
@@ -167,28 +413,27 @@ jobs:
167413
SHA: ${{ github.sha }}
168414
PORT: ${{ secrets.PORT }}
169415
with:
170-
host: ${{ secrets.HOST }}
171-
username: ${{ secrets.USERNAME }}
172-
key: ${{ secrets.KEY }}
173-
port: ${{ secrets.PORT }}
416+
host: ${{ env.REMOTE_HOST }}
417+
username: linuxserver.io
418+
key: ${{ env.PRIVATE_KEY }}
419+
port: 2222
174420
envs: FOO,BAR,SHA,PORT
175421
script: |
176422
echo "I am $FOO, thanks"
177423
echo "I am $BAR, thanks"
178424
echo "sha: $SHA"
179425
echo "port: $PORT"
180-
sh test.sh
181426
182427
- name: custom envs format
183428
uses: ./
184429
env:
185430
FOO: "BAR"
186431
AAA: "BBB"
187432
with:
188-
host: ${{ secrets.HOST }}
189-
username: ${{ secrets.USERNAME }}
190-
key: ${{ secrets.KEY }}
191-
port: ${{ secrets.PORT }}
433+
host: ${{ env.REMOTE_HOST }}
434+
username: linuxserver.io
435+
key: ${{ env.PRIVATE_KEY }}
436+
port: 2222
192437
envs: FOO,BAR,AAA
193438
envs_format: export TEST_{NAME}={VALUE}
194439
script: |
@@ -203,79 +448,24 @@ jobs:
203448
INPUT_FOO: "BAR"
204449
INPUT_AAA: "BBB"
205450
with:
206-
host: ${{ secrets.HOST }}
207-
username: ${{ secrets.USERNAME }}
208-
key: ${{ secrets.KEY }}
209-
port: ${{ secrets.PORT }}
451+
host: ${{ env.REMOTE_HOST }}
452+
username: linuxserver.io
453+
key: ${{ env.PRIVATE_KEY }}
454+
port: 2222
210455
allenvs: true
211456
script: |
212457
echo "I am $INPUT_FOO, thanks"
213458
echo "I am $INPUT_AAA, thanks"
214459
echo "$GITHUB_BASE_REF"
215460
echo "$GITHUB_REF"
216461
217-
testing03:
218-
name: git clone and pull
219-
runs-on: ubuntu-latest
220-
steps:
221-
- name: checkout
222-
uses: actions/checkout@v4
223-
224-
- name: clone private repository
225-
uses: ./
226-
with:
227-
host: ${{ secrets.HOST }}
228-
username: ${{ secrets.USERNAME }}
229-
key: ${{ secrets.KEY }}
230-
port: ${{ secrets.PORT }}
231-
script_stop: true
232-
script: |
233-
git clone https://appleboy:${{ secrets.TEST_TOKEN }}@github.com/go-training/self-runner.git test_repository
234-
rm -rf test_repository
235-
236-
testing04:
237-
name: docker login and pull
238-
runs-on: ubuntu-latest
239-
steps:
240-
- name: checkout
241-
uses: actions/checkout@v4
242-
243-
- name: login GitHub Container Registry
244-
uses: ./
245-
with:
246-
host: ${{ secrets.HOST }}
247-
username: ${{ secrets.USERNAME }}
248-
key: ${{ secrets.KEY }}
249-
port: ${{ secrets.PORT }}
250-
script_stop: true
251-
script: |
252-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u github.actor --password-stdin
253-
254-
- name: login DockerHub Container Registry
255-
uses: ./
256-
with:
257-
host: ${{ secrets.HOST }}
258-
username: ${{ secrets.USERNAME }}
259-
key: ${{ secrets.KEY }}
260-
port: ${{ secrets.PORT }}
261-
script_stop: true
262-
script: |
263-
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
264-
265-
testing05:
266-
name: switch user
267-
runs-on: ubuntu-latest
268-
steps:
269-
- name: checkout
270-
uses: actions/checkout@v4
271-
272462
- name: switch to root user
273463
uses: ./
274464
with:
275-
host: ${{ secrets.HOST }}
276-
username: ${{ secrets.USERNAME }}
277-
key: ${{ secrets.KEY }}
278-
port: ${{ secrets.PORT }}
465+
host: ${{ env.REMOTE_HOST }}
466+
username: linuxserver.io
467+
key: ${{ env.PRIVATE_KEY }}
468+
port: 2222
279469
script_stop: true
280470
request_pty: true
281471
command_timeout: 30s

‎.github/workflows/ssh-server.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: openssh-server
1+
name: testing stable version
22

33
on: [push]
44

0 commit comments

Comments
 (0)
Please sign in to comment.