Skip to content

Commit c9a5a80

Browse files
committed
Support Docker secrets
1 parent 39723b7 commit c9a5a80

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
uses: ./action
3939
with:
4040
compose-file: action/docker-compose.test.yml
41+
secrets: |
42+
- name: secret
43+
value: ${{ secrets.SECRET }}
4144
stack-name: david
4245
ssh-user-at-host: [email protected]
4346
ssh-port: 2222

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ jobs:
3737
compose-file: docker-compose.yml
3838
stack-name: my-app
3939
ssh-user-at-host: [email protected]
40+
secrets: |
41+
- name: secret
42+
value: ${{ secrets.SECRET }}
4043
```
4144
4245
## Inputs
4346
44-
| Name | Description |
45-
|--------------------|----------------------------------------------------------------|
46-
| `compose-file` | Path to your docker compose definition inside the repository. |
47-
| `stack-name` | Name of the Docker Stack that shoud be created on your server. |
48-
| `ssh-user-at-host` | User@host to connect to (e.g. `[email protected]`) |
49-
| `ssh-port` | SSH port to connect to. Defaults to 22 if not defined. |
47+
| Name | Description |
48+
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
49+
| `compose-file` | Path to your docker compose definition inside the repository. |
50+
| `secrets` | Allows to define a YAML array of Docker secrets which should be created (not required). You need to define it as a multiline YAML string, as this is technically not supported by Actions directly. |
51+
| `stack-name` | Name of the Docker Stack that shoud be created on your server. |
52+
| `ssh-user-at-host` | User@host to connect to (e.g. `[email protected]`) |
53+
| `ssh-port` | SSH port to connect to. Defaults to 22 if not defined. |
5054

5155
## License
5256

action.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ inputs:
1313
description: 'Path to the docker-compose file'
1414
required: true
1515

16+
secrets:
17+
description: "Docker secrets to create during the stack"
18+
required: false
19+
1620
stack-name:
1721
description: 'Name of the stack to deploy'
1822
required: true
1923

2024
ssh-user-at-host:
2125
description: 'User@host to connect to'
2226
required: true
23-
27+
2428
ssh-port:
2529
description: "Port to connect to with SSH"
2630
required: false
@@ -43,6 +47,18 @@ runs:
4347
run: docker node ls || docker swarm init
4448
shell: bash
4549

50+
- name: Create secrets
51+
run: |
52+
echo "${{ inputs.secrets }}" | yq e '.[]' - | while IFS= read -r line; do
53+
secret_name=$(echo "$line" | yq e '.name' -)
54+
secret_value=$(echo "$line" | yq e '.value' -)
55+
56+
# Execute the Docker secret command
57+
docker secret inspect "$secret_name" > /dev/null 2>&1 || echo "$secret_value" | docker secret create "$secret_name" -
58+
done
59+
shell: bash
60+
if: "${{ inputs.secrets != '' }}"
61+
4662
- name: Pull docker-stack-wait image
4763
run: docker pull sudobmitch/docker-stack-wait:v0.2.5
4864
shell: bash

docker-compose.test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ services:
44
web:
55
image: "hashicorp/http-echo"
66
command: ["-listen", ":8080", "-text", "Hello World"]
7+
secrets:
8+
- secret
79
ports:
810
- 8080:8080
11+
12+
secrets:
13+
secret:
14+
external: true

0 commit comments

Comments
 (0)