Skip to content

Commit

Permalink
Unified CLI (#37)
Browse files Browse the repository at this point in the history
Brings `node` commands under a unified `nex` command
  • Loading branch information
jordan-rash committed Jan 9, 2024
1 parent 2fd064b commit 3acab96
Show file tree
Hide file tree
Showing 22 changed files with 447 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
working-directory: ./nex-agent/cmd/nex-agent
run: go build -tags netgo -ldflags '-extldflags "-static"'
- name: Build nex-cli
working-directory: ./nex-cli/cmd/nex
working-directory: ./nex-cli
run: go build -tags netgo -ldflags '-extldflags "-static"'

- name: Test nex-agent
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@
# Go workspace file
go.work

.vscode
.vscode

# stash things locally
local/
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,42 @@ Turn your NATS infrastructure into a distributed workload deployment and executi
other than contributors.


To get up and running, follow the [Getting Started](./docs/getting_started.md) guide.
## Quickstart

`GOPRIVATE=github.com/ConnectEverything/nex go install github.com/ConnectEverything/nex/nex-cli@main`

The `nex node preflight` command is here to help you bootstrap your system.

First, we need to create a few directories it is expecting
```
mkdir -p /opt/cni/bin
mkdir -p /etc/cni/conf.d
mkdir -p /tmp/wd
```
You will also need to make sure that `/usr/local/bin` is in your path

Once those things are confirmed, use this configuration file

```json
{
"default_resource_dir":"/tmp/wd",
"machine_pool_size": 1,
"cni": {
"network_name": "fcnet",
"interface_name": "veth0"
},
"machine_template": {
"vcpu_count": 1,
"memsize_mib": 256
},
"tags": {
"simple": "true"
}
}
```

along with the below command

`sudo nex node preflight --config /tmp/wd`

There is a `--force` flag if you do not want to be prompted to install the missing dependencies
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tasks:
- go build -tags netgo -ldflags '-extldflags "-static"'

nex-cli:
dir: nex-cli/cmd/nex
dir: nex-cli
sources:
- "*.go"
cmds:
Expand All @@ -38,4 +38,4 @@ tasks:
- go build -tags netgo -ldflags '-extldflags "-static"'

build:
deps: [nex-agent, nex-node, nex-cli, echo-service]
deps: [nex-agent, nex-node, nex-cli, echo-service]
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/cdfmlr/ellipsis v0.0.1
github.com/choria-io/fisk v0.6.1
github.com/cloudevents/sdk-go v1.2.0
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.15.0
github.com/firecracker-microvm/firecracker-go-sdk v1.0.0
github.com/google/uuid v1.4.0
Expand All @@ -23,6 +22,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rs/xid v1.5.0
github.com/sirupsen/logrus v1.9.3
github.com/tetratelabs/wazero v1.6.0
rogchap.com/v8go v0.9.0
)

