GithubHelp home page GithubHelp logo

maccyber / micro-dockerhub-hook Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 22.0 527 KB

Automatic docker deployment with webhooks

JavaScript 89.75% Shell 2.86% Dockerfile 7.39%
dockerhub dockerhub-webhook webhook automated-builds hub-docker-com docker automated-deployment

micro-dockerhub-hook's Introduction

Build Status js-standard-style Coverage Status Code Climate

micro-dockerhub-hook

Automatic docker deployment with webhooks.

micro-dockerhub-hook listens to incoming HTTP POST-requests from hub.docker.com and triggers your specified script(s).

Features

  • Lightweight
  • Pretty simple setup process
  • Can be runned in a docker container
  • Supports updating multiple docker images
  • Scripts can trigger docker or docker-compose
  • Used in production
  • Good logging

Create a token

Create a secret token with openssl, uuidgen or something else. Don't use any slashes since token is going to be used in the URL.

export TOKEN=$(uuidgen)
echo $TOKEN

Installation alternatives

1. Run on host

Install

Nodejs and npm must be installed.

git clone http://github.com/maccyber/micro-dockerhub-hook
cd micro-dockerhub-hook
npm i

Edit config

See config.js

vim config.js

Configure repos and scripts

See scripts/index.js

vim scripts/index.js

Use this format: 'repo/image[:tag]': 'script.sh [parameter1 parameter2]',

tag and parameters are optional.

Remember to chmod +x script.sh

Start micro-dockerhub-hook

npm start

2. Run with docker-compose

Git clone

git clone http://github.com/maccyber/micro-dockerhub-hook

Add secret token in docker.env with

vim docker.env

Start with

docker-compose up -d

3. Run from docker hub

Git clone

git clone http://github.com/maccyber/micro-dockerhub-hook

Start with

docker run -d \
  -p 3000:3000 \
  -e TOKEN=${TOKEN} \
  -v ${PWD}/scripts:/src/scripts \
  -v /var/run/docker.sock:/var/run/docker.sock \
  --name micro-dockerhub-hook \
  maccyber/micro-dockerhub-hook

Configuration on docker hub

Go to https://hub.docker.com/ -> your repo -> Webhooks

Add a webhook like on the following image.

alt tag

Replace example.com with the domain of your server or it's ip address.

Replace abc123 with your secret token.

docker-hook listens to port 3000 by default.

Testing on local machine

Setup the development environment

git clone https://github.com/maccyber/micro-dockerhub-hook/
cd micro-dockerhub-hook
npm i
npm run dev

Run test with curl

curl -i -d @test/data/payload.json http://localhost:3000/$TOKEN

micro-dockerhub-hook's People

Contributors

anshkathuria avatar greenkeeper[bot] avatar maccyber avatar mattiaprimavera avatar mirestrepo avatar renovate-bot avatar rhrn 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

Watchers

 avatar  avatar  avatar  avatar

micro-dockerhub-hook's Issues

Preserve environment when calling scripts

Currently the runScript function creates a fresh environment with only the TAG and REPO_NAME variables. It would be nice if it would instead use the current process.env and just add those extra variables to it. That way useful variables such as PATH will be accessible to deployment scripts.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile
  • mhart/alpine-node 10
npm
package.json
  • micro 9.3.4
  • ava 2.4.0
  • axios 0.19.0
  • coveralls 3.0.5
  • micro-dev 3.0.0
  • nyc 14.1.1
  • standard 13.1.0
  • test-listen 1.1.0
travis
.travis.yml
  • node 8

  • Check this box to trigger a request for Renovate to run again on this repository

Prebuilt Docker images not reading configuration correctly

Does this project still work?
Edit: I tried running the repo using npm run start and this works as expected. I think the docker image is old. I rebuilt it without docker and it appears to run fine.

# Installs docker
# RUN apk add --update --no-cache docker py-pip
# RUN apk add bash bash-doc bash-completion
# RUN pip install docker-compose

Does the docker container still work ?
I tried to run it on docker using my own script and it didn't work. I tried cloning the repo and using docker-compose and that didn't work either.

Payload:

{
  "push_data": {},
  "repository": {
    "repo_name": "maccyber/tagtest:prod"
  }
}

Response:

maccyber/tagtest:prod does not exist in scripts/index.js

Configuration:

const scripts = {
  'maccyber/testhook': 'hello.sh parameter1 parameter2',
  'maccyber/maccyber.io': 'maccyber.io.sh',
  'maccyber/tagtest:prod': 'tag.sh', // repo/image:tag
  'maccyber/fail': 'fail.sh',
  'anshkathuria/tagtest:release-[0-9.]+': 'tag.sh'
}

module.exports = (repoName, tag) => {
  const hook = Object.keys(scripts)
    .find(key => {
      const regex = new RegExp(`^${key}$`, 'gm')
      const image = tag ? `${repoName}:${tag}` : repoName
      const match = image.match(regex)

      return match && match[0] === image
    })

  return scripts[hook]
}

HTTPS support?

It would be cool if there was https support when running this project on the host.

Otherwise the token in the URL is exposed insecurely.

I wouldn't even mind if random self-signed certs would be generated, because all I care about is the URL being encrypted.

documentation bug token vs. TOKEN

the documentation states to run the docker container with
docker run -d
-p 3000:3000
-e TOKEN=${token}
-v ${PWD}/scripts:/src/scripts
-v /var/run/docker.sock:/var/run/docker.sock
--name micro-dockerhub-hook
maccyber/micro-dockerhub-hook

while the token is set in the shell with TOKEN=

doesn't work as $token will be empty

Configure server PORT

It seems the server port used is 3000. In case that port is already used by another service, it would be great to support the possibility to specify a different port :)

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.