Skip to content

Commit 1a24432

Browse files
authored
Merge pull request #1 from sdolemelipone/add-ssh-passphrase
2 parents dc2f7d4 + d7a9fc2 commit 1a24432

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See [action.yml](./action.yml) for more detailed information.
1313
* `ssh-port` - ssh port, default 22
1414
* `ssh-username` - ssh username
1515
* `ssh-private-key` - content of ssh private key. ex raw content of ~/.ssh/id_rsa
16+
* `ssh-passphrase` - passphrase for ssh private key. no default.
1617
* `ssh-socket` - ssh socket, default /tmp/ssh-auth.sock
1718
* `context-name` - name of docker context. default: remote
1819
* `context-use` - indicate which this context is set as docker current context. default: false
@@ -32,6 +33,7 @@ jobs:
3233
ssh-host: ${{ secrets.SSH_HOST }}
3334
ssh-username: ${{ secrets.SSH_USERNAME }}
3435
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
36+
ssh-passphrase: ${{ secrets.SSH_PASSPHRASE }}
3537

3638
- name: Inspect docker context
3739
run: docker context ls -q

action.yml

+18-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
ssh-private-key:
1313
description: 'content of ssh private key. ex raw content of ~/.ssh/id_rsa'
1414
required: true
15+
ssh-passphrase:
16+
description: 'passphrase for private key, optional'
17+
required: false
1518
ssh-port:
1619
description: 'ssh port, default 22'
1720
required: false
@@ -37,12 +40,6 @@ runs:
3740
run: |
3841
mkdir -p ~/.ssh
3942
chmod 700 ~/.ssh
40-
41-
- shell: bash
42-
name: Start the ssh agent
43-
run: |
44-
ssh-agent -a "${{ inputs.ssh-socket }}"
45-
export SSH_AUTH_SOCK="${{ inputs.ssh-socket }}"
4643
4744
- shell: bash
4845
name: Add the private key
@@ -55,8 +52,22 @@ runs:
5552
run: ssh-keyscan -p "${{ inputs.ssh-port }}" "${{ inputs.ssh-host }}" > ~/.ssh/known_hosts
5653

5754
- shell: bash
58-
name: Create the docker context
55+
name: Create the docker context
5956
run: docker context create ${{ inputs.context-name }} --docker "host=ssh://${{ inputs.ssh-username}}@${{ inputs.ssh-host }}:${{ inputs.ssh-port }}"
57+
58+
- shell: bash
59+
name: Start the ssh agent and set the environment variables
60+
run: |
61+
ssh-agent -a "${{ inputs.ssh-port }}"
62+
echo "SSH_AUTH_SOCK=${{ inputs.ssh-port}}" >> $GITHUB_ENV
63+
echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV
64+
65+
- shell: bash
66+
# https://unix.stackexchange.com/a/571756/559668
67+
name: Run ssh-add with passphrase
68+
if: ${{ inputs.ssh-passphrase }}
69+
run: |
70+
{ sleep 1; echo ${{ inputs.ssh-passphrase }}; } | script -q /dev/null -c 'ssh-add'
6071
6172
- shell: bash
6273
name: Set the context as current context

0 commit comments

Comments
 (0)