The agent that connects your environments, the Yolo CLI and your code editor

  • By Yolo
  • Last update: Dec 21, 2022
  • Comments: 0

Agent / Host

This repository contains the source code of the host agent.

The host agent is installed in the instance running your environment during its creation (most of the time via cloud-init but it may vary depending on the cloud provider used).

The main role of this agent is to enable communication between your environments, the CLI and your code editor.

It is composed of two components:

  • An SSH server.

  • A gRPC server.

Table of contents

Requirements

The host agent only works on nix-based OS and requires:

  • go >= 1.17

  • protoc >= 3.0 (see Protocol Buffer Compiler Installation)

  • google.golang.org/protobuf/cmd/protoc-gen-go@latest (install via go install)

  • google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest (install via go install)

Usage

The host agent could be run using the go run main.go command.

The gRPC server will listen on an Unix socket at /tmp/yolo-grpc.sock whereas the SSH server will listen on :2200 by default.

Generating the gRPC server's code

The gRPC server's code could be generated by running the following command in the proto directory:

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative agent.proto 

Host agent

The SSH server lets you access your environment via SSH without having to install and configure it.

The gRPC server, on the other hand, is used to enable communication with the CLI (via SSH, using the OpenSSH's Unix domain socket forwarding feature).

infra

SSH Server

The SSH server is the sole public-facing component. It will listen on port 2200 and redirect traffic to the gRPC server or to the environment depending on the requested channel type.

The authentication will be done using the Public Key authentication method. The key pair will be generated once, during the creation of the environment.

gRPC server

The gRPC server listens on an Unix socket and, as a result, is not public-facing. It will be accessed by the CLI via SSH, using the OpenSSH's Unix domain socket forwarding feature.

It is principally used to build your environment as you can see in the service definition:

service Agent {
  rpc InitInstance (InitInstanceRequest) returns (stream InitInstanceReply) {}
  rpc BuildAndStartEnv (BuildAndStartEnvRequest) returns (stream BuildAndStartEnvReply) {}
  rpc InitEnv (InitEnvRequest) returns (stream InitEnvReply) {}
}

message InitInstanceRequest {}

message InitInstanceReply {
  string log_line_header = 1;
  string log_line = 2;
}

message BuildAndStartEnvRequest {
  string env_name_slug = 1;
  string env_repo_owner = 2;
  string env_repo_name = 3;
  repeated string env_repo_languages_used = 4;
}

message BuildAndStartEnvReply {
  string log_line_header = 1;
  string log_line = 2;
}

message InitEnvRequest {
  string env_repo_owner = 1;
  string env_repo_name = 2;
  repeated string env_repo_languages_used = 3;
  string github_user_email = 4;
  string user_full_name = 5;
}

message InitEnvReply {
  string log_line_header = 1;
  string log_line = 2;
  optional string github_ssh_public_key_content = 3;
  optional string github_gpg_public_key_content = 4;
}

The InitInstance method will run a shell script that will, among other things, install Docker and Sysbox.

The BuildAndStartEnv method will pull the ghcr.io/yolo-sh/workspace-full image and build the environment container.

The InitEnv method will call the Init method of the container agent's gRPC service.

These methods are idempotent.

License

Yolo is available as open source under the terms of the MIT License.

Download

agent.zip