-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust makes it easy to use external files in crate documentation, take advantage of that to de-duplicate the README.md and the create level documentation
- Loading branch information
Showing
3 changed files
with
107 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,24 @@ | ||
# gitlab-runner-rs | ||
|
||
A crate to help build custom gitlab runner implementations. | ||
|
||
## Implementing a custom runner | ||
|
||
The overall idea is that this crate handles all interaction with the gitlab | ||
server and drives the executions while the the runner implementation focus on | ||
how to handle jobs from gitlab. | ||
|
||
As the focus for an implementer of a custom runner is to implement the async | ||
JobHandler trait, which gets calle during job executation. An absolute minimal | ||
runner can be implement as such: | ||
|
||
```rust,no_run | ||
use gitlab_runner::{outputln, Runner, JobHandler, JobResult, Phase}; | ||
use std::path::PathBuf; | ||
#[derive(Debug)] | ||
struct Run {} | ||
#[async_trait::async_trait] | ||
impl JobHandler for Run { | ||
async fn step(&mut self, script: &[String], phase: Phase) -> JobResult { | ||
outputln!("Running script for phase {:?}", phase); | ||
for s in script { | ||
outputln!("Step: {}", s); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
#[tokio::main] | ||
async fn main() { | ||
let mut runner = Runner::new( | ||
"https://gitlab.example.com".try_into().unwrap(), | ||
"runner token".to_owned(), | ||
PathBuf::from("/tmp")); | ||
runner.run(move | _job | async move { Ok(Run{}) }, 16).await.unwrap(); | ||
} | ||
``` | ||
|
||
## Gitlab runner creation | ||
|
||
This crate does not support creating new runners on the GitLab server. This can | ||
be done using the | ||
[runner creation API](https://docs.gitlab.com/ee/api/users.html#create-a-runner-linked-to-a-user), | ||
or manually in the GitLab | ||
[runner management web interface](https://docs.gitlab.com/ee/ci/runners/runners_scope.html). | ||
Make sure to follow the runner creation with an authentication token workflow, | ||
as the registration token workflow is deprecated. | ||
|
||
One key parameter provided when creating the runner is `run_untagged=false` (or | ||
leaving the `Run untagged jobs` box unchecked in the web interface), which will | ||
make the runner *only* pickup jobs which matches its tags. This is important to | ||
prevent the runner from picking up "normal" jobs which it will not be able to | ||
process. | ||
|
||
When the runner is created GitLab provides an authentication token starting | ||
with `glrt-`. This token should be provided to the runner for its GitLab | ||
connection. | ||
|
||
The token can be verified using a curl command like: | ||
|
||
```shell | ||
curl --request POST "https://GITLAB_URL/api/v4/runners/verify" \ | ||
--form "token=AUTHENTICATION_TOKEN" | ||
``` | ||
|
||
This step is optional. | ||
[![Crates.io][crates-badge]][crates-url] | ||
[![Documentation][docs-badge]][docs-url] | ||
[![MIT/Apache-2 licensed][license-badge]][license-url] | ||
[![Build Status][actions-badge]][actions-url] | ||
|
||
[crates-badge]: https://img.shields.io/crates/v/gitlab-runner | ||
[crates-url]: https://crates.io/crates/gitlab-runner | ||
[docs-badge]: https://docs.rs/gitlab-runner/badge.svg | ||
[docs-url]: https://docs.rs/gitlab-runner | ||
[license-badge]: https://img.shields.io/badge/license-MIT_OR_Apache--2-blue.svg | ||
[license-url]: LICENSE-APACHE | ||
[actions-badge]: https://github.com/collabora/gitlab-runner-rs/workflows/CI/badge.svg | ||
[actions-url]:https://github.com/collabora/gitlab-runner-rs/actions?query=workflow%3ACI | ||
|
||
|
||
[GitLab](https://gitlab.com) provides a REST style API for CI runners. These | ||
crates abstract this API away so custom runners can easily be build without | ||
any knowledge of the gitlab APIs | ||
|
||
This workspace consists of two crates: | ||
* [gitlab-runner](gitlab-runner/README.md) - Main runner crate | ||
* gitlab-runner-mock - Mock crate for the gitlab runner APIs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# gitlab-runner-rs | ||
|
||
A crate to help build custom gitlab runner implementations. | ||
|
||
## Implementing a custom runner | ||
|
||
The overall idea is that this crate handles all interaction with the gitlab | ||
server and drives the executions while the the runner implementation focus on | ||
how to handle jobs from gitlab. | ||
|
||
As the focus for an implementer of a custom runner is to implement the async | ||
JobHandler trait, which gets calle during job executation. An absolute minimal | ||
runner can be implement as such: | ||
|
||
```rust,no_run | ||
use gitlab_runner::{outputln, GitlabLayer, RunnerBuilder, JobHandler, JobResult, Phase}; | ||
use tracing_subscriber::prelude::*; | ||
use std::path::PathBuf; | ||
#[derive(Debug)] | ||
struct Run {} | ||
#[async_trait::async_trait] | ||
impl JobHandler for Run { | ||
async fn step(&mut self, script: &[String], phase: Phase) -> JobResult { | ||
outputln!("Running script for phase {:?}", phase); | ||
for s in script { | ||
outputln!("Step: {}", s); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
#[tokio::main] | ||
async fn main() { | ||
let (layer, jobs) = GitlabLayer::new(); | ||
tracing_subscriber::Registry::default() | ||
.with( | ||
tracing_subscriber::fmt::Layer::new() | ||
.pretty() | ||
.with_filter(tracing::metadata::LevelFilter::INFO), | ||
) | ||
.with(layer) | ||
.init(); | ||
let mut runner = RunnerBuilder::new( | ||
"https://gitlab.example.com".try_into().expect("failed to parse url"), | ||
"runner token", | ||
"/tmp", | ||
jobs | ||
) | ||
.build() | ||
.await; | ||
runner.run(move | _job | async move { Ok(Run{}) }, 16).await.unwrap(); | ||
} | ||
``` | ||
|
||
## Gitlab runner creation | ||
|
||
This crate does not support creating new runners on the GitLab server. This can | ||
be done using the | ||
[runner creation API](https://docs.gitlab.com/ee/api/users.html#create-a-runner-linked-to-a-user), | ||
or manually in the GitLab | ||
[runner management web interface](https://docs.gitlab.com/ee/ci/runners/runners_scope.html). | ||
Make sure to follow the runner creation with an authentication token workflow, | ||
as the registration token workflow is deprecated. | ||
|
||
One key parameter provided when creating the runner is `run_untagged=false` (or | ||
leaving the `Run untagged jobs` box unchecked in the web interface), which will | ||
make the runner *only* pickup jobs which matches its tags. This is important to | ||
prevent the runner from picking up "normal" jobs which it will not be able to | ||
process. | ||
|
||
When the runner is created GitLab provides an authentication token starting | ||
with `glrt-`. This token should be provided to the runner for its GitLab | ||
connection. | ||
|
||
The token can be verified using a curl command like: | ||
|
||
```shell | ||
curl --request POST "https://GITLAB_URL/api/v4/runners/verify" \ | ||
--form "token=AUTHENTICATION_TOKEN" | ||
``` | ||
|
||
This step is optional. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters