Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
ff6cc941d8
commit
1d7c056925
@ -3,16 +3,12 @@ use serde::Serialize;
|
|||||||
use crate::services::artifacts_db::{AddCommitArtifact, GetLatestArtifact};
|
use crate::services::artifacts_db::{AddCommitArtifact, GetLatestArtifact};
|
||||||
use crate::services::file_store::FileStore;
|
use crate::services::file_store::FileStore;
|
||||||
|
|
||||||
use super::archive::Archive;
|
|
||||||
use super::artifacts_db::ArtifactsDB;
|
use super::artifacts_db::ArtifactsDB;
|
||||||
use super::domain_events::DomainEvents;
|
use super::domain_events::DomainEvents;
|
||||||
use super::file_reader::FileReader;
|
|
||||||
|
|
||||||
use self::models::*;
|
use self::models::*;
|
||||||
|
|
||||||
pub struct ReleaseManager {
|
pub struct ReleaseManager {
|
||||||
archive: Archive,
|
|
||||||
file_reader: FileReader,
|
|
||||||
file_store: FileStore,
|
file_store: FileStore,
|
||||||
domain_events: DomainEvents,
|
domain_events: DomainEvents,
|
||||||
artifacts_db: ArtifactsDB,
|
artifacts_db: ArtifactsDB,
|
||||||
@ -20,15 +16,11 @@ pub struct ReleaseManager {
|
|||||||
|
|
||||||
impl ReleaseManager {
|
impl ReleaseManager {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
file_reader: FileReader,
|
|
||||||
file_store: FileStore,
|
file_store: FileStore,
|
||||||
archive: Archive,
|
|
||||||
domain_events: DomainEvents,
|
domain_events: DomainEvents,
|
||||||
artifacts_db: ArtifactsDB,
|
artifacts_db: ArtifactsDB,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
archive,
|
|
||||||
file_reader,
|
|
||||||
file_store,
|
file_store,
|
||||||
domain_events,
|
domain_events,
|
||||||
artifacts_db,
|
artifacts_db,
|
||||||
@ -83,15 +75,30 @@ impl ReleaseManager {
|
|||||||
"releasing latest commit"
|
"releasing latest commit"
|
||||||
);
|
);
|
||||||
|
|
||||||
let artifact = self
|
let latest_artifact = self
|
||||||
.artifacts_db
|
.artifacts_db
|
||||||
.get_latest_artifact(GetLatestArtifact {
|
.get_latest_artifact(GetLatestArtifact {
|
||||||
app: release_req.app,
|
app: release_req.app.clone(),
|
||||||
branch: release_req.branch,
|
branch: release_req.branch.clone(),
|
||||||
})
|
})
|
||||||
.await?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -102,5 +109,12 @@ pub struct CommittedArtifactEvent {
|
|||||||
artifact_id: String,
|
artifact_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct PublishedArtifactEvent {
|
||||||
|
app: String,
|
||||||
|
branch: String,
|
||||||
|
artifact_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub mod extensions;
|
pub mod extensions;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
app::SharedApp,
|
app::SharedApp,
|
||||||
services::{
|
services::{
|
||||||
archive::extensions::ArchiveExt,
|
artifacts_db::extensions::ArtifactsDBExt, domain_events::extensions::DomainEventsExt,
|
||||||
artifacts_db::{extensions::ArtifactsDBExt, AddCommitArtifact},
|
|
||||||
domain_events::extensions::DomainEventsExt,
|
|
||||||
file_reader::extensions::FileReaderExt,
|
|
||||||
file_store::extensions::FileStoreExt,
|
file_store::extensions::FileStoreExt,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CommitArtifact, ReleaseManager};
|
use super::ReleaseManager;
|
||||||
|
|
||||||
pub trait ReleaseManagerExt {
|
pub trait ReleaseManagerExt {
|
||||||
fn release_manager(&self) -> ReleaseManager;
|
fn release_manager(&self) -> ReleaseManager;
|
||||||
@ -17,12 +14,6 @@ pub trait ReleaseManagerExt {
|
|||||||
|
|
||||||
impl ReleaseManagerExt for SharedApp {
|
impl ReleaseManagerExt for SharedApp {
|
||||||
fn release_manager(&self) -> ReleaseManager {
|
fn release_manager(&self) -> ReleaseManager {
|
||||||
ReleaseManager::new(
|
ReleaseManager::new(self.file_store(), self.domain_events(), self.artifacts_db())
|
||||||
self.file_reader(),
|
|
||||||
self.file_store(),
|
|
||||||
self.archive(),
|
|
||||||
self.domain_events(),
|
|
||||||
self.artifacts_db(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,12 @@ impl TryFrom<String> for ArtifactID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<uuid::Uuid> for ArtifactID {
|
||||||
|
fn from(value: uuid::Uuid) -> Self {
|
||||||
|
Self(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct UploadArtifact {
|
pub struct UploadArtifact {
|
||||||
pub file_path: PathBuf,
|
pub file_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 2. Verify that we've splatted the flux cluster over the upstream registry
|
||||||
// 3. Verify database has a release record
|
// 3. Verify database has a release record
|
||||||
|
|
||||||
todo!();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user