Installation #

Add render_cdk to your Cargo.toml:

[dependencies]
render_cdk = "0.0.21"

Alternatively, running cargo add render_cdk at the root of your project will also add render_cdk to your project.

Cpp Reference #

Usage #

Configuration

Add render_cdk to your Cargo.toml:


API_KEY=rnd_xxxxXXXXxxxxXXXXxxxXX
OWNER_CREDENTIALS=owner@email.com

Alternatively, running cargo add render_cdk at the root of your project will also add render_cdk to your project. Make sure to replace rnd_xxxxXXXXxxxxXXXXxxxXX with your actual Render API key.

Examples

Here are basic examples of how to use the render_cdk crate to interact with Render Cloud:

1. Creating and Deploying Services

Create a Service auto deployed

    
use render_cdk::deployment::Template;
use render_cdk::service_management::{ServiceDetails, ServiceManager};

#[tokio::main]
async fn main() {
    let deployment_config = Template {
        type_: "static_site".to_owned(),
        name: "test_deployment".to_owned(),
        repo: "https://github.com/<username>/<repo_url>".to_owned(),
        auto_deploy: "yes".to_owned(),
        root_dir: Some("./public".to_owned()),
        service_details: Some(ServiceDetails {
            publish_path: Some("./".to_owned()),
            pull_request_previews_enabled: Some("yes".to_owned()),
            ..Default::default()
        }),
        ..Default::default()
    };

    // Deploy a static site.
    ServiceManager::create_service(deployment_config).await.unwrap();

    let deployment_config = Template {
        type_: "web_service".to_owned(),
        name: "test_deployment".to_owned(),
        repo: "https://github.com/<username>/<repo_url>".to_owned(),
        auto_deploy: "yes".to_owned(),
        root_dir: Some("./".to_owned()),
        service_details: Some(ServiceDetails {
            region: "oregon".to_owned(),
            plan: "starter".to_owned(),
            runtime: "node".to_owned(),
            num_instances: 1,
            env_specific_details: Some(EnvSpecificDetails {
                build_command: Some("yarn".to_owned()),
                start_command: Some("npm start".to_owned()),
            }),
            pull_request_previews_enabled: Some("yes".to_owned()),
            ..Default::default()
        }),
        ..Default::default()
    };

    // Deploy a web service.
    ServiceManager::create_web_service(deployment_config).await.unwrap();
}
    
    

The example above demonstrates how to deploy a simple static site on Render Cloud.

Note - Only authorized users can create and deploy services.

2. Querying for Deployed Services

List All Services with LIMIT options

    
    use render_cdk::environment_management::prelude::*;
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::list_all_services("10").await;
        // Process the services as needed.
    }
    
    

List All Services by Name and Type with LIMIT options

    
    use render_cdk::environment_management::prelude::*;
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::find_service_by_name_and_type("my_api", "web_service").await;
        // Process the services as needed.
    }
    
    

List All Services by Region with LIMIT options

    
    use render_cdk::environment_management::prelude::*;
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::find_service_by_region("oregon", "10").await;
        // Process the services as needed.
    }
    
    

List All Services by Environment with LIMIT options

    
    use render_cdk::environment_management::prelude::*;
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::find_service_by_environment("image", "10").await;
        // Process the services as needed.
    }
    
    

Delete Services by Name and Type

    
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::delete_service("test_static", "static").await;
        ServiceManager::delete_service("test_web", "web_service").await;
        // Confirm deletion or handle errors as needed.
    }
    
    

Delete PostgreSQL and Redis Instances by Name

    
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::delete_postgres_instance("gearednimbus").await;
        ServiceManager::delete_redis_instance("cyberplasma").await;
        // Confirm deletion or handle errors as needed.
    }
    
    

Query PostgreSQL Instances with Various Options

    
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::list_postgres_instances(true, "50").await;
        ServiceManager::find_postgres_instance_by_name("fluentcomet", true, "50").await;
        ServiceManager::find_postgres_instance_with_status("suspended", true, "50").await;
        // Process the queried instances as needed.
    }
    
    

Query Redis Instances by Name and Options

    
    use render_cdk::resource_management::prelude::*;
    use tokio::main;
    
    #[main]
    async fn main() {
        ServiceManager::find_redis_instance_by_name("cyberplasma", "50").await;
        // Process the queried instances as needed.
    }
    
    

Contribution #

Contributions are welcome! Please see the repository for more information on how to contribute.