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

fix: fix toolchain tags patch hack #1754

Closed
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
25 changes: 22 additions & 3 deletions packages/services/build/src/ops/patch_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ pub async fn patch_tags(ctx: &OperationCtx, input: &Input) -> GlobalResult<Outpu
FROM db_build.builds
WHERE build_id = $1
),
split_exclusive_tags AS (
SELECT key, value
FROM jsonb_each($2)
),
filter_tags AS (
-- Combine the now filtered kv pairs back into an object
SELECT build_id, jsonb_object_agg(key, value) AS tags
Expand All @@ -80,8 +84,15 @@ pub async fn patch_tags(ctx: &OperationCtx, input: &Input) -> GlobalResult<Outpu
) OR
b.env_id = (SELECT env_id FROM build_data)
) AND
-- Check that build has the exclusive tags to begin with (pre-filtering)
b.tags @> $2
-- Check that build has any of the exclusive tags to begin with (pre-filtering)
(
SELECT EXISTS (
SELECT 1
FROM split_exclusive_tags
WHERE b.tags @> jsonb_build_object(key, value)
LIMIT 1
)
)
GROUP BY build_id
)
UPDATE db_build.builds AS b
Expand Down Expand Up @@ -109,7 +120,15 @@ pub async fn patch_tags(ctx: &OperationCtx, input: &Input) -> GlobalResult<Outpu
) OR
b.env_id = (SELECT env_id FROM build_data)
) AND
b.tags @> $2
-- Check that build has any of the exclusive tags
(
SELECT EXISTS (
SELECT 1
FROM split_exclusive_tags
WHERE b.tags @> jsonb_build_object(key, value)
LIMIT 1
)
)
) AS f2
WHERE b.build_id = f2.build_id
",
Expand Down
8 changes: 5 additions & 3 deletions packages/services/build/tests/patch_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async fn multiple_exclusive_tags(ctx: TestCtx) {
("version".to_string(), Some("123".to_string())),
("current".to_string(), Some("true".to_string())),
]),
exclusive_tags: Some(vec!["version".to_string(), "current".to_string()]),
exclusive_tags: Some(vec!["current".to_string(), "version".to_string()]),
})
.await
.unwrap();
Expand All @@ -314,8 +314,9 @@ async fn multiple_exclusive_tags(ctx: TestCtx) {
("name".to_string(), Some("foo".to_string())),
("version".to_string(), Some("123".to_string())),
("current".to_string(), Some("true".to_string())),
("other".to_string(), Some("tag".to_string())),
]),
exclusive_tags: Some(vec!["version".to_string(), "current".to_string()]),
exclusive_tags: Some(vec!["version".to_string(), "current".to_string(), "other".to_string()]),
})
.await
.unwrap();
Expand All @@ -341,7 +342,8 @@ async fn multiple_exclusive_tags(ctx: TestCtx) {
HashMap::from([
("name".to_string(), Some("foo".to_string())),
("version".to_string(), Some("123".to_string())),
("current".to_string(), Some("true".to_string()))
("current".to_string(), Some("true".to_string())),
("other".to_string(), Some("tag".to_string()))
])
);
}
127 changes: 26 additions & 101 deletions packages/toolchain/toolchain/src/tasks/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,6 @@ async fn build_and_upload(
) -> Result<Uuid> {
task.log("");

// let mut tags = HashMap::from([
// (build::tags::VERSION.to_string(), version_name.to_string()),
// (build::tags::CURRENT.to_string(), "true".to_string()),
// ]);
// tags.extend(build.tags.clone());

// let exclusive_tags = vec![
// build::tags::VERSION.to_string(),
// build::tags::CURRENT.to_string(),
// ];

// Build & upload
let build_tags = build
.full_tags(build_name)
Expand Down Expand Up @@ -202,99 +191,35 @@ async fn build_and_upload(
}
};

