Technical Documentation
Configuration
To configure the environment variables for use with render_cdk, you need to set the API_KEY and OWNER_CREDENTIALS environment variables. You can do this by creating a .env file in the root of your project with the following content:
API_KEY=rnd_xxxxXXXXxxxxXXXXxxxXX
OWNER_CREDENTIALS=<render>@<email>.com
Make sure to replace rnd_xxxxXXXXxxxxXXXXxxxXX with your actual Render API key.
Installation
Add render_cdk to your Cargo.toml:
[]
= "0.0.16"
- Alternatively, running at the
cargo add render_cdkroot of your project will also add render_cdk to your project.
Usage Examples
Here are basic examples of how to use the render_cdk crate to interact with Render Cloud:
1. Querying for Deployed Services
You can easily retrieve information about your deployed services using the ServiceManager module. Below are examples of how to query services based on various criteria.
use *;
use *;
use main;
async
2. Retrieving Owner Information
You can retrieve the owner ID of the current account with a simple API call.
use *;
async
3. Reading Configuration Files
The Conf module allows you to read configuration files that define deployment settings.
use Conf;
4. Deploying a Static Site
The following example demonstrates how to deploy a simple static site using a configuration template.
use Template;
use ;
async
Description of Fields:
- build_command: The command Render runs to build your app before each deploy, e.g.,
npm run buildoryarn build. - publish_path: The directory path where the static site will be published, e.g.,
/public/. - pull_request_previews_enabled: Indicates whether pull request previews are enabled for this deployment.
5. Deploying a Web Service
Here’s an example of deploying a simple Node.js web service.
use Template;
use ;
async
6. Deploying an Existing Configuration
If you already have a configuration file, you can deploy it directly using the ServiceManager.
use ServiceManager;
async
7. Deleting Services
Finally, you can delete services that are no longer needed.
use ServiceManager;
async
8. Using Simple .conf Files for Resource Provisioning
.conffiles offer a convenient alternative to programmatic resource provisioning, allowing you to define and manage resources through simple configuration settings.
Configuration File Example
The following is a sample configuration_ file. This will be used to provision a managed Postgres instance and a managed Redis instance.
-
[database]section specifies the configuration for a managed Postgres instance. -
The
nameanduserfields should be filled with the desired database name and user.enable_high_availabilityindicates whether high availability should be enabled.planspecifies the pricing plan for the instance, andversionindicates the Postgres version.
# The following is a sample configuration file.
# This will be used to provision a
# managed postgres instance and managed redis instance.
[]
= "" # Replace with the desired database name
= "" # Set to true to enable high availability
= false # Pricing plan for the database instance
= "starter"
= "12" # Postgres version
= ""
# The following portion enables <public> access.
= [
{ = "0.0.0.0/0", = "Everywhere" }
# { cidrBlock = "0.0.0.0/0", description = "Everywhere" },
# { cidrBlock = "0.0.0.0/0", description = "Everywhere" }
# Add more CIDR blocks here...
]
Note Blank fields will be autogenerated.
[redis]section specifies the configuration for a managed Redis instance.planspecifies the pricing plan for the instance.
[]
= ""
= "starter" # Pricing plan for the Redis instance`
Explanation
-
[database] Section:
-
name: The name of the Postgres database.
-
user: The user for the Postgres database.
-
enable_high_availability: Boolean value to enable or disable high availability for the database.
-
plan: The pricing plan for the Postgres instance. Options may include "starter", "standard", "premium", etc.
Note free plan will result in failed deployments.
-
version: The version of Postgres to be used.
-
-
[redis] Section:
-
name: The name of the Redis instance.
-
plan: The pricing plan for the Redis instance. Options may include "free", "standard", "premium", etc.
Note free plan will result in failed deployments.
-
This configuration file allows you to easily set up managed database and caching services with specific plans and options suited to your project's needs.
use Conf;
This documentation should help guide you through the basic usage of the render_cdk crate for managing your services on Render Cloud.