Skip to main content
Skip to main content
🚧 Work in Progress

Create a Rust service in Zerops

Zerops provides a Rust runtime service with extensive build support. Rust runtime is highly scalable and customisable to suit both development and production.

Create Rust service using Zerops GUI​

First, set up a project in Zerops GUI. Then go to the project dashboard page and choose Add new service in the left menu in the Services block. Then add a new Rust service:

// TODO screenshot (add a new service page)

Choose Rust version​

Following Rust major versions are currently supported:

  • 1.78
  • 1.80
  • nightly
Info

You can change the major version at any time later.

Set a hostname​

Enter a unique service identifier like "app","cache", "gui" etc. Duplicate services with the same name in the same project are forbidden.

Limitations:​

  • maximum 25 characters
  • must contain only lowercase ASCII letters (a-z) or numbers (0-9)
Caution

The hostname is fixed after the service is created. It can't be changed later.

Set secret environment variables​

Add environment variables with sensitive data, such as password, tokens, salts, certificates etc. These will be securely saved inside Zerops and added to your runtime service upon start.

Setting the secret environment variables is optional. You can set them later in Zerops GUI.

Read more about different types of env variables in Zerops.

Set auto scaling configuration​

Zerops scales the Rust services automatically both vertically and horizontally. Vertical scaling means increasing or decreasing the hardware resources (CPU, RAM and disk) of a Rust container. Horizontal scaling adds or removes whole containers.

Automatic Scaling

CPU Mode​

Shared Your application gets a full physical CPU core, but it is shared with up to 10 other applications. In this mode the power your application gets is depended on other applications running on the same CPU core. At best case scenario your application gets 10/10 of CPU core power and 1/10 at worst case scenario.

Dedicated The CPU core is dedicated to your application.

Info

See the pricing for the difference between CPU modes.

Choose the CPU mode when starting a new service or change it later. The CPU mode doesn't change automatically.

Vertical auto scaling​

Vertical auto scaling has following default configuration:

Resources TypeMinimum resourceMaximum resource
CPU cores15
RAM0.25 GB32 GB
Disk1 GB100 GB

Rust service always starts with the minimal resources.

For most cases, the default parameters will work without issues. If you need to limit the cost of the Rust service, lower the maximal resources. Zerops will never scale above the selected maximums.

When you are experiencing problems with insufficient Rust performance or capacity, increase the minimal resources. Zerops will never scale below the selected minimums.

Tip

Learn more about how to fine tune the auto scaling to fit your application needs.

Info

You can change the vertical auto scaling parameters later.

Horizontal auto scaling​

When a container needs more CPU or RAM but already consumes maximal resources defined for the vertical auto scaling, Zerops will add a new container to your Rust service. When your Rust service doesn't need so much power and all containers are vertically scaled down in such a way their CPU allocation is near the minimal resources, Zerops will gradually remove whole containers.

Horizontal auto scaling has following default configuration:

ParameterValue
minimum containers1
maximum containers6

Rust service always starts with the minimum number of containers.

You can increase the minimum or decrease the maximum number of containers. The horizontal scaling parameters can be changed later.

Learn more about Rust auto scaling.

Single container vs. High Availability​

When creating a new runtime service, you can choose the minimum and maximum number of containers. If you set the maximum limit to one, the service will be run in a single container and no horizontal scaling will occur.

Caution

If the single container fails, Zerops will start a new container and deploy your application automatically. The application won't be available for a short period. This mode is recommended for non-critical applications or dev environments.

By increasing the maximum number of containers for your service, you enable horizontal auto scaling. Zerops will then add containers depending on your application’s load. Application running on two or more containers is in High Availability mode, which we highly recommend for production. When the load drops, containers will be gradually removed to the defined minimum.

Each container of the same service is strictly installed on a different server. This prevents the temporary outage in case any of Zerops servers fail. If the connection to a container is broken, Zerops immediately redirects incoming traffic to other containers. A new container will be started automatically and the broken container will be deleted.

Caution

Check if your application is ready to be run in multiple containers.

Create Rust service using zCLI​

zCLI is the Zerops command-line tool. To create a new Rust service via the command-line, follow these steps:

  1. Install & setup zCLI
  2. Create a project description file
  3. Create a project with a Rust and PostgreSQL service

Create a project description file​

Zerops uses a yaml format to describe the project infrastructure.

Basic example:​

Create a directory my-project. Create an description.yml file inside the my-project directory with following content:

# basic project data
project:
# project name
name: my-project
# array of project services
services:
- # service name
hostname: app
# service type and version number in rust@{version} format
type: rust@latest
# defines the minimum number of containers for horizontal autoscaling
minContainers: 1
# defines the maximum number of containers for horizontal autoscaling. Max value = 6.
maxContainers: 6
# optional: create env variables
envSecrets:
S3_ACCESS_KEY_ID: 'P8cX1vVVb'
S3_ACCESS_SECRET: 'ogFthuiLYki8XoL73opSCQ'

The yaml file describes your future project infrastructure. The project will contain one Rust version 18 service with default auto scaling configuration. Hostname will be set to "app", the internal port(s) the service listens on will be defined later in the zerops.yml. Following secret env variables will be configured:

S3_ACCESS_KEY_ID="P8cX1vVVb"
S3_ACCESS_SECRET="ogFthuiLYki8XoL73opSCQ"

Full example:​

Create a directory my-project. Create an description.yml file inside the my-project directory with following content:

