Skip to content

Commit b1ded04

Browse files
Update README.md with docs (#17)
* feat(repo): Add usage example to README.md * fix(repo): Improve docs * fix(repo): Improve docs * fix(repo): Improve docs * fix(repo): Typos
1 parent 93872cb commit b1ded04

File tree

4 files changed

+145
-14
lines changed

4 files changed

+145
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "thresh"
3-
version = "0.1.0"
4-
description = "Tiny local continuous integration based on Github webhooks"
3+
version = "0.0.1"
4+
description = "Tiny GitHub webhooks based CI/CD server for your VPS"
55
authors = ["gillchristian <[email protected]>", "ndelvalle <[email protected]>"]
66
edition = "2018"
77

README.md

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,113 @@
1-
## Tresh
1+
# Tresh
22

3-
🛳 Tiny local continuous integration based on Github webhooks
3+
🛳 Tiny GitHub webhooks based CI/CD server for your VPS
44

5-
### Development
5+
## Install & setup
66

7-
#### Run
7+
Download the latest binary from the release and give exec permission:
8+
9+
```
10+
$ wget -O thresh "https://github.com/Huemul/thresh/releases/download/v0.0.1/thresh_x86-64-linux
11+
"
12+
$ chmod +x thresh
13+
```
14+
15+
**NOTE**: you probably want to change the version (`v0.0.1`) to the [latest available release](https://github.com/Huemul/thresh/releases).
16+
17+
Now that Thresh is available:
18+
19+
```
20+
$ ./thresh --help
21+
thresh 0.0.1
22+
gillchristian <[email protected]>:ndelvalle <[email protected]>
23+
Tiny GitHub webhooks based CI/CD server for your VPS
24+
25+
USAGE:
26+
thresh [OPTIONS]
27+
28+
FLAGS:
29+
-h, --help Prints help information
30+
-V, --version Prints version information
31+
32+
OPTIONS:
33+
-c, --config <config> Path to the Threshfile [default: ./.threshfile]
34+
-l, --logs-dir <logs-dir> Sets a custom logs directory
35+
-p, --port <port> Sets a custom server port
36+
```
37+
38+
Next create a `.threshfile` with the configuration to run for any project you want. For a example threshfile see [sample.threshfile](https://github.com/Huemul/thresh/blob/master/sample.threshfile).
39+
40+
Create a systemd file (`/etc/systemd/system/thresh.service`) with the following contents.
41+
42+
```
43+
[Unit]
44+
Description=Thresh
45+
46+
[Service]
47+
ExecStart=/path/to/thresh -c /path/to/.threshfile -l /path/to/thresh-logs -p 8080
48+
```
49+
50+
**NOTE**: Make sure to update it with the right options and path to the Thresh binary.
51+
52+
Now enable and start thresh service:
853

954
```bash
10-
cargo run
55+
# might require sudo
56+
$ systemctl enable /etc/systemd/system/thresh.service
57+
$ systemctl start thresh
58+
```
1159

12-
# Setting CLI options
13-
cargo run -- --port 9090 --logs-dir ./logs
60+
To see logs and status the following commands are useful:
61+
62+
```bash
63+
$ systemctl status thresh
64+
$ journalctl -u thresh -b
65+
```
66+
67+
Once Thresh is running and exposed to the internet on your VPS is time to [add the GitHub webhook to a repo](https://developer.github.com/webhooks/creating/).
68+
69+
Create a webhook that sends `push` events to the webhook URL (`<domain-running-thresh>/webhook`).
70+
71+
Thresh responds with a "job id" in case a webhook triggered a job. Which can be used to see the log file online:
72+
73+
```
74+
GET <domain-running-thresh>/logs
75+
GET <domain-running-thresh>/logs/:{job_id}
1476
```
1577

78+
## Development
79+
80+
#### Testing
81+
82+
#### Run
83+
1684
```bash
17-
# Using dev watch mode
85+
cargo run
86+
87+
# Watch mode
1888
cargo watch -x run
89+
90+
# Setting CLI options
91+
cargo run -- --port 9090 --logs-dir ./logs
1992
```
2093

2194
#### Test
2295

2396
```bash
2497
cargo test
98+
99+
# Watch mode
100+
cargo watch -x test
25101
```
26102

103+
### Testing the webhook locally
104+
27105
```bash
28-
# Using dev watch mode
29-
cargo watch -x test
30-
```
106+
curl -d {
107+
"ref": "refs/heads/master",
108+
"repository": { "full_name": "username/repository" },
109+
"sender": { "login": "username" }
110+
}' -H "Content-Type: application/json" -X POST http://localhost:8080/webhook
111+
```
112+
113+
:point_up: That can also be used to trigger the webhook from other sources (eg. any CI/CD server). In that case, make sure the URL is passed by secrets.

sample.threshfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Optional flag to run the job on the ping event
2+
# sent by GitHub when setting up the webhook
3+
run_job_on_ping = false
4+
5+
# Optional config, can be set here or by the CLI options
6+
port = 8080
7+
logs_dir = "./logs"
8+
9+
# a list of projects to run jobs for
10+
11+
[[projects]]
12+
# the repository where the webhook is set up
13+
repository = "username/repository"
14+
15+
# run only for this branch
16+
branch = "master"
17+
18+
# path where the commands should run the tilde (~) is properly expanded
19+
#
20+
# NOTE: the path does not have to be a git repo
21+
# it can be any directory
22+
path = "~/path/to/project/directory"
23+
24+
# list of commands to run
25+
commands = [
26+
"git pull --rebase",
27+
"docker-compose down",
28+
"docker-compose up -d",
29+
]
30+
31+
[[projects]]
32+
repository = "username/other"
33+
branch = "development"
34+
path = "~/path/to/other"
35+
commands = [
36+
"git pull",
37+
"./reset.sh",
38+
]
39+
40+
[[projects]]
41+
repository = "username/yet-another"
42+
branch = "master"
43+
path = "~/path/to/another"
44+
commands = [
45+
"git pull",
46+
"systemctl stop yet_another",
47+
"systemctl start yet_another",
48+
]

0 commit comments

Comments
 (0)