Add test for build phase + fix for DO registry (#666)

This commit is contained in:
Erèbe - Romain Gerard
2022-03-25 16:28:36 +01:00
committed by GitHub
parent 603c5c3ff6
commit 08a6833b1c
9 changed files with 204 additions and 7 deletions

View File

@@ -153,6 +153,12 @@ impl Image {
pub fn name(&self) -> String {
self.name.clone()
}
pub fn name_without_repository(&self) -> &str {
self.name
.strip_prefix(&format!("{}/", self.repository_name()))
.unwrap_or(&self.name)
}
}
impl Default for Image {

View File

@@ -201,7 +201,7 @@ impl ContainerRegistry for DOCR {
let url = format!(
"https://api.digitalocean.com/v2/registry/{}/repositories/{}/tags",
image.registry_name,
image.name()
image.name_without_repository()
);
let res = reqwest::blocking::Client::new()

View File

@@ -93,13 +93,23 @@ impl<'a> Transaction<'a> {
)
}
pub fn build_environment(
&mut self,
environment: &Rc<RefCell<Environment>>,
option: DeploymentOption,
) -> Result<(), EnvironmentError> {
self.steps.push(Step::BuildEnvironment(environment.clone(), option));
Ok(())
}
pub fn deploy_environment_with_options(
&mut self,
environment: &Rc<RefCell<Environment>>,
option: DeploymentOption,
) -> Result<(), EnvironmentError> {
// add build step
self.steps.push(Step::BuildEnvironment(environment.clone(), option));
self.build_environment(environment, option)?;
// add deployment step
self.steps.push(Step::DeployEnvironment(environment.clone()));

View File

@@ -25,6 +25,7 @@ use qovery_engine::cloud_provider::aws::AWS;
use qovery_engine::cloud_provider::digitalocean::application::DoRegion;
use qovery_engine::cloud_provider::digitalocean::kubernetes::DOKS;
use qovery_engine::cloud_provider::digitalocean::DO;
use qovery_engine::cloud_provider::environment::Environment;
use qovery_engine::cloud_provider::kubernetes::Kubernetes;
use qovery_engine::cloud_provider::models::NodeGroups;
use qovery_engine::cloud_provider::scaleway::application::ScwZone;
@@ -70,18 +71,27 @@ pub trait Cluster<T, U> {
}
pub trait Infrastructure {
fn build_environment(
&self,
environment: &EnvironmentRequest,
logger: Box<dyn Logger>,
engine_config: &EngineConfig,
) -> (Environment, TransactionResult);
fn deploy_environment(
&self,
environment: &EnvironmentRequest,
logger: Box<dyn Logger>,
engine_config: &EngineConfig,
) -> TransactionResult;
fn pause_environment(
&self,
environment: &EnvironmentRequest,
logger: Box<dyn Logger>,
engine_config: &EngineConfig,
) -> TransactionResult;
fn delete_environment(
&self,
environment: &EnvironmentRequest,
@@ -91,6 +101,33 @@ pub trait Infrastructure {
}
impl Infrastructure for EnvironmentRequest {
fn build_environment(
&self,
environment: &EnvironmentRequest,
logger: Box<dyn Logger>,
engine_config: &EngineConfig,
) -> (Environment, TransactionResult) {
let mut tx = Transaction::new(engine_config, logger.clone(), Box::new(|| false), Box::new(|_| {})).unwrap();
let env = environment.to_environment_domain(
engine_config.context(),
engine_config.cloud_provider(),
engine_config.container_registry().registry_info(),
logger,
);
let env = Rc::new(RefCell::new(env));
let _ = tx.build_environment(
&env,
DeploymentOption {
force_build: true,
force_push: true,
},
);
let ret = tx.commit();
(Rc::try_unwrap(env).ok().unwrap().into_inner(), ret)
}
fn deploy_environment(
&self,
environment: &EnvironmentRequest,

View File

@@ -16,9 +16,56 @@ use test_utilities::aws::aws_default_engine_config;
use test_utilities::utilities::{context, init, kubernetes_config_path};
use tracing::{span, Level};
// TODO:
// - Tests that applications are always restarted when receiving a CREATE action
// see: https://github.com/Qovery/engine/pull/269
#[cfg(feature = "test-aws-self-hosted")]
#[named]
#[test]
fn aws_test_build_phase() {
// This test tries to run up to the build phase of the engine
// basically building and pushing each applications
let test_name = function_name!();
engine_run_test(|| {
init();
let span = span!(Level::INFO, "test", name = test_name);
let _enter = span.enter();
let logger = logger();
let secrets = FuncTestsSecrets::new();
let context = context(
secrets
.AWS_TEST_ORGANIZATION_ID
.as_ref()
.expect("AWS_TEST_ORGANIZATION_ID is not set")
.as_str(),
secrets
.AWS_TEST_CLUSTER_ID
.as_ref()
.expect("AWS_TEST_CLUSTER_ID is not set")
.as_str(),
);
let engine_config = aws_default_engine_config(&context, logger.clone());
let mut environment = test_utilities::common::working_minimal_environment(
&context,
secrets
.DEFAULT_TEST_DOMAIN
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
.as_str(),
);
environment.routers = vec![];
let ea = environment.clone();
let (env, ret) = environment.build_environment(&ea, logger.clone(), &engine_config);
assert!(matches!(ret, TransactionResult::Ok));
// Check the the image exist in the registry
let img_exist = engine_config
.container_registry()
.does_image_exists(&env.applications[0].get_build().image);
assert!(img_exist);
test_name.to_string()
})
}
#[cfg(feature = "test-aws-self-hosted")]
#[named]

View File

@@ -20,6 +20,54 @@ use tracing::{span, warn, Level};
// Note: All those tests relies on a test cluster running on DigitalOcean infrastructure.
// This cluster should be live in order to have those tests passing properly.
#[cfg(feature = "test-do-self-hosted")]
#[named]
#[test]
fn digitalocean_test_build_phase() {
let test_name = function_name!();
engine_run_test(|| {
init();
let span = span!(Level::INFO, "test", name = test_name);
let _enter = span.enter();
let secrets = FuncTestsSecrets::new();
let logger = logger();
let context = context(
secrets
.DIGITAL_OCEAN_TEST_ORGANIZATION_ID
.as_ref()
.expect("DIGITAL_OCEAN_TEST_ORGANIZATION_ID is not set"),
secrets
.DIGITAL_OCEAN_TEST_CLUSTER_ID
.as_ref()
.expect("DIGITAL_OCEAN_TEST_CLUSTER_ID is not set"),
);
let engine_config = do_default_engine_config(&context, logger.clone());
let environment = test_utilities::common::working_minimal_environment(
&context,
secrets
.DEFAULT_TEST_DOMAIN
.as_ref()
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
.as_str(),
);
let env_action = environment.clone();
let (env, ret) = environment.build_environment(&env_action, logger.clone(), &engine_config);
assert!(matches!(ret, TransactionResult::Ok));
// Check the the image exist in the registry
let img_exist = engine_config
.container_registry()
.does_image_exists(&env.applications[0].get_build().image);
assert!(img_exist);
test_name.to_string()
})
}
#[cfg(feature = "test-do-self-hosted")]
#[named]
#[test]

View File

@@ -1,6 +1,6 @@
#[macro_use]
extern crate maplit;
mod aws;
mod digitalocean;
mod scaleway;
mod unit;

View File

@@ -19,6 +19,56 @@ use tracing::{span, warn, Level};
// Note: All those tests relies on a test cluster running on Scaleway infrastructure.
// This cluster should be live in order to have those tests passing properly.
#[cfg(feature = "test-scw-self-hosted")]
#[named]
#[test]
fn scaleway_test_build_phase() {
let test_name = function_name!();
engine_run_test(|| {
init();
let span = span!(Level::INFO, "test", name = test_name);
let _enter = span.enter();
let logger = logger();
let secrets = FuncTestsSecrets::new();
let context = context(
secrets
.SCALEWAY_TEST_ORGANIZATION_ID
.as_ref()
.expect("SCALEWAY_TEST_ORGANIZATION_ID")
.as_str(),
secrets
.SCALEWAY_TEST_CLUSTER_ID
.as_ref()
.expect("SCALEWAY_TEST_CLUSTER_ID")
.as_str(),
);
let engine_config = scw_default_engine_config(&context, logger.clone());
let environment = test_utilities::common::working_minimal_environment(
&context,
secrets
.DEFAULT_TEST_DOMAIN
.as_ref()
.expect("DEFAULT_TEST_DOMAIN is not set in secrets")
.as_str(),
);
let env_action = environment.clone();
let (env, ret) = environment.build_environment(&env_action, logger.clone(), &engine_config);
assert!(matches!(ret, TransactionResult::Ok));
// Check the the image exist in the registry
let img_exist = engine_config
.container_registry()
.does_image_exists(&env.applications[0].get_build().image);
assert!(img_exist);
test_name.to_string()
})
}
#[cfg(feature = "test-scw-self-hosted")]
#[named]
#[test]

View File

@@ -1 +0,0 @@