|
1 | | -## Tresh |
| 1 | +# Tresh |
2 | 2 |
|
3 | | -🛳 Tiny local continuous integration based on Github webhooks |
| 3 | +🛳 Tiny GitHub webhooks based CI/CD server for your VPS |
4 | 4 |
|
5 | | -### Development |
| 5 | +## Install & setup |
6 | 6 |
|
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 | + |
| 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: |
8 | 53 |
|
9 | 54 | ```bash |
10 | | -cargo run |
| 55 | +# might require sudo |
| 56 | +$ systemctl enable /etc/systemd/system/thresh.service |
| 57 | +$ systemctl start thresh |
| 58 | +``` |
11 | 59 |
|
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} |
14 | 76 | ``` |
15 | 77 |
|
| 78 | +## Development |
| 79 | + |
| 80 | +#### Testing |
| 81 | + |
| 82 | +#### Run |
| 83 | + |
16 | 84 | ```bash |
17 | | -# Using dev watch mode |
| 85 | +cargo run |
| 86 | + |
| 87 | +# Watch mode |
18 | 88 | cargo watch -x run |
| 89 | + |
| 90 | +# Setting CLI options |
| 91 | +cargo run -- --port 9090 --logs-dir ./logs |
19 | 92 | ``` |
20 | 93 |
|
21 | 94 | #### Test |
22 | 95 |
|
23 | 96 | ```bash |
24 | 97 | cargo test |
| 98 | + |
| 99 | +# Watch mode |
| 100 | +cargo watch -x test |
25 | 101 | ``` |
26 | 102 |
|
| 103 | +### Testing the webhook locally |
| 104 | + |
27 | 105 | ```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. |
0 commit comments