githubactionsrunnerlauncher

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2020 License: MIT Imports: 19 Imported by: 0

README

github-actions-runner-launcher

Build Status GitHub GoDoc Docker Pulls Test Coverage Release

Automatic setup and registration of GitHub actions runner instances. If you have tried github.com/myoung34/docker-github-actions-runner or similiar options for running the action runners as docker containers for the convenience, but want to run them on bare-metal, this is just right for you!

Configuration works just like with docker-compose as shown in this sample.yml:

version: '3.3'

services:
  my-runner:
    environment:
      REPO_URL: https://github.com/my-org/repo
      # Use access token to automatically obtain runner tokens from the github API (see 1.)
      ACCESS_TOKEN: <MY-SECRET-GITHUB-ACCESS-TOKEN>
      # The runner token must be specified otherwise (see 2.)
      RUNNER_TOKEN: <MY-SECRET-RUNNER-TOKEN>
      RUNNER_NAME: my-runner
      RUNNER_WORKDIR: /my/runners/work/dir
      ORG_RUNNER: "false"
      ORG_NAME: my-org
      LABELS: linux,x64

Important notes:

  1. Youy can obtain an access token to automatically create RUNNER_TOKENs for you with the GitHub API. You can create a token at https://github.com/settings/tokens. When you want the runners to work with public repos only, choose the public_repo scope, otherwise choose the repo scope. Always remember to keep the token and your runner config private!
  2. You can get a new RUNNER_TOKEN at https://github.com/organizations/my-org/settings/actions/add-new-runner. Note that you only have to copy the token used for ./config.sh.

You can then start with

go get -u github.com/romnnn/github-actions-runner-launcher/cmd/github-actions-runner-launcher
# To install the runners dependencies, the first run needs sudo privileges
sudo github-actions-runner-launcher --config sample.yml install
github-actions-runner-launcher --config sample.yml run

You can also download pre built binaries from the releases page, or use the docker image:

docker pull romnn/github-actions-runner-launcher

For a list of options, run with --help.

Troubleshooting
  • Failed to prepare runner: Failed to install runner dependencies: fork/exec usually indicates that you should run the script as a binary instead of with go run.
Development
Prerequisites

Before you get started, make sure you have installed the following tools::

$ python3 -m pip install -U cookiecutter>=1.4.0
$ python3 -m pip install pre-commit bump2version invoke ruamel.yaml halo
$ go get -u golang.org/x/tools/cmd/goimports
$ go get -u golang.org/x/lint/golint
$ go get -u github.com/fzipp/gocyclo
$ go get -u github.com/mitchellh/gox  # if you want to test building on different architectures

Remember: To be able to excecute the tools downloaded with go get, make sure to include $GOPATH/bin in your $PATH. If echo $GOPATH does not give you a path make sure to run (export GOPATH="$HOME/go" to set it). In order for your changes to persist, do not forget to add these to your shells .bashrc.

With the tools in place, it is strongly advised to install the git commit hooks to make sure checks are passing in CI:

invoke install-hooks

You can check if all checks pass at any time:

invoke pre-commit

Note for Maintainers: After merging changes, tag your commits with a new version and push to GitHub to create a release:

bump2version (major | minor | patch)
git push --follow-tags
Note

This project is still in the alpha stage and should not be considered production ready.

Documentation

Index

Constants

View Source
const Version = "0.1.3"

Version is incremented using bump2version

Variables

This section is empty.

Functions

func CreateGitHubAPIClient added in v0.1.2

func CreateGitHubAPIClient(ctx context.Context, accessToken string) *github.Client

CreateGitHubAPIClient ...

Types

type LaunchConfig

type LaunchConfig struct {
	Services map[string]RunnerConfig `yaml:"services"`
}

LaunchConfig ...

type Launcher

type Launcher struct {
	Config         LaunchConfig
	RunnerVersion  string
	RunnerArch     string
	Reconfigure    bool
	RemoveExisting bool
	// contains filtered or unexported fields
}

Launcher ...

func NewWithConfig

func NewWithConfig(file string) (*Launcher, error)

NewWithConfig ...

func (*Launcher) ConfigureRunner added in v0.1.2

func (l *Launcher) ConfigureRunner(rLog *log.Entry, runner RunnerConfig, runnerToken string) error

ConfigureRunner ...

func (*Launcher) GetWorkDirForRunner

func (l *Launcher) GetWorkDirForRunner(runner RunnerConfig) (string, error)

GetWorkDirForRunner ...

func (*Launcher) ObtainRunnerToken

func (l *Launcher) ObtainRunnerToken(ctx context.Context, runnerCfg RunnerConfig, accessToken string) (string, *github.Timestamp, error)

ObtainRunnerToken ...

func (*Launcher) ParseConfigFile

func (l *Launcher) ParseConfigFile(file string) error

ParseConfigFile ...

func (*Launcher) PrepareRunnerFiles added in v0.1.2

func (l *Launcher) PrepareRunnerFiles(rLog *log.Entry, runner RunnerConfig) error

PrepareRunnerFiles ...

func (*Launcher) RemoveRunner added in v0.1.2

func (l *Launcher) RemoveRunner(runner RunnerConfig, removeToken *github.RemoveToken) error

RemoveRunner ....

func (*Launcher) Run

func (l *Launcher) Run(run bool) (err error)

Run ...

type RunnerConfig

type RunnerConfig struct {
	Environment RunnerEnvironment `yaml:"environment"`
}

RunnerConfig ...

type RunnerEnvironment

type RunnerEnvironment struct {
	RepoURL       string `yaml:"REPO_URL"`
	AccessToken   string `yaml:"ACCESS_TOKEN"`
	RunnerName    string `yaml:"RUNNER_NAME"`
	RunnerToken   string `yaml:"RUNNER_TOKEN"`
	RunnerWorkdir string `yaml:"RUNNER_WORKDIR"`
	IsOrgRunner   string `yaml:"ORG_RUNNER"`
	OrgName       string `yaml:"ORG_NAME"`
	Labels        string `yaml:"LABELS"`
}

RunnerEnvironment ...

type TokenSource

type TokenSource struct {
	AccessToken string
}

TokenSource ...

func (*TokenSource) Token

func (t *TokenSource) Token() (*oauth2.Token, error)

Token ...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL