forked from ArwynFr/actions-docker-context
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
65 lines (51 loc) · 1.94 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
name: docker-context-create
description: Creates a docker context pointing to a remote docker engine using SSH authentication
branding:
icon: 'anchor'
color: 'blue'
inputs:
ssh_cert:
required: false
description: SSH server public key for remote docker authentification
ssh_key:
required: false
description: SSH client private key for remote docker authentification
docker_host:
required: true
description: URL to the remote docker engine in format ssh://[email protected]
context_name:
required: true
description: Name of the remote context on the local docker client
use_context:
required: false
default: 'false'
description: Indicates wether the docker context is set as the curent docker context
runs:
using: composite
steps:
- shell: bash
name: Create ssh directory
run: mkdir --parents $HOME/.ssh
- shell: bash
name: Start SSH Agent
run: |
if [ -z "$SSH_AGENT_PID" ]; then
eval $(ssh-agent)
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
echo "SSH_AGENT_PID=SSH_AGENT_PID" >> $GITHUB_ENV
fi
- shell: bash
name: Configure SSH server public key
run: if [ -n "${{ inputs.ssh_cert }}" ]; then echo "${{ inputs.ssh_cert }}" >> "$HOME/.ssh/known_hosts"; fi
- shell: bash
name: Configure SSH client private key
run: if [ -n "${{ inputs.ssh_key }}" ]; then echo "${{ inputs.ssh_key }}" | ssh-add - ; fi
- shell: bash
name: Remove the docker remote context
run: docker context rm -f "${{ inputs.context_name }}"
- shell: bash
name: Create the docker remote context
run: docker context create "${{ inputs.context_name }}" --docker "host=${{ inputs.docker_host }}"
- shell: bash
name: Set as current context
run: if [ "true" == "${{ inputs.use_context}}" ]; then docker context use "${{ inputs.context_name }}"; fi