5
5
[ ![ GitHub Last Commit] ( https://img.shields.io/github/last-commit/cssnr/stack-deploy-action?logo=github&logoColor=white&label=updated )] ( https://github.com/cssnr/stack-deploy-action/graphs/commit-activity )
6
6
[ ![ Codeberg Last Commit] ( https://img.shields.io/gitea/last-commit/cssnr/stack-deploy-action/master?gitea_url=https%3A%2F%2Fcodeberg.org%2F&logo=codeberg&logoColor=white&label=updated )] ( https://codeberg.org/cssnr/stack-deploy-action )
7
7
[ ![ GitHub Top Language] ( https://img.shields.io/github/languages/top/cssnr/stack-deploy-action?logo=htmx&logoColor=white )] ( https://github.com/cssnr/stack-deploy-action )
8
+ [ ![ GitHub Discussions] ( https://img.shields.io/github/discussions/cssnr/stack-deploy-action )] ( https://github.com/cssnr/stack-deploy-action/discussions )
8
9
[ ![ GitHub Forks] ( https://img.shields.io/github/forks/cssnr/stack-deploy-action?style=flat&logo=github )] ( https://github.com/cssnr/stack-deploy-action/forks )
9
10
[ ![ GitHub Repo Stars] ( https://img.shields.io/github/stars/cssnr/stack-deploy-action?style=flat&logo=github&logoColor=white )] ( https://github.com/cssnr/stack-deploy-action/stargazers )
10
11
[ ![ GitHub Org Stars] ( https://img.shields.io/github/stars/cssnr?style=flat&logo=github&logoColor=white&label=org%20stars )] ( https://cssnr.github.io/ )
20
21
This action deploys a docker stack from a compose file to a remote docker host using SSH Password or Key File Authentication.
21
22
You can also optionally authenticate against a private registry using a username and password.
22
23
24
+ This action uses a remote docker context to deploy the stack from the working directory allowing you to easily prepare the workspace for deployment.
25
+
23
26
For more details see [ action.yaml] ( action.yaml ) and [ src/main.sh] ( src/main.sh ) .
24
27
25
28
** Portainer Users:** You can deploy directly to Portainer with: [ cssnr/portainer-stack-deploy-action] ( https://github.com/cssnr/portainer-stack-deploy-action )
@@ -30,24 +33,38 @@ For more details see [action.yaml](action.yaml) and [src/main.sh](src/main.sh).
30
33
31
34
## Inputs
32
35
33
- | input | required | default | description |
34
- | ------------- | :----------: | --------------------- | --------------------------------- |
35
- | host | ** Yes** | - | Remote Docker hostname |
36
- | port | - | ` 22 ` | Remote Docker port |
37
- | user | ** Yes** | - | Remote Docker username |
38
- | pass | or ` ssh_key ` | - | Remote Docker password \* |
39
- | ssh_key | or ` pass ` | - | Remote SSH Key file \* |
40
- | name | ** Yes** | - | Docker Stack name |
41
- | file | - | ` docker-compose.yaml ` | Docker Compose file |
42
- | env_file | - | - | Docker Environment file |
43
- | registry_auth | - | - | Enable Registry Authentication \* |
44
- | registry_host | - | - | Registry Authentication Host \* |
45
- | registry_user | - | - | Registry Authentication User \* |
46
- | registry_pass | - | - | Registry Authentication Pass \* |
47
- | summary | - | ` true ` | Add Job Summary \* |
36
+ | input | required | default | description |
37
+ | ------------- | :----------: | --------------------- | ----------------------------------------- |
38
+ | name | ** Yes** | - | Docker Stack Name |
39
+ | file | - | ` docker-compose.yaml ` | Docker Compose File |
40
+ | host | ** Yes** | - | Remote Docker Hostname |
41
+ | port | - | ` 22 ` | Remote Docker Port |
42
+ | user | ** Yes** | - | Remote Docker Username |
43
+ | pass | or ` ssh_key ` | - | Remote Docker Password \* |
44
+ | ssh_key | or ` pass ` | - | Remote SSH Key File \* |
45
+ | env_file | - | - | Docker Environment File \* |
46
+ | detach | - | ` true ` | Detach Flag, ` false ` to disable \* |
47
+ | prune | - | ` false ` | Prune Flag, ` true ` to enable |
48
+ | resolve_image | - | ` always ` | Options [ ` always ` , ` changed ` , ` never ` ] \* |
49
+ | registry_auth | - | - | Enable Registry Authentication \* |
50
+ | registry_host | - | - | Registry Authentication Host \* |
51
+ | registry_user | - | - | Registry Authentication Username \* |
52
+ | registry_pass | - | - | Registry Authentication Password \* |
53
+ | summary | - | ` true ` | Add Job Summary \* |
54
+
55
+ For additional details on inputs, see the stack deploy [ documentation] ( https://docs.docker.com/reference/cli/docker/stack/deploy/ ) .
48
56
49
57
** pass/ssh_key** - You must provide either a ` pass ` or ` ssh_key ` .
50
58
59
+ ** env_file** - Variables in this file are exported before running stack deploy.
60
+ To use a docker ` env_file ` specify it in your compose file and make it available in a previous step.
61
+ If you need compose file templating this can also be done in a previous step.
62
+
63
+ ** detach** - Set this to ` false ` to not exit immediately and wait for the services to converge.
64
+ This will generate extra output in the logs and is useful for debugging deployments.
65
+
66
+ ** resolve_image** - When the default ` always ` is used, this argument is omitted.
67
+
51
68
** registry_auth** - Set to ` true ` to deploy with ` --with-registry-auth ` .
52
69
53
70
** registry_host** - To run ` docker login ` on another registry. Example: ` ghcr.io `
@@ -56,16 +73,32 @@ For more details see [action.yaml](action.yaml) and [src/main.sh](src/main.sh).
56
73
57
74
** summary** - Write a Summary for the job. To disable this set to ` false ` .
58
75
76
+ To view a workflow run, click on a recent
77
+ [ Test] ( https://github.com/cssnr/stack-deploy-action/actions/workflows/test.yaml ) job _ (requires login)_ .
78
+
59
79
<details ><summary >👀 View Example Job Summary</summary >
60
80
61
81
---
62
82
63
- 🎉 Stack ` test-stack ` Successfully Deployed.
83
+ 🎉 Stack ` test_stack-deploy ` Successfully Deployed.
84
+
85
+ ``` text
86
+ docker stack deploy --detach=false --resolve-image=changed -c docker-compose.yaml test_stack-deploy
87
+ ```
64
88
65
89
<details ><summary >Results</summary >
66
90
67
91
``` text
68
- Updating service test-stack_alpine (id: ewi9ck5hcdmmvaj8ms0te4t8r)
92
+ Updating service test_stack-deploy_alpine (id: tdk8v42m0rvp9hz4rbfrtszb6)
93
+ 1/1:
94
+ overall progress: 0 out of 1 tasks
95
+ overall progress: 1 out of 1 tasks
96
+ verify: Waiting 5 seconds to verify that tasks are stable...
97
+ verify: Waiting 4 seconds to verify that tasks are stable...
98
+ verify: Waiting 3 seconds to verify that tasks are stable...
99
+ verify: Waiting 2 seconds to verify that tasks are stable...
100
+ verify: Waiting 1 seconds to verify that tasks are stable...
101
+ verify: Service tdk8v42m0rvp9hz4rbfrtszb6 converged
69
102
```
70
103
71
104
</details >
@@ -74,8 +107,24 @@ Updating service test-stack_alpine (id: ewi9ck5hcdmmvaj8ms0te4t8r)
74
107
75
108
</details >
76
109
77
- To view a workflow run, click on a recent
78
- [ Test] ( https://github.com/cssnr/stack-deploy-action/actions/workflows/test.yaml ) job _ (requires login)_ .
110
+ ``` yaml
111
+ - name : ' Stack Deploy'
112
+ uses : cssnr/stack-deploy-action@v1
113
+ with :
114
+ name : ' stack-name'
115
+ file : ' docker-compose-swarm.yaml'
116
+ host : ${{ secrets.DOCKER_HOST }}
117
+ port : ${{ secrets.DOCKER_PORT }}
118
+ user : ${{ secrets.DOCKER_USER }}
119
+ pass : ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
120
+ ssh_key : ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
121
+ ` ` `
122
+
123
+ ## Examples
124
+
125
+ 💡 _Click on a heading to expand or collapse an example._
126
+
127
+ <details open><summary>With password, docker login and --with-registry-auth</summary>
79
128
80
129
` ` ` yaml
81
130
- name : ' Stack Deploy'
@@ -87,9 +136,33 @@ To view a workflow run, click on a recent
87
136
port : ${{ secrets.DOCKER_PORT }}
88
137
user : ${{ secrets.DOCKER_USER }}
89
138
pass : ${{ secrets.DOCKER_PASS }}
139
+ registry_host : ' ghcr.io'
140
+ registry_user : ${{ vars.GHCR_USER }}
141
+ registry_pass : ${{ secrets.GHCR_PASS }}
142
+ ` ` `
143
+
144
+ </details>
145
+
146
+ <details><summary>With SSH key, --prune, --detach=false and --resolve-image=changed</summary>
147
+
148
+ ` ` ` yaml
149
+ - name : ' Stack Deploy'
150
+ uses : cssnr/stack-deploy-action@v1
151
+ with :
152
+ name : ' stack-name'
153
+ file : ' docker-compose-swarm.yaml'
154
+ host : ${{ secrets.DOCKER_HOST }}
155
+ port : ${{ secrets.DOCKER_PORT }}
156
+ user : ${{ secrets.DOCKER_USER }}
157
+ ssh_key : ${{ secrets.DOCKER_SSH_KEY }}
158
+ detach : false
159
+ prune : true
160
+ resolve_image : ' changed'
90
161
` ` `
91
162
92
- Use ` docker login` and enable `--with-registry-auth`
163
+ </details>
164
+
165
+ <details><summary>With All Inputs</summary>
93
166
94
167
` ` ` yaml
95
168
- name : ' Stack Deploy'
@@ -100,15 +173,22 @@ Use `docker login` and enable `--with-registry-auth`
100
173
host : ${{ secrets.DOCKER_HOST }}
101
174
port : ${{ secrets.DOCKER_PORT }}
102
175
user : ${{ secrets.DOCKER_USER }}
103
- pass: ${{ secrets.DOCKER_PASS }}
176
+ pass : ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
177
+ ssh_key : ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
178
+ env_file : ' stack.env'
179
+ detach : true
180
+ prune : false
181
+ resolve_image : ' always'
182
+ registry_auth : true # not needed with registry_pass/registry_user
104
183
registry_host : ' ghcr.io'
105
184
registry_user : ${{ vars.GHCR_USER }}
106
185
registry_pass : ${{ secrets.GHCR_PASS }}
186
+ summary : true
107
187
` ` `
108
188
109
- # # Examples
189
+ </details>
110
190
111
- Simple Example
191
+ <details><summary> Simple Workflow Example</summary>
112
192
113
193
` ` ` yaml
114
194
name : ' Stack Deploy Action'
@@ -137,7 +217,9 @@ jobs:
137
217
pass : ${{ secrets.DOCKER_PASS }}
138
218
` ` `
139
219
140
- Full Example
220
+ </details>
221
+
222
+ <details><summary>Full Workflow Example</summary>
141
223
142
224
` ` ` yaml
143
225
name : ' Stack Deploy Action'
@@ -153,11 +235,15 @@ on:
153
235
env :
154
236
REGISTRY : ' ghcr.io'
155
237
238
+ concurrency :
239
+ group : ${{ github.workflow }}
240
+ cancel-in-progress : true
241
+
156
242
jobs :
157
243
build :
158
244
name : ' Build'
159
245
runs-on : ubuntu-latest
160
- timeout-minutes: 5
246
+ timeout-minutes : 15
161
247
permissions :
162
248
packages : write
163
249
@@ -168,7 +254,7 @@ jobs:
168
254
- name : ' Setup Buildx'
169
255
uses : docker/setup-buildx-action@v2
170
256
with :
171
- platforms: linux/amd64,linux/arm64
257
+ platforms : ' linux/amd64,linux/arm64'
172
258
173
259
- name : ' Docker Login'
174
260
uses : docker/login-action@v3
@@ -181,14 +267,14 @@ jobs:
181
267
id : tags
182
268
uses : smashedr/docker-tags-action@v1
183
269
with :
184
- images: ' $${{ env.REGISTRY }}/${{ github.repository }}'
270
+ images : $${{ env.REGISTRY }}/${{ github.repository }}
185
271
tags : ${{ inputs.tags }}
186
272
187
273
- name : ' Build and Push'
188
274
uses : docker/build-push-action@v6
189
275
with :
190
276
context : .
191
- platforms: linux/amd64,linux/arm64
277
+ platforms : ' linux/amd64,linux/arm64'
192
278
push : true
193
279
tags : ${{ steps.tags.outputs.tags }}
194
280
labels : ${{ steps.tags.outputs.labels }}
@@ -211,9 +297,30 @@ jobs:
211
297
host : ${{ secrets.DOCKER_HOST }}
212
298
port : ${{ secrets.DOCKER_PORT }}
213
299
user : ${{ secrets.DOCKER_USER }}
214
- ssh_key: '${{ secrets.DOCKER_SSH_KEY }}'
300
+ ssh_key : ${{ secrets.DOCKER_SSH_KEY }}
301
+
302
+ cleanup :
303
+ name : ' Cleanup'
304
+ runs-on : ubuntu-latest
305
+ timeout-minutes : 5
306
+ needs : deploy
307
+ permissions :
308
+ contents : read
309
+ packages : write
310
+
311
+ steps :
312
+ - name : ' Purge Cache'
313
+ uses : cssnr/cloudflare-purge-cache-action@v2
314
+ with :
315
+ token : ${{ secrets.CLOUDFLARE_API_TOKEN }}
316
+ zones : cssnr.com
215
317
` ` `
216
318
319
+ </details>
320
+
321
+ For more examples, you can check out other projects using this action:
322
+ https://github.com/cssnr/stack-deploy-action/network/dependents
323
+
217
324
# Support
218
325
219
326
For general help or to request a feature see:
0 commit comments