# basic project data
project:
# project name
name: my-project
# optional: project description
description: A project with a Rust and PostgreSQL database
# optional: project tags
tags:
- DEMO
- ZEROPS
# array of project services
services:
- # service name
hostname: app
# service type and version number in rust@{version} format
type: rust@latest
# optional: vertical auto scaling customization
verticalAutoscaling:
cpuMode: DEDICATED
minCpu: 2
maxCpu: 5
minRam: 2
maxRam: 24
minDisk: 6
maxDisk: 50
startCpuCoreCount: 3
minFreeRamGB: 0.5
minFreeRamPercent: 20
# defines the minimum number of containers for horizontal autoscaling. Max value = 6.
minContainers: 2
# defines the maximum number of containers for horizontal autoscaling. Max value = 6.
maxContainers: 4
# optional: create secret env variables
envSecrets:
S3_ACCESS_KEY_ID: 'P8cX1vVVb'
S3_ACCESS_SECRET: 'ogFthuiLYki8XoL73opSCQ'
- # second service hostname
hostname: db
# service type and version number in postgresql@{version} format
type: postgresql@12
# mode of operation "HA"/"non_HA"
mode: NON_HA

The yaml file describes your future project infrastructure. The project will contain a Rust service and a PostgreSQL service.

Rust service with "app" hostname, the internal port(s) the service listens on will be defined later in the zerops.yml. Rust service will run on version 18 with a custom vertical and horizontal scaling. Following secret env variables will be configured:

S3_ACCESS_KEY_ID="P8cX1vVVb"
S3_ACCESS_SECRET="ogFthuiLYki8XoL73opSCQ"

The hostname of the PostgreSQL service will be set to "db". The single container mode will be chosen and the default auto scaling configuration will be set.

Description of description.yml parameters​

The project: section is required. Only one project can be defined.

ParameterDescriptionLimitations
nameThe name of the new project. Duplicates are allowed.
descriptionOptional. Description of the new project.Maximum 255 characters.
tagsOptional. One or more string tags. Tags do not have a functional meaning, they only provide better orientation in projects.

At least one service in services: section is required. You can create a project with multiple services. The example above contains Rust and PostgreSQL services but you can create a description.yml with your own combination of services.

ParameterDescription
hostname

The unique service identifier.

  • duplicate services with the same name in the same project are forbidden
  • maximum 25 characters
  • must contain only lowercase ASCII letters (a-z) or numbers (0-9)
type

Specifies the service type and version.


See what Rust service types are currently supported.

verticalAutoscaling

Optional. Defines custom vertical auto scaling parameters.
All verticalAutoscaling attributes are optional. Not specified attributes will be set to their default values.

- cpuMode

Optional. Accepts SHARED, DEDICATED values. Default is SHARED

- minCpu/maxCpu

Optional. Set the minCpu or maxCpu in CPU cores (integer).

- minRam/maxRam

Optional. Set the minRam or maxRam in GB (float).

- minDisk/maxDisk

Optional. Set the minDisk or maxDisk in GB (float).

minContainers

Optional. Default = 1. Defines the minimum number of containers for horizontal autoscaling.


Limitations:

Current maximum value = 6.

maxContainers

Defines the maximum number of containers for horizontal autoscaling.


Limitations:

Current maximum value = 6.

envSecrets

Optional. Defines one or more secret env variables as a key value map. See env variable restrictions.

Create a project based on the description.yml​

When you have your description.yml ready, use the zcli project project-import command to create a new project and the service infrastructure.

Usage:
zcli project project-import importYamlPath [flags]

Flags:
-h, --help the project import command.
--orgId string If you have access to more than one organization, you must specify the org ID for which the
project is to be created.
--workingDie string Sets a custom working directory. Default working directory is the current directory. (default "./")

Zerops will create a project and one or more services based on the description.yml content.

Maximum size of the description.yml file is 100 kB.

You don't specify the project name in the zcli project project-import command, because the project name is defined in the description.yml.

If you have access to more than one client, you must specify the client ID for which the project is to be created. The clientID is located in the Zerops GUI under the client name on the project dashboard page.

image

Add Rust service to an existing project​

Example:​

Create a directory my-project if it doesn't exist. Create an import.yml file inside the my-project directory with following content:

# basic project data
project:
# project name
name: my-project
# array of project services
services:
- # service name
hostname: app
# service type and version number in rust@{version} format
type: rust@latest
# defines the minimum number of containers for horizontal autoscaling
minContainers: 1
# defines the maximum number of containers for horizontal autoscaling. Max value = 6.
maxContainers: 6
# optional: create env variables
envSecrets:
S3_ACCESS_KEY_ID: 'P8cX1vVVb'
S3_ACCESS_SECRET: 'ogFthuiLYki8XoL73opSCQ'

The yaml file describes the list of one or more services that you want to add to your existing project. In the example above, one Rust service version 18 with default auto scaling configuration will be added to your project. Hostname of the new service will be set to app. Following secret env variables will be configured:

S3_ACCESS_KEY_ID="P8cX1vVVb"
S3_ACCESS_SECRET="ogFthuiLYki8XoL73opSCQ"

The content of the services: section of import.yml is identical to the project description file. The import.yml never contains the project: section because the project already exists.

When you have your import.yml ready, use the zcli project service-import command to add one or more services to your existing Zerops project.

Usage:
zcli project service-import importYamlPath [flags]

Flags:
-h, --help the project service import command.
--projectId string If you have access to more than one project, you must specify the project ID for which the
command is to be executed.

zCLI commands are interactive, when you press enter after zcli project service-import importYamlPath, you will be given a list of your projects to choose from.

Maximum size of the import.yml file is 100 kB.