-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
78 lines (69 loc) · 2.35 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: 'Docker context over SSH'
description: 'Create a docker context over SSH authentication'
author: 'Amir Marmul'
inputs:
ssh-host:
description: 'ssh host'
required: true
ssh-username:
description: 'ssh username'
required: true
ssh-private-key:
description: 'content of ssh private key. ex raw content of ~/.ssh/id_rsa'
required: true
ssh-passphrase:
description: 'passphrase for private key, optional'
required: false
ssh-port:
description: 'ssh port, default 22'
required: false
default: 22
ssh-socket:
description: 'ssh socket, default /tmp/ssh-auth.sock'
required: false
default: '/tmp/ssh-auth.sock'
context-name:
description: 'name of docker context. default: remote'
required: true
default: 'remote'
context-use:
description: 'indicate which this context is set as docker current context. default: false'
required: false
default: 'false'
runs:
using: 'composite'
steps:
- shell: bash
name: Create the required directory
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh
- shell: bash
name: Add the private key
run: |
echo "${{ inputs.ssh-private-key }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- shell: bash
name: Add the host to the known_hosts file
run: ssh-keyscan -p "${{ inputs.ssh-port }}" "${{ inputs.ssh-host }}" > ~/.ssh/known_hosts
- shell: bash
name: Create the docker context
run: docker context create ${{ inputs.context-name }} --docker "host=ssh://${{ inputs.ssh-username}}@${{ inputs.ssh-host }}:${{ inputs.ssh-port }}"
- shell: bash
name: Start the ssh agent and set the environment variables
run: |
ssh-agent -a "${{ inputs.ssh-port }}"
echo "SSH_AUTH_SOCK=${{ inputs.ssh-port}}" >> $GITHUB_ENV
echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV
- shell: bash
# https://unix.stackexchange.com/a/571756/559668
name: Run ssh-add with passphrase
if: ${{ inputs.ssh-passphrase }}
run: |
{ sleep 1; echo ${{ inputs.ssh-passphrase }}; } | script -q /dev/null -c 'ssh-add'
- shell: bash
name: Set the context as current context
run: if [ "${{ inputs.context-use }}" == "true" ]; then docker context use "${{ inputs.context-name }}"; fi
branding:
icon: 'anchor'
color: 'gray-dark'