Skip to main content

Your First Deploy

Now that we have Hydro Deploy installed, let's deploy our first app. We'll start with a simple app that echoes packets.

First, we need to write the Hydroflow application, which will intergrate with Hydro Deploy to initialize connections to other services. We can create a project using the Cargo template:

# if you don't already have cargo-generate installed
cargo install --locked cargo-generate

cargo generate hydro-project/hydroflow-template

We'll need to add an additional dependency for hydroflow_cli_integration to our Cargo.toml:

# ...
hydroflow_cli_integration = "0.1.1"

Let's open up src/ in the generated project and write a new main function that initializes Hydro Deploy:

async fn main() {
let mut ports = hydroflow::util::cli::init().await;

This ports value gives us access to any network ports we define in our Hydro Deploy configuration. Let's create that next, in a file. A Hydro Deploy script consists of an asynchronous main function which can interactively create and destroy services. We start by creating a new deployment, which tracks the active resources and services:

import hydro

async def main(args):
deployment = hydro.Deployment()

Next, we pick out the host we want to run the service on (localhost for now), and create a pair of services on that host.

    host = deployment.Localhost()
echo_service_1 = deployment.HydroflowCrate(

echo_service_2 = deployment.HydroflowCrate(

Now, we need to wire up the ports. Hydro Deploy uses named ports, which can then be loaded in our Hydroflow logic. In our example, each echo service will have an "input" and "output" port. We can wire them up using the send_to method:


Returning briefly to our Hydroflow code, we can then load these ports and use them to send and receive packets:

use hydroflow_cli_integration::ConnectedDirect;
use hydroflow::hydroflow_syntax;

async fn main() {
let mut ports = hydroflow::util::cli::init().await;

let input_recv = ports
// connect to the port with a single recipient

let output_send = ports

hydroflow::util::cli::launch_flow(hydroflow_syntax! {
source_iter(["hello".to_string()]) -> dest_sink(output_send);
input = source_stream(input_recv) -> tee();
input -> dest_sink(output_send);
input -> for_each(|s| println!("{}", std::str::from_utf8(s).unwrap()));

Finally, we can return to to launch the application. First, deploy compiles the binaries, initializes hosts, and sets up the networking topology. Then, we use start to launch the services:

    await deployment.deploy()
await deployment.start()

To run the deployment, we can use the hydro deploy command:

hydro deploy

And if all goes well, we should see the packets being echoed back and forth between the two services!