-
Notifications
You must be signed in to change notification settings - Fork 35
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
suppress autobuild in builder api #1680
Conversation
@@ -6,6 +6,7 @@ targets = ["x86_64-linux", "x86_64-linux-kernel2", "x86_64-windows"] | |||
build_targets = ["x86_64-linux", "x86_64-linux-kernel2", "x86_64-windows"] | |||
build_on_upload = true | |||
saas_bldr_url = "https://bldr.habitat.sh" | |||
suppress_autobuild_origins = "test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be []
since we would not want to suppress any origins by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing
components/builder-api/src/config.rs
Outdated
@@ -136,7 +138,8 @@ impl Default for ApiCfg { | |||
features_enabled: vec!["jobsrv".to_string()], | |||
build_on_upload: true, | |||
private_max_age: 300, | |||
saas_bldr_url: "https://bldr.habitat.sh".to_string(), } | |||
saas_bldr_url: "https://bldr.habitat.sh".to_string(), | |||
suppress_autobuild_origins: vec!["test".to_string()], } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per comment above, we don't want test
to be the default.
@@ -109,6 +109,8 @@ pub struct ApiCfg { | |||
pub build_on_upload: bool, | |||
pub private_max_age: usize, | |||
pub saas_bldr_url: String, | |||
#[serde(with = "deserialize_into_vec")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deserialize_into_vec
will transform origins to uppercase but actual origins can be mixed case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add and use a similar function like deserialize_into_vec.
IMO deserialize_into_vec should have something in its name to indicate that it is changing the case.
Like:
deserialize_into_vec_upper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need a deserializer. I think a Vec<String>
should work as is. Like bootstrap_nodes
in
pub bootstrap_nodes: Vec<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but does that change how user will enter these using "hab config apply"?
After making the change, the test case in config.rs fails here:
let config = Config::from_raw(content).unwrap();
The test line:
suppress_autobuild_origins = "origin1, origin2"
Fails to load unless I change it to ["origin1", "origin2"], which would be awkward if the user
has to enter this at the command line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right it would need to be a proper toml array. That format is in line with other config we have. If you wanted to stick with "origin1, origin2" I think you would need to create a deserializer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I think we should stick to whatever convention we are already using.
@@ -408,3 +414,28 @@ async fn read_plan_targets(github: &GitHubClient, | |||
|
|||
Ok(targets) | |||
} | |||
|
|||
fn suppress_autobuild_for_origin(config: &Config, origin: &str) -> bool { | |||
config.api.suppress_autobuild_origins.contains(&origin.to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just keep this inline since it is just a one-liner and not used anywhere else?
use crate::server::services::github::suppress_autobuild_for_origin; | ||
|
||
#[test] | ||
fn suppress_autobuild_verify() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really just testing contains
applied to a vector so Its probably not gaining us much coverage. However, I think you could make a small refactoring to build_plans
to factor out the db call and allow for the creation of a dummy Project
and get much better unit test coverage of this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not clear on how we can create a dummy Project and pass it in to build_plans. If we passed a Project in, then we are now building a project, not the plans. We would move the plans iterator out of this function, then it would become build_plan.
Please clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh right. That iterator complicates this. Well you could still extract more logic into something like:
fn should_reject_build(plan: &PlanWithTarget, project: Project, config: &Config, repo_url: &str) -> bool {
if repo_url != project.vcs_data {
warn!("Repo URL ({}) doesn't match project vcs data ({}). Aborting.",
repo_url, project.vcs_data);
return true;
}
if !config.api.build_targets.contains(&plan.1) {
debug!("Rejecting build with target: {:?}", plan.1);
return true;
}
if config.api.suppress_autobuild_origins.contains(&plan.0.origin.to_string()) {
debug!("Skipping autobuild for origin {:?}", &plan.0.origin);
return true;
}
return false
}
And here would be an example "happy path" test:
#[test]
fn valid_plan_is_not_rejected() {
let mut config = Config::default();
config.api.suppress_autobuild_origins = vec!["hest".to_string(), "sest".to_string()];
let project = Project { id: 1,
owner_id: 1,
origin: "origin".to_string(),
package_name: "pkg".to_string(),
name: "origin/pkg".to_string(),
plan_path: "plan.sh".to_string(),
target: "x86_64-linux".to_string(),
vcs_type: "git".to_string(),
vcs_data: "https://github.com/habitat-sh/testapp.git".to_string(),
vcs_installation_id: None,
auto_build: true,
created_at: None,
updated_at: None };
let plan = PlanWithTarget(Plan { name: "pkg".to_string(),
origin: "origin".to_string(),
version: None},
PackageTarget::from_str("x86_64-linux").unwrap());
assert_eq!(should_reject_build(&plan, project, &config, "https://github.com/habitat-sh/testapp.git"), false);
}
I'd leave it up to you if you wanted to add something like that. I'm just not sure if the test as it stands in the PR is worth including.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this makes sense. We can encapsulate the failure and test each separately. I think it is good to have coverage for all of these so I'll go ahead and add tests for the repo_url and build_targets check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not include the top two shell scripts in this PR. I can see how it would help you as you build this but we already have end to end tests around hab config apply. See the first couple test cases in https://github.com/habitat-sh/habitat/tree/main/test/end-to-end/multi-supervisor/testcases.
let mut config = Config::default(); | ||
config.api.suppress_autobuild_origins = vec!["hest".to_string(), "sest".to_string()]; | ||
|
||
let project = Project { id: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might extract create_project
and a create_plan
functions that return a mutable project and a mutable plan and also have them take origin
, package
, target
, and repo_url
args. You could then reuse them in all the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing me to the hab config apply testing. I still would like to see that this succeeds inside of builder-api by observing whether or not the build kicks off depending on the current origin set defined in suppress_autobuild_origins.
e1440a3
to
b1404a6
Compare
Signed-off-by: pozsgaic <pozsgai@progress.com>
b1404a6
to
62c82a5
Compare
Code to suppress autobuild using via cli command "hab config apply"