Expand All @@ -33,6 +33,7 @@ require (
github.com/containerd/fifo v1.0.0 // indirect
github.com/containernetworking/cni v1.0.1 // indirect
github.com/containernetworking/plugins v1.0.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/analysis v0.21.2 // indirect
github.com/go-openapi/errors v0.20.2 // indirect
Expand Down Expand Up @@ -64,7 +65,6 @@ require (
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/tetratelabs/wazero v1.6.0 // indirect
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5 // indirect
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
go.mongodb.org/mongo-driver v1.8.3 // indirect
Expand Down
142 changes: 142 additions & 0 deletions internal/models/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package models

import (
"net/url"
"time"
)

type UiOptions struct {
Port int
}

type DevRunOptions struct {
Filename string
// Stop a workload with the same name on a target
AutoStop bool
}

// Options configure the CLI
type Options struct {
Servers string
// Creds is nats credentials to authenticate with
Creds string
// TlsCert is the TLS Public Certificate
TlsCert string
// TlsKey is the TLS Private Key
TlsKey string
// TlsCA is the certificate authority to verify the connection with
TlsCA string
// Timeout is how long to wait for operations
Timeout time.Duration
// ConnectionName is the name to use for the underlying NATS connection
ConnectionName string
// Username is the username or token to connect with
Username string
// Password is the password to connect with
Password string
// Nkey is the file holding a nkey to connect with
Nkey string
// Trace enables verbose debug logging
Trace bool
// SocksProxy is a SOCKS5 proxy to use for NATS connections
SocksProxy string
// TlsFirst configures theTLSHandshakeFirst behavior in nats.go
TlsFirst bool
// Namespace for scoping workload requests
Namespace string
}

type RunOptions struct {
TargetNode string
WorkloadUrl *url.URL
Name string
WorkloadType string
Description string
PublisherXkeyFile string
ClaimsIssuerFile string
Env map[string]string
DevMode bool
TriggerSubjects []string
}

type StopOptions struct {
TargetNode string
WorkloadName string
WorkloadId string
ClaimsIssuerFile string
}

type WatchOptions struct {
NodeId string
WorkloadId string
WorkloadName string
LogLevel string
}

// Node configuration is used to configure the node process as well
// as the virtual machines it produces
type NodeOptions struct {
Config string `json:"-"`
ForceDepInstall bool `json:"-"`

KernelFile string `json:"kernel_file"`
RootFsFile string `json:"rootfs_file"`
DefaultDir string `json:"default_resource_dir"`
CNI CNIDefinition `json:"cni"`
InternalNodeHost *string `json:"internal_node_host,omitempty"`
InternalNodePort *int `json:"internal_node_port"`
KernelPath *string `json:"kernel_path"`
MachinePoolSize int `json:"machine_pool_size"`
MachineTemplate MachineTemplate `json:"machine_template"`
RateLimiters *Limiters `json:"rate_limiters,omitempty"`
RootFsPath *string `json:"rootfs_path"`
ValidIssuers []string `json:"valid_issuers,omitempty"`
WorkloadTypes []string `json:"workload_types,omitempty"`
Tags map[string]string `json:"tags,omitempty"`

Errors []error `json:"errors,omitempty"`
}

func (c *NodeOptions) Validate() bool {
c.Errors = make([]error, 0)

// TODO-- add validation

return len(c.Errors) == 0
}

// A set of rate limiters. These fields are identical to those in firecracker rate limiter configuration
type Limiters struct {
Bandwidth *TokenBucket `json:"bandwidth,omitempty"`
Operations *TokenBucket `json:"iops,omitempty"`
}

// Defines a reference to the CNI network name, which is defined and configured in a {network}.conflist file, as per
// CNI convention
type CNIDefinition struct {
NetworkName *string `json:"network_name"`
InterfaceName *string `json:"interface_name"`
}

// Defines the CPU and memory usage of a machine to be configured when it is added to the pool
type MachineTemplate struct {
VcpuCount *int `json:"vcpu_count"`
MemSizeMib *int `json:"memsize_mib"`
}

type TokenBucket struct {

// The initial size of a token bucket.
// Minimum: 0
OneTimeBurst *int64 `json:"one_time_burst,omitempty"`

// The amount of milliseconds it takes for the bucket to refill.
// Required: true
// Minimum: 0
RefillTime *int64 `json:"refill_time"`

// The total number of tokens this bucket can hold.
// Required: true
// Minimum: 0
Size *int64 `json:"size"`
}
2 changes: 1 addition & 1 deletion nex-cli/banner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nexcli
package main

// No CLI is truly complete without an ASCII art banner

Expand Down
83 changes: 0 additions & 83 deletions nex-cli/cli.go

This file was deleted.

1 change: 0 additions & 1 deletion nex-cli/cmd/nex/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion nex-cli/columns.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nexcli
package main

import (
"github.com/nats-io/natscli/columns"
Expand Down
2 changes: 1 addition & 1 deletion nex-cli/conn.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nexcli
package main

import (
"strings"
Expand Down
2 changes: 1 addition & 1 deletion nex-cli/devrunner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nexcli
package main

import (
"errors"
Expand Down
Binary file added nex-cli/nex-cli
Binary file not shown.
Loading

0 comments on commit 3acab96

Please sign in to comment.