Skip to content

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

License

Notifications You must be signed in to change notification settings

kitconcept/docker-stack-deploy

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub Pages Deploy Action Logo

Docker Stack Deploy Tool

GitHub Actions MarketplaceRelease version badge

GitHub Repo starslicense badge

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

Configuration options

GitHub Action InputEnvironment VariableSummaryRequiredDefault Value
registryREGISTRYSpecify which container registry to login to.
usernameUSERNAMEContainer registry username.
passwordPASSWORDContainer registry password.
remote_hostREMOTE_HOSTHostname or address of the machine running the Docker Swarm manager node
remote_portREMOTE_PORTSSH port to connect on the the machine running the Docker Swarm manager node.22
remote_userREMOTE_USERUser with SSH and Docker privileges on the machine running the Docker Swarm manager node.
remote_private_keyREMOTE_PRIVATE_KEYPrivate key used for ssh authentication.
deploy_timeoutDEPLOY_TIMEOUTSeconds, to wait until the deploy finishes600
stack_fileSTACK_FILEPath to the stack file used in the deploy.
stack_nameSTACK_NAMEName of the stack to be deployed.
stack_paramSTACK_PARAMAdditional parameter (env var) to be passed to the stack.
env_fileENV_FILEAdditional environment variables to be passed to the stack.
debugDEBUGVerbose logging0
scale_afterSCALE_AFTERScale a service after a deployment has converged successfully. Example: servicename=1

Using the GitHub Action

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

Examples

Deploying public images

name: Deploy Stagingon: push: branches: - mainjobs: deploy: runs-on: ubuntu-lateststeps: - name: Checkout codebaseuses: actions/checkout@v2 - name: Deployuses: kitconcept/[email protected]with: remote_host: ${{secrets.REMOTE_HOST }}remote_user: ${{secrets.REMOTE_USER }}remote_private_key: ${{secrets.REMOTE_PRIVATE_KEY }}stack_file: "stacks/plone.yml"stack_name: "plone-staging"

Deploying private images from GitHub Container Registry

First, follow the steps to create a Personal Access Token.

name: Deploy Liveon: push: tags: - '*.*.*'jobs: deploy: runs-on: ubuntu-lateststeps: - name: Checkout codebaseuses: actions/checkout@v2 - name: Deployuses: kitconcept/[email protected]with: registry: "ghcr.io"username: ${{secrets.GHCR_USERNAME }}password: ${{secrets.GHCR_TOKEN }}remote_host: ${{secrets.REMOTE_HOST }}remote_user: ${{secrets.REMOTE_USER }}remote_private_key: ${{secrets.REMOTE_PRIVATE_KEY }}stack_file: "stacks/plone.yml"stack_name: "plone-live"stack_param: "foo"

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:

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:

image: busybox:latestservices: - docker:20.10.16-dindbefore_script: - docker infodeploy: stage: deployvaribles: REGISTRY: ${REGISTRY}USERNAME: ${REGISTRY_USER}PASSWORD: ${REGISTRY_PASSWORD}REMOTE_HOST: ${DEPLOY_HOST}REMOTE_PORT: 22REMOTE_USER: ${DEPLOY_USER}REMOTE_PRIVATE_KEY: "${DEPLOY_KEY}"STACK_FILE: stacks/app.ymlSTACK_NAME: appDEPLOY_IMAGE: ghcr.io/kitconcept/docker-stack-deploy:latestscript: - 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

Please DO NOT commit to version branches directly. Even for the smallest and most trivial fix.

ALWAYS open a pull request and ask somebody else to merge your code. NEVER merge it yourself.

Credits

kitconcept GmbH

This repository also uses the docker-stack-wait script, available at GitHub.

The logo is based on rocket icon.

License

The project is licensed under MIT License

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •