Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
cmd/gohci-worker: move everything into cmd/gohci-worker
Browse files Browse the repository at this point in the history
This is in preparation for adding other tools.
  • Loading branch information
maruel committed May 2, 2018
1 parent 6cc9515 commit cfc03cb
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ go:
- 1.x

script:
- go test . ./lib
- go test ./...
38 changes: 20 additions & 18 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ This includes Raspbian and Ubuntu.
recent version.
- See [official instructions](https://golang.org/doc/install#install) for
help.
- Create a `gohci` standard account (optional).
- Setup `$PATH` to include `~/go/bin`
- Install git.
- Install `gohci`.
- Install `gohci-worker`.
- Create the directory `gohci`.
- Set up the system to run `gohci` automatically and update it every
- Set up the system to run `gohci-worker` automatically and update it every
day via [`systemd/setup.sh`](systemd/setup.sh) .

Overall it looks like this:
Expand All @@ -71,7 +72,7 @@ Overall it looks like this:
sudo apt install git
export PATH="$PATH:$HOME/go/bin"
echo 'export PATH="$PATH:$HOME/go/bin"' >> ~/.bash_aliases
go get -u -v periph.io/x/gohci
go get -u -v periph.io/x/gohci/cmd/gohci-worker
mkdir -p ~/gohci
$HOME/go/src/periph.io/x/gohci/systemd/setup.sh
```
Expand All @@ -84,7 +85,8 @@ $HOME/go/src/periph.io/x/gohci/systemd/setup.sh
- See [official instructions](https://golang.org/doc/install#install) for
help.
- Install [git](https://git-scm.com)
- First enable auto-login (optionally on a fresh low privilege account).
- Create a `gohci` standard account (optional).
- Enable auto-login.
- Win-R
- `netplwiz`
- Uncheck _Users must enter a user name and password to use this computer_.
Expand All @@ -97,23 +99,23 @@ $HOME/go/src/periph.io/x/gohci/systemd/setup.sh
title gohci
cd %USERPROFILE%\gohci
:loop
gohci
gohci-worker
goto loop
```
- Auto-update can be done via the task scheduler. The following command will
auto-update `gohci` every day:
auto-update `gohci-worker` every day:
```
schtasks /create /tn "Update gohci" /tr "go get -v -u periph.io/x/gohci" /sc minute /mo 1439
schtasks /create /tn "Update gohci-worker" /tr "go get -v -u periph.io/x/gohci/cmd/gohci-worker" /sc minute /mo 1439
```
- The task should show up with: `schtasks /query /fo table | more` or
navigating the GUI with `taskschd.msc`.
- Open `cmd` and run:
```
go get -u -v periph.io/x/gohci
go get -u -v periph.io/x/gohci/cmd/gohci-worker
mkdir %USERPROFILE%/gohci
cd %USERPROFILE%/gohci
```
- Run `gohci` twice to make sure the firewall popup is shown and you allow the
- Run `gohci-worker` twice to make sure the firewall popup is shown and you allow the
app.


Expand All @@ -125,9 +127,9 @@ $HOME/go/src/periph.io/x/gohci/systemd/setup.sh
help.
- Install [Homebrew](https://brew.sh) (optional).
- Create a `gohci` standard account (optional).
- Install `gohci` and setup for auto-start:
- Install `gohci-worker` and setup for auto-start:
```
go get -u -v periph.io/x/gohci
go get -u -v periph.io/x/gohci/cmd/gohci-worker
mkdir -p ~/Library/LaunchAgents
cp $HOME/go/src/periph.io/x/gohci/macos/gohci.plist ~/Library/LaunchAgents
mkdir -p ~/gohci
Expand All @@ -141,7 +143,7 @@ $HOME/go/src/periph.io/x/gohci/systemd/setup.sh
```
mkdir -p ~/gohci
cd ~/gohci
gohci
gohci-worker
```
- It will look like this, with comments added here:
```
Expand All @@ -158,16 +160,16 @@ $HOME/go/src/periph.io/x/gohci/systemd/setup.sh
- Edit the values based on your needs.
- `oauth2accesstoken` must be set to the `AccessToken` you created at the step
[OAuth2 token](#oauth2-token).
- Run `gohci` again and it will start a web server. When `gohci` is running,
updating `gohci.yml` will make the process quit (after completing any enqueued
checks).
- Reboot the host and make sure `gohci` starts correctly.
- Run `gohci-worker` again and it will start a web server. When `gohci-worker`
is running, updating `gohci.yml` will make the process quit (after completing
any enqueued checks).
- Reboot the host and make sure `gohci-worker` starts correctly.


### Private repository

`gohci` will automatically switch from HTTPS to SSH checkout when the repository
is private. For it to work you must:
`gohci-worker` will automatically switch from HTTPS to SSH checkout when the
repository is private. For it to work you must:
- On your device, create a key via `ssh-keygen -C "raspberrypi"` and do not
specify a password.
- Visit `github.com/<user>/<repo>/settings/keys`.
Expand Down
21 changes: 11 additions & 10 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ which means the attacker can:

## Test on multiple kind of hardware simultaneously?

- Install `gohci` on each of your devices, e.g. a
- Install `gohci-worker` on each of your devices, e.g. a
[C.H.I.P.](https://getchip.com/), a [Raspberry
Pi](https://www.raspberrypi.org/), a [BeagleBone](https://beagleboard.org/),
macOS, Windows, etc.
- Register [one webhook](CONFIG.md#webhook) on your repository per device. For
each hook, use URLs in the format `https://1.2.3.4/gohci/deviceX` or as your
choosing.
- Each `gohci` worker is completely independent. They do not need to be all
located at the same physical location.
- Each `gohci-worker` worker is completely independent. They do not need to be
all located at the same physical location.
- Setup your `Caddyfile` like this:

```
Expand All @@ -58,10 +58,10 @@ ci.example.com {

## Won't the auto-updater break my CI when you push broken code?

Maybe. I'll try to keep `gohci` always in a working condition but it can fail
from time to time. So feel free to fork the `gohci` repository and run from your
copy. Don't forget to update `gohci_update.timer` to pull from your repository
instead.
Maybe. I'll try to keep `gohci-worker` always in a working condition but it can
fail from time to time. So feel free to fork the `gohci` repository and run from
your copy. Don't forget to update `gohci_update.timer` to pull from your
repository instead.


## What's the maximum testing rate per hour?
Expand All @@ -79,9 +79,10 @@ requests. Each test run does:

So a configuration defining 7 tests would sum for `3 + 1 + (2 * (7+2))` = 22
requests. 5000/13 = *227 test runs/hour*. If you have 3 workers, this means an
upper bound of *75 test runs/hour*. In practice, `gohci` throttles its requests
by buffering all the updates that happen within a second so the effective number
of requests per build is lower, i.e. you can run more tests in practice.
upper bound of *75 test runs/hour*. In practice, `gohci-worker` throttles its
requests by buffering all the updates that happen within a second so the
effective number of requests per build is lower, i.e. you can run more tests in
practice.


## Can you add support for `gd`, `glide`, `vgo`, etc?
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ It hardly can get any simpler:
- Each check's stdout is attached to the gist as they complete.
- The commit's status is updated "_live_" on Github. This is pretty cool to see
in action on a GitHub PR.
- `gohci` exits whenever the executable or `gohci.yml` is updated; making it
easy to use an auto-updating mechanism.
- `gohci-worker` exits whenever the executable or `gohci.yml` is updated; making
it easy to use an auto-updating mechanism.

Not convinced? Read the [FAQ.md](FAQ.md) for additional information.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/lib.go → cmd/gohci-worker/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Package lib exposes SetConsoleTitle.
//
// This is mainly useful on Windows.
package lib // import "periph.io/x/gohci/lib"
package main
2 changes: 1 addition & 1 deletion lib/lib_curse.go → cmd/gohci-worker/lib_curse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// +build !windows

package lib
package main

// SetConsoleTitle sets the console title.
func SetConsoleTitle(title string) error {
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_windows.go → cmd/gohci-worker/lib_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

package lib
package main

import (
"syscall"
Expand Down
2 changes: 1 addition & 1 deletion main.go → cmd/gohci-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// - github webhook webserver that triggers on pushes and PRs
// - runs a Go build and a list of user supplied commands
// - posts the stdout to a Github gist and updates the commit's status
package main // import "periph.io/x/gohci"
package main // import "periph.io/x/gohci/cmd/gohci-worker"

import (
"errors"
Expand Down
3 changes: 1 addition & 2 deletions server.go → cmd/gohci-worker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/google/go-github/github"
fsnotify "gopkg.in/fsnotify.v1"
"periph.io/x/gohci/lib"
)

// runServer runs the web server.
Expand Down Expand Up @@ -52,7 +51,7 @@ func runServer(c serverConfig, wkr worker, fileName string) error {
log.Printf("Failed to initialize watcher: %v", err)
}

lib.SetConsoleTitle(fmt.Sprintf("gohci - %s", a))
SetConsoleTitle(fmt.Sprintf("gohci - %s", a))
if err == nil {
select {
case <-w.Events:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion macos/gohci.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string>gohci</string>
<key>ProgramArguments</key>
<array>
<string>/Users/gohci/go/bin/gohci</string>
<string>/Users/gohci/go/bin/gohci-worker</string>
</array>
<!-- Edit if you installed Go locally.
<key>EnvironmentVariables</key>
Expand Down
16 changes: 8 additions & 8 deletions systemd/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

set -eu

if (which gohci >/dev/null); then
echo Found gohci
if (which gohci-worker >/dev/null); then
echo Found gohci-worker
else
echo Fetching gohci
go get periph.io/x/gohci
echo Fetching gohci-worker
go get periph.io/x/gohci/cmd/gohci-worker
fi

mkdir -p /home/${USER}/gohci
Expand All @@ -33,7 +33,7 @@ Group=${USER}
KillMode=mixed
Restart=always
TimeoutStopSec=20s
ExecStart=/home/${USER}/go/bin/gohci
ExecStart=/home/${USER}/go/bin/gohci-worker
WorkingDirectory=/home/${USER}/gohci
Environment=PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[Install]
Expand All @@ -43,23 +43,23 @@ EOF
sudo tee /etc/systemd/system/gohci_update.service << EOF
# Created by https://github.com/periph/gohci/blob/master/systemd/setup.sh
[Unit]
Description=Updates gohci, as triggered by gohci_update.timer
Description=Updates gohci-worker, as triggered by gohci_update.timer
After=network-online.target
[Service]
Type=oneshot
User=${USER}
Group=${USER}
NoNewPrivileges=true
# /bin/sh is necessary to load .profile to set $GOPATH:
ExecStart=/bin/sh -l -c "go get -v -u periph.io/x/gohci"
ExecStart=/bin/sh -l -c "go get -v -u periph.io/x/gohci/cmd/gohci-worker"
Environment=PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
EOF


sudo tee /etc/systemd/system/gohci_update.timer << EOF
# Created by https://github.com/periph/gohci/blob/master/systemd/setup.sh
[Unit]
Description=Runs "go get -u periph.io/x/gohci" as a cron job
Description=Runs "go get -u periph.io/x/gohci/cmd/gohci-worker" as a cron job
[Timer]
OnBootSec=1min
OnUnitActiveSec=1440min
Expand Down

0 comments on commit cfc03cb

Please sign in to comment.