mirror of
https://github.com/jlengrand/engine.git
synced 2026-03-10 08:11:21 +00:00
chore: update examples
chore: update README.md
This commit is contained in:
44
README.md
44
README.md
@@ -82,10 +82,48 @@ match tx.commit() {
|
||||
};
|
||||
```
|
||||
|
||||
Deploy an app on AWS
|
||||
Deploy an app from a Github repository on AWS
|
||||
```rust
|
||||
// TODO
|
||||
// create a session before
|
||||
//------------------------
|
||||
|
||||
let mut environment = Environment {...};
|
||||
|
||||
let app = Application {
|
||||
id: "app-id-1".to_string(),
|
||||
name: "app-name-1".to_string(),
|
||||
action: Action::Create, // create the application, you can also do other actions
|
||||
git_url: "https://github.com/Qovery/node-simple-example.git".to_string(),
|
||||
git_credentials: GitCredentials {
|
||||
login: "github-login".to_string(), // if the repository is a private one, then use credentials
|
||||
access_token: "github-access-token".to_string(),
|
||||
expired_at: Utc::now(), // it's provided by the Github API
|
||||
},
|
||||
branch: "main".to_string(),
|
||||
commit_id: "238f7f0454783defa4946613bc17ebbf4ccc514a".to_string(),
|
||||
dockerfile_path: "Dockerfile".to_string(),
|
||||
private_port: Some(3000),
|
||||
total_cpus: "1".to_string(),
|
||||
cpu_burst: "1.5".to_string(),
|
||||
total_ram_in_mib: 256,
|
||||
total_instances: 1,
|
||||
storage: vec![], // you can add persistent storage here
|
||||
environment_variables: vec![], // you can include env var here
|
||||
};
|
||||
|
||||
// add the app to the environment that we want to deploy
|
||||
environment.applications.push(app);
|
||||
|
||||
// open a transaction
|
||||
let mut tx = session.transaction();
|
||||
|
||||
// request to deploy the environment
|
||||
tx.deploy_environment(&EnvironmentAction::Environment(environment));
|
||||
|
||||
// commit and deploy the environment
|
||||
tx.commit();
|
||||
```
|
||||
*Note: the repository needs to have a Dockerfile at the root.*
|
||||
|
||||
## Documentation
|
||||
Full, comprehensive documentation is available on the Qovery website: https://docs.qovery.com
|
||||
@@ -117,7 +155,7 @@ At Qovery, we believe that the Cloud musts be simple than what it is today. Our
|
||||
Rust is underrated in the Cloud industry. At Qovery, we believe that Rust can help in building resilient, efficient, and performant products. Qovery wants to contribute to make Rust being a significant player in the Cloud industry for the next 10 years.
|
||||
|
||||
### Why do you use Terraform, Helm and Kubectl binaries?
|
||||
TODO
|
||||
The Qovery Engine is designed to operate as an administrator and takes decisions on the output of binaries, service, API, etc. Qovery uses the most efficient tools available in the market to manage resources.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use chrono::Utc;
|
||||
|
||||
use qovery_engine::build_platform::local_docker::LocalDocker;
|
||||
use qovery_engine::cloud_provider::aws::kubernetes::node::Node;
|
||||
use qovery_engine::cloud_provider::aws::kubernetes::{Options, EKS};
|
||||
use qovery_engine::cloud_provider::aws::AWS;
|
||||
use qovery_engine::cloud_provider::aws::kubernetes::{EKS, Options};
|
||||
use qovery_engine::cloud_provider::aws::kubernetes::node::Node;
|
||||
use qovery_engine::cloud_provider::TerraformStateCredentials;
|
||||
use qovery_engine::container_registry::ecr::ECR;
|
||||
use qovery_engine::dns_provider::cloudflare::Cloudflare;
|
||||
@@ -91,43 +92,6 @@ fn main() {
|
||||
let mut tx = session.transaction();
|
||||
tx.create_kubernetes(&eks);
|
||||
|
||||
let environment = Environment {
|
||||
execution_id: "unique-id".to_string(),
|
||||
id: "environment-id".to_string(),
|
||||
kind: Kind::Production,
|
||||
owner_id: "owner-id".to_string(),
|
||||
project_id: "project-id".to_string(),
|
||||
organization_id: "organization-id".to_string(),
|
||||
action: Action::Create,
|
||||
applications: vec![Application {
|
||||
id: "app-id-1".to_string(),
|
||||
name: "app-name-1".to_string(),
|
||||
action: Action::Create,
|
||||
git_url: "https://github.com/Qovery/node-simple-example.git".to_string(),
|
||||
git_credentials: GitCredentials {
|
||||
login: "github-login".to_string(),
|
||||
access_token: "github-access-token".to_string(),
|
||||
expired_at: Utc::now(),
|
||||
},
|
||||
branch: "main".to_string(),
|
||||
commit_id: "238f7f0454783defa4946613bc17ebbf4ccc514a".to_string(),
|
||||
dockerfile_path: "Dockerfile".to_string(),
|
||||
private_port: Some(3000),
|
||||
total_cpus: "256m".to_string(),
|
||||
cpu_burst: "500m".to_string(),
|
||||
total_ram_in_mib: 256,
|
||||
total_instances: 1,
|
||||
storage: vec![],
|
||||
environment_variables: vec![],
|
||||
}],
|
||||
routers: vec![],
|
||||
databases: vec![],
|
||||
external_services: vec![],
|
||||
clone_from_environment_id: None,
|
||||
};
|
||||
|
||||
tx.deploy_environment(&eks, &EnvironmentAction::Environment(environment));
|
||||
|
||||
match tx.commit() {
|
||||
TransactionResult::Ok => println!("infrastructure initialization OK"),
|
||||
TransactionResult::Rollback(commit_err) => {
|
||||
|
||||
141
examples/deploy_app_on_aws.rs
Normal file
141
examples/deploy_app_on_aws.rs
Normal file
@@ -0,0 +1,141 @@
|
||||
use chrono::Utc;
|
||||
|
||||
use qovery_engine::build_platform::local_docker::LocalDocker;
|
||||
use qovery_engine::cloud_provider::aws::AWS;
|
||||
use qovery_engine::cloud_provider::aws::kubernetes::{EKS, Options};
|
||||
use qovery_engine::cloud_provider::aws::kubernetes::node::Node;
|
||||
use qovery_engine::cloud_provider::aws::router::Router;
|
||||
use qovery_engine::cloud_provider::TerraformStateCredentials;
|
||||
use qovery_engine::container_registry::ecr::ECR;
|
||||
use qovery_engine::dns_provider::cloudflare::Cloudflare;
|
||||
use qovery_engine::engine::Engine;
|
||||
use qovery_engine::error::ConfigurationError;
|
||||
use qovery_engine::models::{
|
||||
Action, Application, Context, Environment, EnvironmentAction, GitCredentials, Kind,
|
||||
};
|
||||
use qovery_engine::session::Session;
|
||||
use qovery_engine::transaction::TransactionResult;
|
||||
|
||||
fn main() {
|
||||
let context = Context::new("unique-id", "/tmp/qovery-workspace", "lib", None, None);
|
||||
|
||||
// build image with Docker
|
||||
let local_docker = LocalDocker::new(context.clone(), "local-docker-id", "local-docker-name");
|
||||
|
||||
// use ECR as Container Registry
|
||||
let ecr = ECR::new(
|
||||
context.clone(),
|
||||
"ecr-id",
|
||||
"ecr-name",
|
||||
"YOUR AWS ACCESS KEY",
|
||||
"YOUR AWS SECRET ACCESS KEY",
|
||||
"us-east-1",
|
||||
);
|
||||
|
||||
// use cloudflare as DNS provider
|
||||
let cloudflare = Cloudflare::new(
|
||||
context.clone(),
|
||||
"cloudflare-id",
|
||||
"cloudflare-name",
|
||||
"tld.io",
|
||||
"YOUR CLOUDFLARE TOKEN",
|
||||
"YOUR CLOUDFLARE EMAIL",
|
||||
);
|
||||
|
||||
// use AWS
|
||||
let aws = AWS::new(
|
||||
context.clone(),
|
||||
"aws-id",
|
||||
"organization-id",
|
||||
"eks-name",
|
||||
"YOUR AWS ACCESS KEY",
|
||||
"YOUR AWS SECRET ACCESS KEY",
|
||||
TerraformStateCredentials::new(
|
||||
"YOUR AWS ACCESS KEY",
|
||||
"YOUR AWS SECRET ACCESS KEY",
|
||||
"us-east-1",
|
||||
),
|
||||
);
|
||||
|
||||
let nodes = vec![Node::new(2, 4), Node::new(2, 4), Node::new(2, 4)];
|
||||
|
||||
// use Kubernetes
|
||||
let eks = EKS::new(
|
||||
context.clone(),
|
||||
"eks-id",
|
||||
"eks-name",
|
||||
"1.16",
|
||||
"us-east-1",
|
||||
&aws,
|
||||
&cloudflare,
|
||||
Options::default(),
|
||||
nodes,
|
||||
);
|
||||
|
||||
let engine = Engine::new(
|
||||
context,
|
||||
Box::new(local_docker),
|
||||
Box::new(ecr),
|
||||
Box::new(aws),
|
||||
Box::new(cloudflare),
|
||||
);
|
||||
|
||||
let session = match engine.session() {
|
||||
Ok(session) => session,
|
||||
Err(config_error) => match config_error {
|
||||
ConfigurationError::BuildPlatform(_) => panic!("build platform config error"),
|
||||
ConfigurationError::ContainerRegistry(_) => panic!("container registry config error"),
|
||||
ConfigurationError::CloudProvider(_) => panic!("cloud provider config error"),
|
||||
ConfigurationError::DnsProvider(_) => panic!("dns provider config error"),
|
||||
},
|
||||
};
|
||||
|
||||
let mut tx = session.transaction();
|
||||
|
||||
let environment = Environment {
|
||||
execution_id: "unique-id".to_string(),
|
||||
id: "environment-id".to_string(),
|
||||
kind: Kind::Production,
|
||||
owner_id: "owner-id".to_string(),
|
||||
project_id: "project-id".to_string(),
|
||||
organization_id: "organization-id".to_string(),
|
||||
action: Action::Create,
|
||||
applications: vec![Application {
|
||||
id: "app-id-1".to_string(),
|
||||
name: "app-name-1".to_string(),
|
||||
action: Action::Create,
|
||||
git_url: "https://github.com/Qovery/node-simple-example.git".to_string(),
|
||||
git_credentials: GitCredentials {
|
||||
login: "github-login".to_string(),
|
||||
access_token: "github-access-token".to_string(),
|
||||
expired_at: Utc::now(),
|
||||
},
|
||||
branch: "main".to_string(),
|
||||
commit_id: "238f7f0454783defa4946613bc17ebbf4ccc514a".to_string(),
|
||||
dockerfile_path: "Dockerfile".to_string(),
|
||||
private_port: Some(3000),
|
||||
total_cpus: "256m".to_string(),
|
||||
cpu_burst: "500m".to_string(),
|
||||
total_ram_in_mib: 256,
|
||||
total_instances: 1,
|
||||
storage: vec![],
|
||||
environment_variables: vec![],
|
||||
}],
|
||||
routers: vec![],
|
||||
databases: vec![],
|
||||
external_services: vec![],
|
||||
clone_from_environment_id: None,
|
||||
};
|
||||
|
||||
tx.deploy_environment(&eks, &EnvironmentAction::Environment(environment));
|
||||
|
||||
match tx.commit() {
|
||||
TransactionResult::Ok => println!("infrastructure initialization OK"),
|
||||
TransactionResult::Rollback(commit_err) => {
|
||||
println!("infrastructure initialization ERROR and rollback OK")
|
||||
}
|
||||
TransactionResult::UnrecoverableError(commit_err, rollback_err) => {
|
||||
println!("infrastructure initialization ERROR and rollback FAILED")
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user