// // Tag build
// let complete_res = apis::actor_builds_api::actor_builds_patch_tags(
// &ctx.openapi_config_cloud,
// &build_id.to_string(),
// models::ActorPatchBuildTagsRequest {
// tags: Some(serde_json::to_value(&tags)?),
// exclusive_tags: Some(exclusive_tags.clone()),
// },
// Some(&ctx.project.name_id),
// Some(&env.slug),
// )
// .await;
// if let Err(err) = complete_res.as_ref() {
// task.log(format!("{err:?}"));
// }
// complete_res.context("complete_res")?;

// HACK: Multiple exclusive tags doesn't work atm
{
let complete_res = apis::actor_builds_api::actor_builds_patch_tags(
&ctx.openapi_config_cloud,
&build_id.to_string(),
models::ActorPatchBuildTagsRequest {
tags: Some(serde_json::to_value(&build_tags)?),
exclusive_tags: None,
},
Some(&ctx.project.name_id),
Some(&env.slug),
)
.await;
if let Err(err) = complete_res.as_ref() {
task.log(format!("{err:?}"));
}
complete_res.context("complete_res")?;

let complete_res = apis::actor_builds_api::actor_builds_patch_tags(
&ctx.openapi_config_cloud,
&build_id.to_string(),
models::ActorPatchBuildTagsRequest {
tags: Some(serde_json::json!({
build::tags::ACCESS: build.access,
})),
exclusive_tags: None,
},
Some(&ctx.project.name_id),
Some(&env.slug),
)
.await;
if let Err(err) = complete_res.as_ref() {
task.log(format!("{err:?}"));
}
complete_res.context("complete_res")?;
let mut tags = HashMap::from([
(build::tags::VERSION.to_string(), version_name.to_string()),
(build::tags::CURRENT.to_string(), "true".to_string()),
]);
if let Some(build_tags) = build.tags.clone() {
tags.extend(build_tags.clone());
}

let complete_res = apis::actor_builds_api::actor_builds_patch_tags(
&ctx.openapi_config_cloud,
&build_id.to_string(),
models::ActorPatchBuildTagsRequest {
tags: Some(serde_json::to_value(&HashMap::from([(
build::tags::CURRENT.to_string(),
"true".to_string(),
)]))?),
exclusive_tags: Some(vec![build::tags::CURRENT.to_string()]),
},
Some(&ctx.project.name_id),
Some(&env.slug),
)
.await;
if let Err(err) = complete_res.as_ref() {
task.log(format!("{err:?}"));
}
complete_res.context("complete_res")?;
let exclusive_tags = vec![
build::tags::VERSION.to_string(),
build::tags::CURRENT.to_string(),
];

let complete_res = apis::actor_builds_api::actor_builds_patch_tags(
&ctx.openapi_config_cloud,
&build_id.to_string(),
models::ActorPatchBuildTagsRequest {
tags: Some(serde_json::to_value(&HashMap::from([(
build::tags::VERSION.to_string(),
version_name.to_string(),
)]))?),
// TODO: This does not behave correctly atm
exclusive_tags: None,
// exclusive_tags: Some(vec![build::tags::VERSION.to_string()]),
},
Some(&ctx.project.name_id),
Some(&env.slug),
)
.await;
if let Err(err) = complete_res.as_ref() {
task.log(format!("{err:?}"));
}
complete_res.context("complete_res")?;
// Tag build
let complete_res = apis::actor_builds_api::actor_builds_patch_tags(
&ctx.openapi_config_cloud,
&build_id.to_string(),
models::ActorPatchBuildTagsRequest {
tags: Some(serde_json::to_value(&tags)?),
exclusive_tags: Some(exclusive_tags.clone()),
},
Some(&ctx.project.name_id),
Some(&env.slug),
)
.await;
if let Err(err) = complete_res.as_ref() {
task.log(format!("{err:?}"));
}
complete_res.context("complete_res")?;

// Upgrade actors
task.log(format!("[Upgrading Actors]"));
Expand Down
Loading