mirror of
https://github.com/jlengrand/engine.git
synced 2026-03-10 08:11:21 +00:00
Add more logs
This commit is contained in:
@@ -13,7 +13,11 @@ use rusoto_sts::{GetCallerIdentityRequest, Sts, StsClient};
|
||||
use crate::build_platform::Image;
|
||||
use crate::container_registry::errors::ContainerRegistryError;
|
||||
use crate::container_registry::{ContainerRegistry, ContainerRegistryInfo, Kind};
|
||||
use crate::models::{Context, Listen, Listener, Listeners};
|
||||
use crate::events::{EngineEvent, EventMessage, GeneralStep, Stage};
|
||||
use crate::logger::Logger;
|
||||
use crate::models::{
|
||||
Context, Listen, Listener, Listeners, ListenersHelper, ProgressInfo, ProgressLevel, ProgressScope,
|
||||
};
|
||||
use crate::runtime::block_on;
|
||||
use retry::delay::Fixed;
|
||||
use retry::Error::Operation;
|
||||
@@ -30,6 +34,7 @@ pub struct ECR {
|
||||
region: Region,
|
||||
registry_info: Option<ContainerRegistryInfo>,
|
||||
listeners: Listeners,
|
||||
logger: Box<dyn Logger>,
|
||||
}
|
||||
|
||||
impl ECR {
|
||||
@@ -40,6 +45,7 @@ impl ECR {
|
||||
access_key_id: &str,
|
||||
secret_access_key: &str,
|
||||
region: &str,
|
||||
logger: Box<dyn Logger>,
|
||||
) -> Result<Self, ContainerRegistryError> {
|
||||
let mut cr = ECR {
|
||||
context,
|
||||
@@ -50,6 +56,7 @@ impl ECR {
|
||||
region: Region::from_str(region).unwrap(),
|
||||
registry_info: None,
|
||||
listeners: vec![],
|
||||
logger,
|
||||
};
|
||||
|
||||
let credentials = cr.get_credentials()?;
|
||||
@@ -57,6 +64,7 @@ impl ECR {
|
||||
let _ = registry_url.set_username(&credentials.access_token);
|
||||
let _ = registry_url.set_password(Some(&credentials.password));
|
||||
|
||||
cr.log_info(format!("🔓 Login to ECR registry {}", credentials.endpoint_url));
|
||||
let _ = cr
|
||||
.context
|
||||
.docker
|
||||
@@ -76,6 +84,23 @@ impl ECR {
|
||||
Ok(cr)
|
||||
}
|
||||
|
||||
pub fn log_info(&self, msg: String) {
|
||||
self.logger.log(EngineEvent::Info(
|
||||
self.get_event_details(Stage::General(GeneralStep::ValidateSystemRequirements)),
|
||||
EventMessage::new_from_safe(msg.clone()),
|
||||
));
|
||||
|
||||
let lh = ListenersHelper::new(&self.listeners);
|
||||
lh.deployment_in_progress(ProgressInfo::new(
|
||||
ProgressScope::Environment {
|
||||
id: self.context.execution_id().to_string(),
|
||||
},
|
||||
ProgressLevel::Info,
|
||||
Some(msg),
|
||||
self.context.execution_id(),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn credentials(&self) -> StaticProvider {
|
||||
StaticProvider::new(self.access_key_id.to_string(), self.secret_access_key.to_string(), None, None)
|
||||
}
|
||||
@@ -225,6 +250,8 @@ impl ECR {
|
||||
}
|
||||
|
||||
fn get_or_create_repository(&self, repository_name: &str) -> Result<Repository, ContainerRegistryError> {
|
||||
self.log_info(format!("🗂️ Provisioning container repository {}", repository_name));
|
||||
|
||||
// check if the repository already exists
|
||||
let repository = self.get_repository(repository_name);
|
||||
if let Some(repo) = repository {
|
||||
|
||||
@@ -4,8 +4,8 @@ use url::Url;
|
||||
use crate::build_platform::Image;
|
||||
use crate::container_registry::errors::ContainerRegistryError;
|
||||
use crate::errors::EngineError;
|
||||
use crate::events::EventDetails;
|
||||
use crate::models::{Context, Listen};
|
||||
use crate::events::{EventDetails, Stage, Transmitter};
|
||||
use crate::models::{Context, Listen, QoveryIdentifier};
|
||||
|
||||
pub mod docr;
|
||||
pub mod ecr;
|
||||
@@ -36,6 +36,21 @@ pub trait ContainerRegistry: Listen {
|
||||
|
||||
// Check on the registry if a specific image already exist
|
||||
fn does_image_exists(&self, image: &Image) -> bool;
|
||||
|
||||
fn get_event_details(&self, stage: Stage) -> EventDetails {
|
||||
let context = self.context();
|
||||
let ev = EventDetails::new(
|
||||
None,
|
||||
QoveryIdentifier::from(context.organization_id().to_string()),
|
||||
QoveryIdentifier::from(context.cluster_id().to_string()),
|
||||
QoveryIdentifier::from(context.execution_id().to_string()),
|
||||
None,
|
||||
stage,
|
||||
Transmitter::ContainerRegistry(self.id().to_string(), self.name().to_string()),
|
||||
);
|
||||
|
||||
ev
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_engine_error(event_details: EventDetails, err: ContainerRegistryError) -> EngineError {
|
||||
|
||||
@@ -32,7 +32,7 @@ pub const AWS_DATABASE_INSTANCE_TYPE: &str = "db.t3.micro";
|
||||
pub const AWS_DATABASE_DISK_TYPE: &str = "gp2";
|
||||
pub const AWS_RESOURCE_TTL_IN_SECONDS: u32 = 7200;
|
||||
|
||||
pub fn container_registry_ecr(context: &Context) -> ECR {
|
||||
pub fn container_registry_ecr(context: &Context, logger: Box<dyn Logger>) -> ECR {
|
||||
let secrets = FuncTestsSecrets::new();
|
||||
if secrets.AWS_ACCESS_KEY_ID.is_none()
|
||||
|| secrets.AWS_SECRET_ACCESS_KEY.is_none()
|
||||
@@ -49,6 +49,7 @@ pub fn container_registry_ecr(context: &Context) -> ECR {
|
||||
secrets.AWS_ACCESS_KEY_ID.unwrap().as_str(),
|
||||
secrets.AWS_SECRET_ACCESS_KEY.unwrap().as_str(),
|
||||
secrets.AWS_DEFAULT_REGION.unwrap().as_str(),
|
||||
logger,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@@ -73,7 +74,7 @@ impl Cluster<AWS, Options> for AWS {
|
||||
vpc_network_mode: Option<VpcQoveryNetworkMode>,
|
||||
) -> EngineConfig {
|
||||
// use ECR
|
||||
let container_registry = Box::new(container_registry_ecr(context));
|
||||
let container_registry = Box::new(container_registry_ecr(context, logger.clone()));
|
||||
|
||||
// use LocalDocker
|
||||
let build_platform = Box::new(build_platform_local_docker(context, logger.clone()));
|
||||
|
||||
Reference in New Issue
Block a user