Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gitlab-runner-rs for cancellation support, and timeout configuration, and small cleanups #17

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tracing-error = "0.2"
tracing-subscriber = { version = "0.3", features = ["default", "json"] }
url = "2.2"

gitlab-runner = "0.0.5"
gitlab-runner = "0.0.7"
# gitlab-runner = { path = "../gitlab-runner-rs/gitlab-runner" }
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ generate-monitor RUNNER_TAG
[--build-info BUILD_INFO_FILE=build-info.yml]
[--pipeline-out PIPELINE_FILE=obs.yml]
[--job-prefix MONITOR_JOB_PREFIX=obs]
[--job-timeout MONITOR_JOB_TIMEOUT]
[--artifact-expiration ARTIFACT_EXPIRATION='3 days']
[--build-log-out BUILD_LOG_FILE=build.log]
```
Expand Down Expand Up @@ -214,6 +215,12 @@ Changes the filename of the child pipeline YAML.
Changes the prefix that will be prepended to each generated job
(`MONITOR_JOB_PREFIX-REPOSITORY-ARCH`).

##### `--job-timeout MONITOR_JOB_TIMEOUT`

Changes the timeout for each generated job, using the [job `timeout`
setting](https://docs.gitlab.com/ee/ci/yaml/#timeout). If not passed, the
timeout will not be set.

##### `--artifact-expiration ARTIFACT_EXPIRATION='3 days'`

Changes the expiration of the build results & logs.
Expand Down
4 changes: 2 additions & 2 deletions src/binaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::{fs::File as AsyncFile, io::AsyncSeekExt};
use tokio_util::compat::FuturesAsyncReadCompatExt;
use tracing::{info_span, instrument, Instrument};

use crate::retry::{retry_large_request, retry_request};
use crate::retry::retry_request;

#[instrument(skip(client))]
pub async fn download_binaries(
Expand All @@ -28,7 +28,7 @@ pub async fn download_binaries(
let mut binaries = HashMap::new();

for binary in binary_list.binaries {
let mut dest = retry_large_request(|| {
let mut dest = retry_request(|| {
let binary = binary.clone();
let client = client.clone();
async move {
Expand Down
15 changes: 13 additions & 2 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct GenerateMonitorAction {
pipeline_out: String,
#[clap(long, default_value_t = DEFAULT_PIPELINE_JOB_PREFIX.to_owned())]
job_prefix: String,
#[clap(long)]
job_timeout: Option<String>,
#[clap(long, default_value_t = DEFAULT_ARTIFACT_EXPIRATION.to_owned())]
artifact_expiration: String,
#[clap(long, default_value_t = DEFAULT_BUILD_LOG.into())]
Expand Down Expand Up @@ -410,6 +412,7 @@ impl ObsJobHandler {
tags: vec![args.tag],
artifact_expiration: args.artifact_expiration,
prefix: args.job_prefix,
timeout: args.job_timeout,
rules: args.rules,
download_binaries: if let Some(build_results_dir) = args.build_results_dir {
PipelineDownloadBinaries::OnSuccess {
Expand Down Expand Up @@ -1266,6 +1269,7 @@ mod tests {
download_binaries: bool,
) {
const TEST_JOB_RUNNER_TAG: &str = "test-tag";
const TEST_MONITOR_TIMEOUT: &str = "1 day";
const TEST_BUILD_RESULTS_DIR: &str = "results";
const TEST_BUILD_RESULT: &str = "test-build-result";
const TEST_BUILD_RESULT_CONTENTS: &[u8] = b"abcdef";
Expand Down Expand Up @@ -1307,8 +1311,8 @@ mod tests {
);

let mut generate_command = format!(
"generate-monitor {} --rules '[{{a: 1}}, {{b: 2}}]'",
TEST_JOB_RUNNER_TAG
"generate-monitor {} --job-timeout '{}' --rules '[{{a: 1}}, {{b: 2}}]'",
TEST_JOB_RUNNER_TAG, TEST_MONITOR_TIMEOUT
);
if download_binaries {
generate_command += &format!(" --download-build-results-to {}", TEST_BUILD_RESULTS_DIR);
Expand Down Expand Up @@ -1432,6 +1436,13 @@ mod tests {
assert_eq!(tags.len(), 1);
assert_eq!(tags[0].as_str().unwrap(), TEST_JOB_RUNNER_TAG);

let timeout = monitor_map
.get(&"timeout".into())
.unwrap()
.as_str()
.unwrap();
assert_eq!(timeout, TEST_MONITOR_TIMEOUT);

let rules: Vec<_> = monitor_map
.get(&"rules".into())
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::{
};
use tracing::{debug, instrument};

use crate::retry::{retry_large_request, retry_request};
use crate::retry::retry_request;

#[derive(Debug)]
pub enum PackageCompletion {
Expand Down Expand Up @@ -245,7 +245,7 @@ impl ObsMonitor {
pub async fn download_build_log(&self) -> Result<LogFile> {
const LOG_LEN_TO_CHECK_FOR_MD5: u64 = 2500;

let mut file = retry_large_request(|| async {
let mut file = retry_request(|| async {
let mut file = AsyncFile::from_std(
tempfile::tempfile().wrap_err("Failed to create tempfile to build log")?,
);
Expand Down
4 changes: 4 additions & 0 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct GeneratePipelineOptions {
pub tags: Vec<String>,
pub artifact_expiration: String,
pub prefix: String,
pub timeout: Option<String>,
pub rules: Option<String>,
pub build_log_out: String,
pub download_binaries: PipelineDownloadBinaries,
Expand All @@ -35,6 +36,8 @@ struct JobSpec {
before_script: Vec<String>,
script: Vec<String>,
after_script: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
timeout: Option<String>,
artifacts: ArtifactsSpec,
#[serde(skip_serializing_if = "Option::is_none")]
rules: Option<serde_yaml::Sequence>,
Expand Down Expand Up @@ -114,6 +117,7 @@ pub fn generate_monitor_pipeline(
// ensure that they're set to be empty.
before_script: vec![],
after_script: vec![],
timeout: options.timeout.clone(),
artifacts: ArtifactsSpec {
paths: artifact_paths,
when: "always".to_owned(),
Expand Down
Loading
Loading