Git Product home page Git Product logo

docker-deploy-webhook's Introduction

Docker Deploy Webhook

A web service for automated deployment of releases from Docker Hub to a Docker Swarm, triggered by a Docker Hub webhook (which can in turn be triggred by pushing to GitHub).

screen shot 2018-02-02 at 18 55 18

Flow for automated deployment:

  • Configure Docker Hub to build an image when a GitHub repository is updated.
  • Configure Docker Hub to call this service via webhook when a new image is available.
  • Configure and deploy this service to your Docker Swarm cluster.
  • When a new image is built, it will update the Docker Service in the Swarm.

This webhook is intended for use with private Docker Hub repositories and self hosted Docker Swarm instances.

To get started, clone this repository, add an image of it to your Docker Hub account, configure config.json and deploy it to your Docker Swarm as a service (see steps below).

Read more about this service in this blog post.

Configuration

Supported environment variables:

PORT="8080" // Port to run on
CONFIG="production" // Which part of the config.json file to load
TOKEN="123-456-ABC-DEF" // A token used to restrict access to the webhook
USERNAME="docker-hub-username" // A Docker Hub account username
PASSWORD="docker-hub-password" // A Docker Hub account password

The config.json file defines each environment:

{
  "production": {},
  "development": {}
}

Inside each environment config is the name of an image and tag to listen for, and the service that should be updated to run it:

{
  "production": {
    "my-org/my-repo:latest": {
      "service": "my-docker-service"
    }
  },
  "development": {
    "my-org/my-repo:development": {
      "service": "my-docker-service"
    }
  }
}

You can use the CONFIG environment variable to tell docker-deploy-webhook which section to use when it loads - this is useful if you have multiple Docker Swarm instances - e.g. production, development.

You use the same callback URL for all services, when docker-deploy-webhook receives an update for an image and tag is it is configured for it will push that release to the service associated with it in config.json.

Deploy to Docker Swarm

swarm-manager000000> docker login
swarm-manager000000> docker service create \
--name docker-deploy-webhook \
--with-registry-auth \
--constraint "node.role==manager" \
--publish=8080:8080 \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
-e PORT="8080" \
-e CONFIG="production" \
-e TOKEN="123456ABCDEF" \
-e USERNAME="docker-hub-username" \
-e PASSWORD="docker-hub-password" \
your-org-name/decoders-deploy-webhook:latest

Note: This example exposes the service directly on port 8080.

Configure Docker Hub to use Webhook

Use the "Create automated build" option in Docker Hub to automatically build an image in Docker Hub when changes are pushed to a GitHub repository, then add a webhook to the Docker Hub image repository.

The URL to specify for the webhook in Docker Hub will be ${your-server}/webhook/${your-token}.

e.g. https://example.com/webhook/123456ABCDEF

You can configure multiple webhooks for a Docker Hub repository (e.g. one webhook on your production cluster, one on development, etc).

While all webhooks will receive the callback, the specific image that has just been built (e.g. :latest, :edge, etc.) will only be deployed to an environment if the webhook service running on it has it whitelisted in the config.json block for that environment.

Testing

To test locally with the example payload:

curl -v -H "Content-Type: application/json" --data @payload.json  http://localhost:3000/webhook/123456ABCDEF

To test in production with the example payload:

curl -v -H "Content-Type: application/json" --data @payload.json https://example.com/webhook/123456ABCDEF

docker-deploy-webhook's People

Contributors

bopoha avatar iaincollins avatar levino avatar raaymax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

docker-deploy-webhook's Issues

Suggest creating DockerHub accounts with read-only access

As far as I can tell I have to give the service the login for docker hub. Is there no way to have a less permissive authentication method? If this service gets hacked, you have a real problem. Especially if third parties use your images.

webhook and gitlab

Hello,

i'm a absolute begginner in docker.
My simple question is:
Can i use gitlab for the docker-deploy-webhook ?

Your sincerly

Stephan

No license

Can you consider adding a OSS license to this project. I would like to make an adjustment to it for my own needs, but without license, I won't do it.

Thanks in advance
~InDieTasten

Do we want a simple web based management UI?

I could do a very simple web based management UI to view the status of deployments.

It could provide status info, with a list of last deploys for each service and a button to trigger a deployment and restart a service. It could tell you if a service or image could not be found.

It could also provide buttons for other actions like 'downloading an image of a host for backup' (useful for instances that are databases and don't use shared storage; an actual use case I have).

It could easily store the data in simple SQL lite / neDB database as the amount of data would be small.

As it's just for debugging / administration the data store could be transient (and just store the data in it's local DB) or you could give it a shared volume if you wanted that info to persist.

We could also make this how the app is configured - and have it write/ it's configuration info to a JSON file that lives on the host it's running on (with an option to view / download it for backup).

This would mean you would not have to fork the repo just to deploy an instance as the config would be outside the app.

( Interested in your thoughts on this @imjosh !)

I don't want to replicate the functionality of something like Portainer so would have authentication maybe use basic auth and environment variable or a simple .htaccess file for users.

Would love feedback on if this is - or isn't - a thing people care about, and if they do, where we should draw the line.

Optional credentials

As far as I can see, the only reason for having to provide credentials for this software is to be able to pull images from private repos on docker hub.

Would it be possible to make the software not crash, but skip docker login, if the credentials are omitted? This way, one wouldn't have expose credentials and having to keep them updated, if passwords change, etc.

How to call docker-deploy-webhook service

Can you give details on the below points on how to call docker-deploy-webhook to execute the docker commands when the whitelisted images in config.json are refreshed.

  • Configure Docker Hub to call this service via webhook when a new image is available.
  • Configure and deploy this service to your Docker Swarm cluster.

I have created webhook for whitelisted images but couldn't link to call docker-deploy-webhook service.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.