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.20"
- 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. Deleting Services
You can delete services that are no longer needed as well.
use ServiceManager;
async
3. Reading Configuration Files
The Conf module allows you to read configuration files that define deployment settings.
use Conf;
4. Deploying an Existing Configuration
If you already have a configuration file, you can deploy it directly using the ServiceManager.
use ServiceManager;
async
5. 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.
6. Deploying a Web Service
Here’s an example of deploying a simple Node.js web service.
use Template;
use ;
async
7. Retrieving Owner Information
Finally, you can retrieve the owner ID of the current account with a simple API call.
use *;
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 that will be used to provision a managed Postgres instance and a managed Redis instance.
- The
[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.cidrBlocksdefines which IP ranges are allowed to access the database, using CIDR notation.
# Sample configuration file for provisioning
# managed Postgres and Redis instances.
[]
= "" # Replace with the desired database name
= "" # Replace with the desired user for the database
= false # Set to true to enable high availability
= "starter" # Pricing plan for the database instance
= "12" # Postgres version
= ""
# The following portion enables access control via CIDR blocks
= [
{ = "0.0.0.0/0", = "Public access from anywhere" },
# { cidrBlock = "192.168.1.0/24", description = "Office network" },
# Add more CIDR blocks here as needed
]
Note: Any blank fields (such as name and user) will be autogenerated if not provided.
- The
[redis]section specifies the configuration for a managed Redis instance:planspecifies the pricing plan for the instance.cidrBlockscontrols which IP ranges have access to the Redis instance, using CIDR notation.
[]
= "" # Replace with the desired Redis instance name
= "starter" # Pricing plan for the Redis instance
# CIDR blocks for access control to Redis
= [
{ = "0.0.0.0/0", = "Public access from anywhere" },
# { cidrBlock = "10.0.0.0/16", description = "Private network access" },
# Add more CIDR blocks here as needed
]
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: The free plan will result in failed deployments.
-
version: The version of Postgres to be used.
-
cidrBlocks: A list of CIDR blocks for controlling access to the database. This ensures that only allowed IP ranges can access the instance.
- cidrBlock: A string representing the range of allowed IPs in CIDR format (e.g.,
0.0.0.0/0for public access or192.168.1.0/24for a private network). - description: A human-readable description of the CIDR block's purpose.
- cidrBlock: A string representing the range of allowed IPs in CIDR format (e.g.,
-
-
[redis] Section:
-
name: The name of the Redis instance.
-
plan: The pricing plan for the Redis instance. Options may include "starter", "standard", "premium", etc.
Note: The free plan will result in failed deployments.
-
cidrBlocks: A list of CIDR blocks for controlling access to the Redis instance, similar to the database configuration.
-
This configuration file allows you to easily set up managed database and caching services with specific plans and access controls 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.