Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 89 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@
GitHub Action and Docker image used to deploy a Docker stack on a Docker Swarm.


## Prerequisites

To use this action or Docker image, you need the following:

- A Docker Swarm manager node reachable over SSH from the GitHub runner or Docker host
- SSH credentials: the private key corresponding to a user account on the Swarm manager node
- The user account must have Docker privileges (typically membership in the `docker` group)
- A stack file (docker-compose YAML format) available in the repository or generated during the workflow
- For private container images: credentials for the container registry where the images are hosted


## Configuration options

| GitHub Action Input | Environment Variable | Summary | Required | Default Value |
| --- | --- | --- | --- | --- |
| `registry` | `REGISTRY` | Specify which container registry to login to. | |
| `registry` | `REGISTRY` | Specify which container registry to login to. | | |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we mention the right values for common options like DockerHub and GHCR here? I was trying to find them recently.

| `username` | `USERNAME` | Container registry username. | | |
| `password` | `PASSWORD` | Container registry password. | | |
| `remote_host` | `REMOTE_HOST` | Hostname or address of the machine running the Docker Swarm manager node | ✅ | |
| `remote_port` | `REMOTE_PORT` | SSH port to connect on the the machine running the Docker Swarm manager node. | | **22** |
| `remote_port` | `REMOTE_PORT` | SSH port to connect on the machine running the Docker Swarm manager node. | | **22** |
| `remote_user` | `REMOTE_USER` | User with SSH and Docker privileges on the machine running the Docker Swarm manager node. | ✅ | |
| `remote_private_key` | `REMOTE_PRIVATE_KEY` | Private key used for ssh authentication. | ✅ | |
| `deploy_timeout` | `DEPLOY_TIMEOUT` | Seconds, to wait until the deploy finishes | | **600** |
Expand All @@ -43,7 +54,7 @@ GitHub Action and Docker image used to deploy a Docker stack on a Docker Swarm.
| `debug` | `DEBUG` | Verbose logging | | **0** |
| `scale_after` | `SCALE_AFTER` | Scale a service after a deployment has converged successfully. Example: servicename=1 | | |

### A note on whitespace
## A note on whitespace

`registry`, `username`, `remote_host`, `remote_port` and `remote_user` cannot
contain whitespace, so any is removed before the value is used, and a line
Expand All @@ -61,6 +72,69 @@ repository UI, and used to surface much later as an opaque
structural in a PEM key, and whitespace can be a legitimate part of a token.


## Optional Parameters

### Registry Authentication

Container registry authentication is skipped when either `username` or `password` is not provided. This is useful when deploying public images that do not require credentials.

### `deploy_timeout`

Specifies the number of seconds to wait for a deployment to converge. The default is 600 seconds (10 minutes). The action polls the remote Docker Swarm manager via SSH to check deployment status using the `docker-stack-wait` script.

```yaml
- name: Deploy
uses: kitconcept/[email protected]
with:
deploy_timeout: "1200"
# ... other inputs
```

### `resolve_image`

Controls whether the action queries the container registry to resolve image digests and supported platforms before deployment. Supported values are:

- `always` (default): Always resolve image metadata
- `changed`: Only resolve for images that have changed since the last deployment
- `never`: Skip image resolution

```yaml
- name: Deploy
uses: kitconcept/[email protected]
with:
resolve_image: "changed"
# ... other inputs
```

### `prune`

When set to `1`, services that are not defined in the stack file are removed from the Swarm. The default is `0` (disabled). Use with caution on shared Swarms.

```yaml
- name: Deploy
uses: kitconcept/[email protected]
with:
prune: "1"
# ... other inputs
```

### `scale_after`

Scales a service to a specific number of replicas after a deployment has converged successfully. Useful when you want to adjust replica counts after initial deployment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really the purpose of it is to scale up a one-off job that should only run after the deployment has converged (like a solr reindex)


```yaml
- name: Deploy
uses: kitconcept/[email protected]
with:
stack_name: "mystack"
scale_after: "mystack_frontend=3 mystack_backend=2"
# ... other inputs
```

The value is passed to `docker service scale`, so use the full Swarm service
name, `<stack_name>_<service>`. Separate several services with spaces.


## Passing values into the stack file

Your stack file can reference environment variables, and `docker stack deploy`
Expand Down Expand Up @@ -142,7 +216,7 @@ case of `env_file` with a name you cannot choose. Prefer `env_file` or

## Using the GitHub Action

Add, or edit an existing, `yaml` file inside `.github/actions` and use the configuration options listed above.
Add, or edit an existing, `yaml` file inside `.github/workflows` and use the configuration options listed above.

### Examples

Expand Down Expand Up @@ -219,7 +293,7 @@ It is possible to directly use the `ghcr.io/kitconcept/docker-stack-deploy` Dock
Considering you have a local file named `.env_deploy` with content:

```
REGISTRY=hub.docker.com
REGISTRY=docker.io
USERNAME=foo_usr
PASSWORD=averylargepasswordortoken
REMOTE_HOST=192.168.17.2
Expand All @@ -232,32 +306,32 @@ DEBUG=1

Run the following command:
```shell
docker run --rm
-v "$(pwd)":/github/workspace
-v /var/run/docker.sock:/var/run/docker.sock
--env-file=.env_deploy
-e REMOTE_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)"
docker run --rm \
-v "$(pwd)":/github/workspace \
-v /var/run/docker.sock:/var/run/docker.sock \
--env-file=.env_deploy \
-e REMOTE_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" \
ghcr.io/kitconcept/docker-stack-deploy:latest
```

#### GitLab CI

On your GitLab project, go to `Settings -> CI/CD` and add the environment variables under **Variables**.

Then edit your `.gitlab-cy.yml` to include the `deploy` step:
Then edit your `.gitlab-ci.yml` to include the `deploy` step:

```yaml
image: busybox:latest

services:
- docker:20.10.16-dind
- docker:29-dind

before_script:
- docker info

deploy:
stage: deploy
varibles:
variables:
REGISTRY: ${REGISTRY}
USERNAME: ${REGISTRY_USER}
PASSWORD: ${REGISTRY_PASSWORD}
Expand Down Expand Up @@ -347,9 +421,10 @@ request that genuinely needs no entry can carry the `skip changelog` label.

[![kitconcept GmbH](https://raw.githubusercontent.com/kitconcept/docker-stack-deploy/main/docs/kitconcept.png)](https://kitconcept.com)

This repository also uses the `docker-stack-wait` script, available at [GitHub](https://github.com/sudo-bmitch/docker-stack-wait).
This repository includes a maintained fork of the `docker-stack-wait` script, originally from [GitHub](https://github.com/sudo-bmitch/docker-stack-wait).

The logo is based on [rocket icon](https://freeicons.io/seo/rocket-icon-24668#).

## License

The project is licensed under [MIT License](./LICENSE)
1 change: 1 addition & 0 deletions news/+readme-fixes.documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved README with clearer instructions, fixed broken examples, and added comprehensive documentation for optional parameters and prerequisites.
Loading