gitdeploy/README.md

165 lines
3.7 KiB
Markdown
Raw Normal View History

2020-10-09 09:22:06 +00:00
# [gitdeploy](https://git.rootprojects.org/root/gitdeploy)
2020-09-09 04:30:07 +00:00
2020-10-09 09:22:06 +00:00
**gitdeploy** is an app for handling continuous deployment of static websites.
2020-09-17 18:50:23 +00:00
2020-09-29 03:15:30 +00:00
## Usage
```bash
echo 'GITHUB_SECRET=xxxxxxx' >> .env
2020-10-09 09:22:06 +00:00
./gitdeploy init
./gitdeploy run --listen :3000 --serve-path ./overrides --exec ./path/to/script.sh
2020-09-29 03:15:30 +00:00
```
To manage `git credentials`
see [The Vanilla DevOps Git Credentials Cheatsheet][1]
[1]: https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/
## Git Info
The exec script will receive the parent environment as well as
```bash
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
```bash
pushd html/
2020-10-01 15:11:34 +00:00
npm ci
scripts/build
popd
```
```bash
go mod tidy
go mod vendor
go generate -mod=vendor ./...
go build -mod=vendor .
```
2020-09-29 08:10:50 +00:00
You can use build tags to remove providers from the build:
```bash
go build -mod=vendor -tags nobitbucket,nogithub .
```
Supported tags are:
- nogithub
- nobitbucket
2020-10-09 09:44:56 +00:00
## Run as a System Service
```bash
sudo env PATH="$PATH" \
serviceman add --name gitdeploy --system \
--username app -path "$PATH" -- \
gitdeploy run --exec ./scripts/
```
2020-09-28 23:39:05 +00:00
## Add Webhooks
To add a webhook you'll first need a secret
**with node.js**:
```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`
```txt
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: ✅
```
2020-09-29 08:08:35 +00:00
### 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:
```txt
2020-10-09 09:22:06 +00:00
Title: gitdeploy
2020-09-29 08:08:35 +00:00
URL: https://YOUR_DOMAIN/api/webhooks/bitbucket?access_token=YOUR_SECRET
Triggers: Repository push
```
## TODO
2020-10-09 09:22:06 +00:00
**gitdeploy** is intended for use with static websites that are generated after
2020-09-17 18:50:23 +00:00
changes are pushed to a Git repository. This works with sites that are being
2020-09-26 15:56:23 +00:00
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.
2020-09-17 18:50:23 +00:00
2020-10-09 09:22:06 +00:00
**gitdeploy** supports verified webhooks from Github, Bitbucket, and Gitea.
2020-09-17 18:50:23 +00:00
2020-10-09 09:22:06 +00:00
**gitdeploy** is written in Go. This means that it's a standalone binary
2020-09-26 15:56:23 +00:00
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.
2020-09-17 18:50:23 +00:00
2020-10-09 09:22:06 +00:00
**gitdeploy** comes with a simple interface. The interface be disabled if you
2020-09-26 15:56:23 +00:00
don't want to use it.
2020-09-17 18:50:23 +00:00
2020-10-09 09:22:06 +00:00
**gitdeploy** also comes with basic authentication via integration with
2020-09-26 15:56:23 +00:00
[Pocket ID](https://pocketid.app). Authentication can also be disabled if you
don't want to use it. The built-in interface requires the built-in
authentication.
2020-09-29 03:17:10 +00:00
2020-09-28 23:39:05 +00:00
## How to Generate a Base64 Secret
**in your browser**:
```js
(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**:
```js
crypto
.randomBytes(16)
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
```
2020-09-29 03:17:10 +00:00
## License
2020-10-09 09:22:06 +00:00
Copyright 2020 The gitdeploy Authors
2020-09-29 03:15:30 +00:00
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/.