Skip to content

Commit c781418

Browse files
authoredMar 16, 2024··
ci: enhance GitHub Actions for IPv6 and flexibility (#303)
* ci: enhance GitHub Actions for IPv6 and flexibility - Add a new CI job for testing IPv6 in GitHub Actions workflow - Update the Docker image version from `1.7.3` to `1.7.4` - Add a new `protocol` input parameter to the GitHub action with a default value of `tcp` - Change the GitHub action to use a composite run steps action instead of a Docker container - Update the `entrypoint.sh` script to use `bash` instead of `sh`, set stricter error handling, and add a function to detect client platform and architecture - Modify the `entrypoint.sh` script to download a specific version of `drone-ssh` based on the detected client info and execute it Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * ci: refactor CI workflow and Docker setup - Remove IPv6 ping command from CI workflow - Uncomment Docker run configuration in action.yml Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent 8a779a5 commit c781418

File tree

4 files changed

+139
-6
lines changed

4 files changed

+139
-6
lines changed
 

‎.github/workflows/ci.yml

+28
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,31 @@ jobs:
282282
script: |
283283
whoami && echo 'hello world' && touch todo.txt
284284
sudo whoami
285+
286+
testing06:
287+
name: testing ipv6
288+
runs-on: ubuntu-latest
289+
steps:
290+
- name: checkout
291+
uses: actions/checkout@v1
292+
293+
- name: Set up WARP
294+
uses: fscarmen/warp-on-actions@v1.1
295+
with:
296+
stack: dual
297+
298+
- name: testing ipv6 for command
299+
run: |
300+
curl -m 9 --ipv6 --verbose https://google.com
301+
302+
- name: testing ipv6
303+
uses: ./
304+
with:
305+
host: 2402:1f00:8000:800::2628
306+
username: ubuntu
307+
password: ${{ secrets.OVH_PASSWORD }}
308+
protocol: tcp6
309+
port: 22
310+
command_timeout: 30s
311+
script: |
312+
whoami

‎Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/appleboy/drone-ssh:1.7.3
1+
FROM ghcr.io/appleboy/drone-ssh:1.7.4
22

33
COPY entrypoint.sh /bin/entrypoint.sh
44

‎action.yml

+48-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
description: "SSH username."
1414
password:
1515
description: "SSH password."
16+
protocol:
17+
description: 'The IP protocol to use. Valid values are "tcp". "tcp4" or "tcp6". Default to tcp.'
18+
default: "tcp"
1619
sync:
1720
description: "Enable synchronous execution if multiple hosts are involved."
1821
use_insecure_cipher:
@@ -69,9 +72,52 @@ inputs:
6972
description: "pass all environment variable to shell script."
7073
request_pty:
7174
description: "Request a pseudo-terminal from the server."
75+
7276
runs:
73-
using: "docker"
74-
image: "Dockerfile"
77+
using: "composite"
78+
steps:
79+
- name: Set GitHub Path
80+
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
81+
shell: bash
82+
env:
83+
GITHUB_ACTION_PATH: ${{ github.action_path }}
84+
- name: Run entrypoint.sh
85+
run: entrypoint.sh
86+
shell: bash
87+
env:
88+
GITHUB_ACTION_PATH: ${{ github.action_path }}
89+
INPUT_HOST: ${{ inputs.host }}
90+
INPUT_PORT: ${{ inputs.port }}
91+
INPUT_PROTOCOL: ${{ inputs.protocol }}
92+
INPUT_USERNAME: ${{ inputs.username }}
93+
INPUT_PASSWORD: ${{ inputs.password }}
94+
INPUT_PASSPHRASE: ${{ inputs.passphrase }}
95+
INPUT_KEY: ${{ inputs.key }}
96+
INPUT_KEY_PATH: ${{ inputs.key_path }}
97+
INPUT_FINGERPRINT: ${{ inputs.fingerprint }}
98+
INPUT_PROXY_HOST: ${{ inputs.proxy_host }}
99+
INPUT_PROXY_PORT: ${{ inputs.proxy_port }}
100+
INPUT_PROXY_USERNAME: ${{ inputs.proxy_username }}
101+
INPUT_PROXY_PASSWORD: ${{ inputs.proxy_password }}
102+
INPUT_PROXY_PASSPHRASE: ${{ inputs.proxy_passphrase }}
103+
INPUT_PROXY_KEY: ${{ inputs.proxy_key }}
104+
INPUT_PROXY_KEY_PATH: ${{ inputs.proxy_key_path }}
105+
INPUT_PROXY_FINGERPRINT: ${{ inputs.proxy_fingerprint }}
106+
INPUT_TIMEOUT: ${{ inputs.timeout }}
107+
INPUT_PROXY_TIMEOUT: ${{ inputs.proxy_timeout }}
108+
INPUT_COMMAND_TIMEOUT: ${{ inputs.command_timeout }}
109+
INPUT_SCRIPT: ${{ inputs.script }}
110+
INPUT_SCRIPT_STOP: ${{ inputs.script_stop }}
111+
INPUT_ENVS: ${{ inputs.envs }}
112+
INPUT_ENVS_FORMAT: ${{ inputs.envs_format }}
113+
INPUT_DEBUG: ${{ inputs.debug }}
114+
INPUT_ALL_ENVS: ${{ inputs.allenvs }}
115+
INPUT_REQUEST_PTY: ${{ inputs.request_pty }}
116+
INPUT_USE_INSECURE_CIPHER: ${{ inputs.use_insecure_cipher }}
117+
INPUT_CIPHER: ${{ inputs.cipher }}
118+
INPUT_PROXY_USE_INSECURE_CIPHER: ${{ inputs.proxy_use_insecure_cipher }}
119+
INPUT_PROXY_CIPHER: ${{ inputs.proxy_cipher }}
120+
INPUT_SYNC: ${{ inputs.sync }}
75121

76122
branding:
77123
icon: "terminal"

‎entrypoint.sh

+62-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,66 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
set -eu
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
46

57
export GITHUB="true"
68

7-
sh -c "/bin/drone-ssh $*"
9+
DRONE_SSH_RELEASE_URL="${DRONE_SSH_RELEASE_URL:-https://github.com/appleboy/drone-ssh/releases/download}"
10+
DRONE_SSH_VERSION="${DRONE_SSH_VERSION:-1.7.4}"
11+
12+
function detect_client_info() {
13+
if [ -n "${SSH_CLIENT_OS-}" ]; then
14+
CLIENT_PLATFORM="${SSH_CLIENT_OS}"
15+
else
16+
local kernel
17+
kernel="$(uname -s)"
18+
case "${kernel}" in
19+
Darwin)
20+
CLIENT_PLATFORM="darwin"
21+
;;
22+
Linux)
23+
CLIENT_PLATFORM="linux"
24+
;;
25+
Windows)
26+
CLIENT_PLATFORM="windows"
27+
;;
28+
*)
29+
echo "Unknown, unsupported platform: ${kernel}." >&2
30+
echo "Supported platforms: Linux, Darwin and Windows." >&2
31+
echo "Bailing out." >&2
32+
exit 2
33+
esac
34+
fi
35+
36+
if [ -n "${SSH_CLIENT_ARCH-}" ]; then
37+
CLIENT_ARCH="${SSH_CLIENT_ARCH}"
38+
else
39+
# TODO: migrate the kube::util::host_platform function out of hack/lib and
40+
# use it here.
41+
local machine
42+
machine="$(uname -m)"
43+
case "${machine}" in
44+
x86_64*|i?86_64*|amd64*)
45+
CLIENT_ARCH="amd64"
46+
;;
47+
aarch64*|arm64*)
48+
CLIENT_ARCH="arm64"
49+
;;
50+
*)
51+
echo "Unknown, unsupported architecture (${machine})." >&2
52+
echo "Supported architectures x86_64, i686, arm64." >&2
53+
echo "Bailing out." >&2
54+
exit 3
55+
;;
56+
esac
57+
fi
58+
}
59+
60+
detect_client_info
61+
DOWNLOAD_URL_PREFIX="${DRONE_SSH_RELEASE_URL}/v${DRONE_SSH_VERSION}"
62+
CLIENT_BINARY="drone-ssh-${DRONE_SSH_VERSION}-${CLIENT_PLATFORM}-${CLIENT_ARCH}"
63+
echo "Will download ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX}"
64+
curl -fL --retry 3 --keepalive-time 2 "${DOWNLOAD_URL_PREFIX}/${CLIENT_BINARY}" -o ${GITHUB_ACTION_PATH}/drone-ssh
65+
chmod +x ${GITHUB_ACTION_PATH}drone-ssh
66+
sh -c "${GITHUB_ACTION_PATH}/drone-ssh $*"

0 commit comments

Comments
 (0)
Please sign in to comment.