Skip to content

Commit 378323e

Browse files
committed
ci: add multi-server support to CI workflow
- Add a new job `multiple-server` to the GitHub Actions workflow - Configure the job to run on `ubuntu-latest` - Add steps to checkout code, add public and private keys to environment variables, and create two new SSH servers using Docker - Update the `host` configuration to include both new SSH servers - Remove the `port` configuration - Replace the command `ls -lah` with `whoami` - Remove the `use_insecure_cipher` configuration Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 815c574 commit 378323e

File tree

1 file changed

+65
-5
lines changed

1 file changed

+65
-5
lines changed

.github/workflows/ssh-server.yml

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,77 @@ jobs:
209209
-lah
210210
use_insecure_cipher: true
211211

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+
212275
# https://github.com/appleboy/ssh-action/issues/85
213276
- name: Deployment to multiple hosts with different ports
214277
uses: appleboy/[email protected]
215278
with:
216-
host: "${{ env.REMOTE_HOST }}:2222"
279+
host: "${{ env.REMOTE_HOST_01 }}:2222,${{ env.REMOTE_HOST_02 }}:2223"
217280
username: linuxserver.io
218281
key: ${{ env.PRIVATE_KEY }}
219-
port: 1111
220282
passphrase: 1234
221283
script_stop: true
222284
script: |
223-
ls \
224-
-lah
225-
use_insecure_cipher: true
285+
whoami

0 commit comments

Comments
 (0)