|
| 1 | +# Installing the SDK |
| 2 | + |
| 3 | +## Installing packages |
| 4 | + |
| 5 | +To use FirecrackerSharp, you'll need the core package (`FirecrackerSharp`): |
| 6 | + |
| 7 | +```dotnet add package FirecrackerSharp``` |
| 8 | + |
| 9 | +And then, one of the hosts, the local host is installed as follows: |
| 10 | + |
| 11 | +```dotnet add package FirecrackerSharp.Host.Local``` |
| 12 | + |
| 13 | +And the SSH host is installed as follows: |
| 14 | + |
| 15 | +```dotnet add package FirecrackerSharp.Host.Ssh``` |
| 16 | + |
| 17 | +## Configuring the host |
| 18 | + |
| 19 | +For now, the hosts are configured via static classes (`LocalHost` or `SshHost`). An ASP.NET Core-specific extension that will use Microsoft's DI to do it is planned for the 1.0 release, but not available yet. |
| 20 | + |
| 21 | +### Local host |
| 22 | + |
| 23 | +Simply call: |
| 24 | + |
| 25 | +```cs |
| 26 | +LocalHost.Configure(); |
| 27 | +``` |
| 28 | + |
| 29 | +No extra configuration is needed, everything should "just work". |
| 30 | + |
| 31 | +### SSH host |
| 32 | + |
| 33 | +The SSH host needs three main configurations to work, the first is a connection pool configuration that will specify the settings of the SSH and SFTP connection pool and the credentials used to connect to the destination: |
| 34 | + |
| 35 | +```cs |
| 36 | +public sealed record ConnectionPoolConfiguration( |
| 37 | + ConnectionInfo ConnectionInfo, |
| 38 | + uint SshConnectionAmount, |
| 39 | + uint SftpConnectionAmount, |
| 40 | + TimeSpan KeepAliveInterval); |
| 41 | +``` |
| 42 | + |
| 43 | +The second configuration is used to create PTYs (virtual terminals) that are needed to launch and interact with the firecracker/jailer processes. There's a sensible default configuration at `ShellConfiguration.Default`: |
| 44 | + |
| 45 | +```cs |
| 46 | +public sealed record ShellConfiguration( |
| 47 | + string Terminal, |
| 48 | + uint Columns, |
| 49 | + uint Rows, |
| 50 | + uint Width, |
| 51 | + uint Height, |
| 52 | + int BufferSize) |
| 53 | +{ |
| 54 | + public static readonly ShellConfiguration Default = new( |
| 55 | + "/bin/bash", 1000, 1000, 1000, 1000, 1000); |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +The third configuration is used for the `curl` tool that is needed to make HTTP requests to Unix domain sockets of the Firecracker process. SSH.NET needs to support Unix socket forwarding for this not to be necessary, but the [related issue](https://github.com/sshnet/SSH.NET/issues/238) hasn't been resolved for more than 7 years, so `curl` is used over SSH instead. A sensible default configuration is available at `CurlConfiguration.Default`: |
| 60 | + |
| 61 | +```cs |
| 62 | +public sealed record CurlConfiguration( |
| 63 | + TimeSpan PollFrequency, |
| 64 | + int RetryAmount, |
| 65 | + int RetryDelaySeconds, |
| 66 | + int RetryMaxTimeSeconds) |
| 67 | +{ |
| 68 | + public static readonly CurlConfiguration Default = new(TimeSpan.FromMilliseconds(5), 1, 0, 20); |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +Lastly, **ensure the following packages are installed on the SSH Linux machine!**: |
| 73 | + |
| 74 | +- `tar` (working with archives) |
| 75 | +- `untar` or `unar` (same thing) |
| 76 | +- `curl` (requests) |
| 77 | + |
| 78 | +To set up the host, call `SshHost` like so: |
| 79 | + |
| 80 | +```cs |
| 81 | +SshHost.Configure(new ConnectionPoolConfiguration(...), new CurlConfiguration(...), new ShellConfiguration(...)); |
| 82 | +``` |
| 83 | + |
| 84 | +The connection pool keeps up the constant amount of SSH and SFTP connections through your app's lifetime. **Ensure the connection pool is disposed of like so:** |
| 85 | + |
| 86 | +```cs |
| 87 | +SshHost.Dispose(); |
| 88 | +``` |
0 commit comments