listens for git webhooks and runs bash scripts when they arrive
Go to file
AJ ONeal b98c99fe72 bugfix: git clone correct branch 2020-10-11 10:39:47 +00:00
assets rename to gitdeploy 2020-10-09 09:22:06 +00:00
examples bugfix: git clone correct branch 2020-10-11 10:39:47 +00:00
html rename to gitdeploy 2020-10-09 09:22:06 +00:00
internal rename to gitdeploy 2020-10-09 09:22:06 +00:00
public git-deploy static server with basic options 2020-09-28 01:26:16 -06:00
tools git-deploy static server with basic options 2020-09-28 01:26:16 -06:00
vendor vendor deps 2020-09-28 21:17:23 -06:00
.gitignore rename to gitdeploy 2020-10-09 09:22:06 +00:00
.gitmodules work 2020-09-19 13:59:59 -04:00
.prettierignore work 2020-09-19 13:59:59 -04:00
.prettierrc git-deploy static server with basic options 2020-09-28 01:26:16 -06:00
AUTHORS add exec script 2020-09-28 21:18:35 -06:00
LICENSE add exec script 2020-09-28 21:18:35 -06:00
README.md how to run as system service 2020-10-09 09:44:56 +00:00
bitbucket.go rename to gitdeploy 2020-10-09 09:22:06 +00:00
gitea.go rename to gitdeploy 2020-10-09 09:22:06 +00:00
github.go rename to gitdeploy 2020-10-09 09:22:06 +00:00
go.mod rename to gitdeploy 2020-10-09 09:22:06 +00:00
go.sum handle github and github-like hooks 2020-09-28 21:17:23 -06:00
main.go bugfix remove job 2020-10-09 09:30:48 +00:00

README.md

gitdeploy

gitdeploy is an app for handling continuous deployment of static websites.

Usage

echo 'GITHUB_SECRET=xxxxxxx' >> .env
./gitdeploy init
./gitdeploy run --listen :3000 --serve-path ./overrides --exec ./path/to/script.sh

To manage git credentials see The Vanilla DevOps Git Credentials Cheatsheet

Git Info

The exec script will receive the parent environment as well as

GIT_DEPLOY_JOB_ID=xxxxxx
GIT_REF_NAME=master
GIT_REF_TYPE=branch
GIT_REPO_OWNER=example
GIT_REPO_NAME=example
GIT_CLONE_URL=https://github.com/example/example

Build

pushd html/
npm ci
scripts/build
popd
go mod tidy
go mod vendor
go generate -mod=vendor ./...
go build -mod=vendor .

You can use build tags to remove providers from the build:

go build -mod=vendor -tags nobitbucket,nogithub .

Supported tags are:

  • nogithub
  • nobitbucket

Run as a System Service

sudo env PATH="$PATH" \
  serviceman add --name gitdeploy --system \
    --username app -path "$PATH" -- \
    gitdeploy run --exec ./scripts/

Add Webhooks

To add a webhook you'll first need a secret

with node.js:

crypto.randomBytes(16).toString("hex");

Then you'll need to set up the webhook in your platform of choice.

Github

New Webhook: https://github.com/YOUR_ORG/YOUR_REPO/settings/hooks/new

Payload URL: https://YOUR_DOMAIN/api/webhooks/github
Content-Type: application/json
Secret: YOUR_SECRET
Which events would you like to trigger this webhook?
Just the `push` event.
Active: ✅

Bitbucket

Sometimes Bitbucket does not give you the option to specify the (X-Hub-Signature) secret, so you'll have to append an access_token instead. Example:

Title: gitdeploy
URL: https://YOUR_DOMAIN/api/webhooks/bitbucket?access_token=YOUR_SECRET
Triggers: Repository push

TODO

gitdeploy is intended for use with static websites that are generated after changes are pushed to a Git repository. This works with sites that are being edited in code and tracked in Git. Sites that have their content managed with a headless CMS that pushes to Git are also very well-suited.

gitdeploy supports verified webhooks from Github, Bitbucket, and Gitea.

gitdeploy is written in Go. This means that it's a standalone binary available on all major operating systems and architectures. It provides an API with endpoints that handle webhooks, allow for initiation of builds, and getting the status of builds and build jobs.

gitdeploy comes with a simple interface. The interface be disabled if you don't want to use it.

gitdeploy also comes with basic authentication via integration with Pocket ID. Authentication can also be disabled if you don't want to use it. The built-in interface requires the built-in authentication.

How to Generate a Base64 Secret

in your browser:

(async function () {
  var rnd = new Uint8Array(16);
  await crypto.getRandomValues(rnd);
  var b64 = [].slice
    .apply(rnd)
    .map(function (ch) {
      return String.fromCharCode(ch);
    })
    .join("");
  var secret = btoa(b64)
    .replace(/\//g, "_")
    .replace(/\+/g, "-")
    .replace(/=/g, "");
  console.info(secret);
})();

with node.js:

crypto
  .randomBytes(16)
  .toString("base64")
  .replace(/\+/g, "-")
  .replace(/\//g, "_")
  .replace(/=/g, "");

License

Copyright 2020 The gitdeploy Authors

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.