Skip to content

Commit

Permalink
Update README file to also include instructions about Docker image us…
Browse files Browse the repository at this point in the history
…age.
  • Loading branch information
ericof committed Aug 15, 2022
1 parent 67ddd9b commit 2d32111
Showing 1 changed file with 106 additions and 49 deletions.
155 changes: 106 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,46 @@
</p>

<h1 align="center">
Docker Stack Deploy Action
Docker Stack Deploy Tool
</h1>

<div align="center">

[![GitHub Actions Marketplace](https://img.shields.io/badge/action-marketplace-blue.svg?logo=github&color=orange)](https://github.com/marketplace/actions/docker-stack-deploy-action)
[![Release version badge](https://img.shields.io/github/v/release/kitconcept/docker-stack-deploy)](https://github.com/kitconcept/docker-stack-deploy/release)

![GitHub Repo stars](https://img.shields.io/github/stars/kitconcept/docker-stack-deploy?style=flat-square)
[![license badge](https://img.shields.io/github/license/kitconcept/docker-stack-deploy)](./LICENSE)

GitHub Action and Docker image used to deploy a Docker stack on a Docker Swarm.

## Inputs

## `registry`

When using private images, specify which registry to login to. If no value is provided, we fallback to Docker Hub.

To use GitHub Container registry, set the value to **ghcr.io**.

## `username`

When using private images, specify username to be used to log in.

## `password`

When using private images, specify password to be used to log in.

## `remote_host`

**Required** Hostname or address of the machine running the Docker Swarm manager node.

## `remote_port`

SSH port to connect on the the machine running the Docker Swarm manager node.

**Default value**: 22

## `remote_user`

**Required** User with SSH and Docker privileges on the machine running the Docker Swarm manager node.

## `remote_private_key`

**Required** Private key used for ssh authentication.
</div>

## `deploy_timeout`

Seconds, to wait until the deploy finishes.
GitHub Action and Docker image used to deploy a Docker stack on a Docker Swarm.

**Default value**: 300

## `stack_file`
## Configuration options

**Required** Path to the stack file used in the deploy.
| GitHub Action Input | Environment Variable | Summary | Required | Default Value |
| --- | --- | --- | --- | --- |
| `registry` | `REGISTRY` | Specify which container registry to login to. | |
| `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_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** |
| `stack_file` | `STACK_FILE` | Path to the stack file used in the deploy. || |
| `stack_name` | `STACK_NAME` | Name of the stack to be deployed. || |
| `debug` | `DEBUG` | Verbose logging | | **0** |

## `stack_name`

**Required** Name of the stack to be deployed.
## Using the GitHub Action

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

## Examples
### Examples

### Deploying public images
#### Deploying public images


```yaml
Expand All @@ -86,7 +64,7 @@ jobs:
uses: actions/checkout@v2

- name: Deploy
uses: kitconcept/[email protected].0
uses: kitconcept/[email protected].1
with:
remote_host: ${{ secrets.REMOTE_HOST }}
remote_user: ${{ secrets.REMOTE_USER }}
Expand All @@ -95,7 +73,7 @@ jobs:
stack_name: "plone-staging"
```
### Deploying private images from GitHub Container Registry
#### Deploying private images from GitHub Container Registry
First, follow the steps to [create a Personal Access Token](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry).
Expand All @@ -116,7 +94,7 @@ jobs:
uses: actions/checkout@v2

- name: Deploy
uses: kitconcept/[email protected].0
uses: kitconcept/[email protected].1
with:
registry: "ghcr.io"
username: ${{ secrets.GHCR_USERNAME }}
Expand All @@ -128,6 +106,85 @@ jobs:
stack_name: "plone-live"
```
## Using the Docker Image
It is possible to directly use the `ghcr.io/kitconcept/docker-stack-deploy` Docker image, passing the configuration options as environment variables.

### Examples

#### Local machine

Considering you have a local file named `.env_deploy` with content:

```
REGISTRY=hub.docker.com
USERNAME=foo_usr
PASSWORD=averylargepasswordortoken
REMOTE_HOST=192.168.17.2
REMOTE_PORT=22
REMOTE_USER=user
STACK_FILE=path/to/stack.yml
STACK_NAME=mystack
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)"
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:

```yaml
image: busybox:latest
services:
- docker:20.10.16-dind
before_script:
- docker info
deploy:
stage: deploy
varibles:
REGISTRY: ${REGISTRY}
USERNAME: ${REGISTRY_USER}
PASSWORD: ${REGISTRY_PASSWORD}
REMOTE_HOST: ${DEPLOY_HOST}
REMOTE_PORT: 22
REMOTE_USER: ${DEPLOY_USER}
REMOTE_PRIVATE_KEY: "${DEPLOY_KEY}"
STACK_FILE: stacks/app.yml
STACK_NAME: app
DEPLOY_IMAGE: ghcr.io/kitconcept/docker-stack-deploy:latest
script:
- docker pull ${DEPLOY_IMAGE}
- docker run --rm
-v "$(pwd)":/github/workspace
-v /var/run/docker.sock:/var/run/docker.sock
-e REGISTRY=${REGISTRY}
-e USERNAME=${USERNAME}
-e PASSWORD=${PASSWORD}
-e REMOTE_HOST=${REMOTE_HOST}
-e REMOTE_PORT=${REMOTE_PORT}
-e REMOTE_USER=${REMOTE_USER}
-e REMOTE_PRIVATE_KEY="${REMOTE_PRIVATE_KEY}"
-e STACK_FILE=${STACK_FILE}
-e STACK_NAME=${STACK_NAME}
-e DEBUG=1
${DEPLOY_IMAGE}
```

## Contribute

- [Issue Tracker](https://github.com/kitconcept/docker-stack-deploy/issues)
Expand Down

0 comments on commit 2d32111

Please sign in to comment.