feat: download archive
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-02-22 18:36:44 +01:00
parent ff6cc941d8
commit 1d7c056925
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
4 changed files with 35 additions and 26 deletions

View File

@ -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;

View File

@ -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())
}
}

View File

@ -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 file_path: PathBuf,
}

View File

@ -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(())
}