From 1d7c0569256d24835389889d266bfb307e162247 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Thu, 22 Feb 2024 18:36:44 +0100 Subject: [PATCH] feat: download archive Signed-off-by: kjuulh --- .../src/services/release_manager.rs | 38 +++++++++++++------ .../services/release_manager/extensions.rs | 15 ++------ .../src/services/release_manager/models.rs | 6 +++ .../flux-releaser/tests/publish_artifacts.rs | 2 - 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/crates/flux-releaser/src/services/release_manager.rs b/crates/flux-releaser/src/services/release_manager.rs index 48251cc..bd939f3 100644 --- a/crates/flux-releaser/src/services/release_manager.rs +++ b/crates/flux-releaser/src/services/release_manager.rs @@ -3,16 +3,12 @@ use serde::Serialize; use crate::services::artifacts_db::{AddCommitArtifact, GetLatestArtifact}; use crate::services::file_store::FileStore; -use super::archive::Archive; use super::artifacts_db::ArtifactsDB; use super::domain_events::DomainEvents; -use super::file_reader::FileReader; use self::models::*; pub struct ReleaseManager { - archive: Archive, - file_reader: FileReader, file_store: FileStore, domain_events: DomainEvents, artifacts_db: ArtifactsDB, @@ -20,15 +16,11 @@ pub struct ReleaseManager { impl ReleaseManager { pub fn new( - file_reader: FileReader, file_store: FileStore, - archive: Archive, domain_events: DomainEvents, artifacts_db: ArtifactsDB, ) -> Self { Self { - archive, - file_reader, file_store, domain_events, artifacts_db, @@ -83,15 +75,30 @@ impl ReleaseManager { "releasing latest commit" ); - let artifact = self + let latest_artifact = self .artifacts_db .get_latest_artifact(GetLatestArtifact { - app: release_req.app, - branch: release_req.branch, + app: release_req.app.clone(), + branch: release_req.branch.clone(), }) .await?; - tracing::trace!("found latest artifact: {:?}", artifact); + tracing::trace!("found latest artifact: {:?}", latest_artifact); + + let artifact = self + .file_store + .get_archive(latest_artifact.artifact_id.into()) + .await?; + + tracing::trace!("placed artifact in: {}", artifact.display()); + + self.domain_events + .publish_event(&serde_json::to_string(&PublishedArtifactEvent { + artifact_id: latest_artifact.artifact_id.to_string(), + app: release_req.app, + branch: release_req.branch, + })?) + .await?; Ok(()) } @@ -102,5 +109,12 @@ pub struct CommittedArtifactEvent { artifact_id: String, } +#[derive(Serialize)] +pub struct PublishedArtifactEvent { + app: String, + branch: String, + artifact_id: String, +} + pub mod extensions; pub mod models; diff --git a/crates/flux-releaser/src/services/release_manager/extensions.rs b/crates/flux-releaser/src/services/release_manager/extensions.rs index 6e5f298..e87aa30 100644 --- a/crates/flux-releaser/src/services/release_manager/extensions.rs +++ b/crates/flux-releaser/src/services/release_manager/extensions.rs @@ -1,15 +1,12 @@ use crate::{ app::SharedApp, services::{ - archive::extensions::ArchiveExt, - artifacts_db::{extensions::ArtifactsDBExt, AddCommitArtifact}, - domain_events::extensions::DomainEventsExt, - file_reader::extensions::FileReaderExt, + artifacts_db::extensions::ArtifactsDBExt, domain_events::extensions::DomainEventsExt, file_store::extensions::FileStoreExt, }, }; -use super::{CommitArtifact, ReleaseManager}; +use super::ReleaseManager; pub trait ReleaseManagerExt { fn release_manager(&self) -> ReleaseManager; @@ -17,12 +14,6 @@ pub trait ReleaseManagerExt { impl ReleaseManagerExt for SharedApp { fn release_manager(&self) -> ReleaseManager { - ReleaseManager::new( - self.file_reader(), - self.file_store(), - self.archive(), - self.domain_events(), - self.artifacts_db(), - ) + ReleaseManager::new(self.file_store(), self.domain_events(), self.artifacts_db()) } } diff --git a/crates/flux-releaser/src/services/release_manager/models.rs b/crates/flux-releaser/src/services/release_manager/models.rs index 2b18475..35091b9 100644 --- a/crates/flux-releaser/src/services/release_manager/models.rs +++ b/crates/flux-releaser/src/services/release_manager/models.rs @@ -41,6 +41,12 @@ impl TryFrom for ArtifactID { } } +impl From for ArtifactID { + fn from(value: uuid::Uuid) -> Self { + Self(value) + } +} + pub struct UploadArtifact { pub file_path: PathBuf, } diff --git a/crates/flux-releaser/tests/publish_artifacts.rs b/crates/flux-releaser/tests/publish_artifacts.rs index 24e8e31..20567bf 100644 --- a/crates/flux-releaser/tests/publish_artifacts.rs +++ b/crates/flux-releaser/tests/publish_artifacts.rs @@ -231,8 +231,6 @@ async fn can_trigger_latest_release() -> anyhow::Result<()> { // 2. Verify that we've splatted the flux cluster over the upstream registry // 3. Verify database has a release record - todo!(); - Ok(()) }