Skip to content

Commit

Permalink
quick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Aug 16, 2024
1 parent 17f5519 commit 9c5a5f7
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 19 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ With the github plugin, there is a Controller Plugin and a Service Plugin.
file_dir: /Users/myUser/Library/Logs/
services:
# GITHUB CONTROLLER
- name: github_controller
- name: GITHUB_WEBHOOK_CONTROLLER
plugin: github_controller
hook_id: 489747753
port: 54321
port: 54321 # port that's open to the internet so github can post to it
secret: 00000000
private_key: /Users/nathanpierce/veertuinc-anklet.2024-07-19.private-key.pem
app_id: 949431
Expand All @@ -79,9 +79,12 @@ With the github plugin, there is a Controller Plugin and a Service Plugin.
user: ""
password: ""
database: 0
# GITHUB SERVICES
- name: RUNNER1
plugin: github
token: github_pat_1XXXXX
private_key: /Users/nathanpierce/veertuinc-anklet.2024-07-19.private-key.pem
app_id: 949431
installation_id: 52970581
registration: repo
repo: anklet
owner: veertuinc
Expand Down Expand Up @@ -450,8 +453,8 @@ The `dev` LOG_LEVEL has colored output with text + pretty printed JSON for easie
"repo": "anklet",
"serviceName": "RUNNER1",
"source": {
"file": "/Users/nathanpierce/anklet/plugins/github/github.go",
"function": "github.com/veertuinc/anklet/plugins/github.Run",
"file": "/Users/nathanpierce/anklet/plugins/services/github/github.go",
"function": "github.com/veertuinc/anklet/plugins/services/github.Run",
"line": 408
},
"uniqueId": "1",
Expand Down Expand Up @@ -479,7 +482,7 @@ Plugins are, currently, stored in the `plugins/` directory.
If your plugin has any required files stored on disk, you should keep them in `~/.config/anklet/plugins/{plugin-name}/`. For example, `github` requires three bash files to prepare the github actions runner in the VMs. They are stored on each host:

```bash
❯ ll ~/.config/anklet/plugins/github
❯ ll ~/.config/anklet/plugins/services/github
total 0
lrwxr-xr-x 1 nathanpierce staff 61B Apr 4 16:02 install-runner.bash
lrwxr-xr-x 1 nathanpierce staff 62B Apr 4 16:02 register-runner.bash
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ require (
golang.org/x/sys v0.19.0 // indirect
)

replace github.com/veertuinc/anklet/plugins/github => ./plugins/github
replace github.com/veertuinc/anklet/plugins/services/github => ./plugins/services/github

replace github.com/veertuinc/anklet/plugins/controllers => ./plugins/controllers
replace github.com/veertuinc/anklet/plugins/controllers/github => ./plugins/controllers/github
4 changes: 2 additions & 2 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/veertuinc/anklet/internal/config"
"github.com/veertuinc/anklet/internal/logging"
"github.com/veertuinc/anklet/internal/metrics"
github_controller "github.com/veertuinc/anklet/plugins/controllers"
"github.com/veertuinc/anklet/plugins/github"
github_controller "github.com/veertuinc/anklet/plugins/controllers/github"
"github.com/veertuinc/anklet/plugins/services/github"
)

func Plugin(workerCtx context.Context, serviceCtx context.Context, serviceCancel context.CancelFunc, logger *slog.Logger, firstServiceStarted chan bool) {
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This plugin makes API requests to github's API to watch for workflow run jobs. It will then prepare a macOS VM, install the runner, and register it to the CI platform to run the job.
# GITHUB SERVICE PLUGIN

Since there are are limits for github API requests, we use [go-github-ratelimit/](https://github.com/gofri/go-github-ratelimit/) and our own primary rate limit logic to pause any active work when we hit the API rate limit. It's recommeded to increase the limits for API requests with github, but it's not necessary.
The github Service Plugin is responsible for pulling a job from the database/queue, preparing a macOS VM, and registering it to the repo's action runners so it can execute the job inside.

Workflow Run Jobs are processed in order of creation and then finally based on name. Sorting by name allows you the flexibility to run jobs in a specific order by naming them appropriately.
Workflow Run Jobs are processed in order of creation. The Github Controller Plugin will place the jobs in the database/queue in the order they're created.

In the `config.yml`, you can define the `github` plugin as follows:

Expand Down
27 changes: 21 additions & 6 deletions plugins/github/github.go → plugins/services/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"log/slog"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -733,10 +734,24 @@ func Run(workerCtx context.Context, serviceCtx context.Context, serviceCancel co
// Install runner
globals := config.GetGlobalsFromContext(serviceCtx)
logger.InfoContext(serviceCtx, "installing github runner inside of vm")
installRunnerPath := globals.PluginsPath + "/github/install-runner.bash"
registerRunnerPath := globals.PluginsPath + "/services/github/register-runner.bash"
startRunnerPath := globals.PluginsPath + "/services/github/start-runner.bash"
_, installRunnerErr := os.Stat(installRunnerPath)
_, registerRunnerErr := os.Stat(registerRunnerPath)
_, startRunnerErr := os.Stat(startRunnerPath)
if installRunnerErr != nil || registerRunnerErr != nil || startRunnerErr != nil {
logger.ErrorContext(serviceCtx, "must include install-runner.bash, register-runner.bash, and start-runner.bash in "+globals.PluginsPath+"/services/github/", "err", err)
err := sendCancelWorkflowRun(serviceCtx, logger, workflowJob.RunID)
if err != nil {
logger.ErrorContext(serviceCtx, "error sending cancel workflow run", "err", err)
}
return
}
err = ankaCLI.AnkaCopy(serviceCtx,
globals.PluginsPath+"/github/install-runner.bash",
globals.PluginsPath+"/github/register-runner.bash",
globals.PluginsPath+"/github/start-runner.bash",
installRunnerPath,
registerRunnerPath,
startRunnerPath,
)
if err != nil {
logger.ErrorContext(serviceCtx, "error executing anka copy", "err", err)
Expand All @@ -755,7 +770,7 @@ func Run(workerCtx context.Context, serviceCtx context.Context, serviceCancel co
default:
}

installRunnerErr := ankaCLI.AnkaRun(serviceCtx, "./install-runner.bash")
installRunnerErr = ankaCLI.AnkaRun(serviceCtx, "./install-runner.bash")
if installRunnerErr != nil {
logger.ErrorContext(serviceCtx, "error executing install-runner.bash", "err", installRunnerErr)
failureChannel <- true
Expand All @@ -772,7 +787,7 @@ func Run(workerCtx context.Context, serviceCtx context.Context, serviceCancel co
return
default:
}
registerRunnerErr := ankaCLI.AnkaRun(serviceCtx,
registerRunnerErr = ankaCLI.AnkaRun(serviceCtx,
"./register-runner.bash",
vm.Name, *repoRunnerRegistration.Token, repositoryURL, strings.Join(workflowJob.Labels, ","),
)
Expand All @@ -793,7 +808,7 @@ func Run(workerCtx context.Context, serviceCtx context.Context, serviceCancel co
return
default:
}
startRunnerErr := ankaCLI.AnkaRun(serviceCtx, "./start-runner.bash")
startRunnerErr = ankaCLI.AnkaRun(serviceCtx, "./start-runner.bash")
if startRunnerErr != nil {
logger.ErrorContext(serviceCtx, "error executing start-runner.bash", "err", startRunnerErr)
failureChannel <- true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9c5a5f7

Please sign in to comment.