Skip to content

Commit

Permalink
feat: support multi instances (#178)
Browse files Browse the repository at this point in the history
Because

- user can have more than 1 instance of Instill AI

This commit

- adds instance management and switching

- instances management
  - `add`, `edit`, `list`, `remove`, `set-default`
- markdown tables
- tests
- typed config (for hosts)
- default config when empty
- hostname validation
- breaking dependabot updates
- readme

---------

Signed-off-by: Tobias Cudnik <[email protected]>
  • Loading branch information
Tobias Cudnik authored and TobiaszCudnik committed Sep 27, 2023
1 parent 9bb57d6 commit b43100b
Show file tree
Hide file tree
Showing 50 changed files with 2,231 additions and 1,993 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ vendor/
# air configuration file: https://github.com/cosmtrek/air
.air.toml
dist/

/*.env
/coverage.txt
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ script/build: script/build.go
GOOS= GOARCH= GOARM= GOFLAGS= CGO_ENABLED= go build -o $@ $<

.PHONY: clean
clean: script/build
@script/build $@
clean:
rm -f script/build
rm -f bin/instill

# just a convenience task around `go test`
.PHONY: test
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="https://www.instill.tech/?utm_source=github&utm_medium=banner&utm_campaign=cli_readme">Website</a> |
<a href="https://discord.gg/sevxWsqpGh">Community</a> |
<a href="https://blog.instill.tech/?utm_source=github&utm_medium=banner&utm_campaign=cli_readme">Blog</a><br/><br/>
<a href="https://docs.instill.tech/?utm_source=github&utm_medium=banner&utm_campaign=cli_readme">User Manual</a> |
<a href="https://www.instill.tech/docs/?utm_source=github&utm_medium=banner&utm_campaign=cli_readme">User Manual</a> |
<a href="https://discord.gg/sevxWsqpGh">API Reference</a><br/><br/>
<a href="https://www.instill.tech/get-access/?utm_source=github&utm_medium=banner&utm_campaign=cli_readme"><strong>Get Early Access</strong></a>
</h4>
Expand Down Expand Up @@ -49,6 +49,45 @@ To upgrade:
brew upgrade instill-ai/tap/instill
```

## Usage examples

```bash
# log in
$ instill auth login

# list pipelines
$ instill api pipelines

# list models
$ instill api models

# add parameters to a GET request
$ instill api models?visibility=public

# list instances
$ instill instances list

# selected a default instance
$ instill instances set-default my-host.com

# add an instance
$ instill instances add instill.localhost \
--oauth2 auth.instill.tech \
--audience https://instill.tech \
--issuer https://auth.instill.tech/ \
--secret YOUR_SECRET \
--client-id CLIENT_ID

# add parameters to a POST request
$ instill api -X POST oauth2/token?audience=...&grant_type=...

# add nested JSON body to a POST request
$ jq -n '{"contents":[{"url": "https://artifacts.instill.tech/dog.jpg"}]}' | instill api demo/tasks/classification/outputs --input -

# set a custom HTTP header
$ instill api -H 'Authorization: Basic mytoken' ...
```

## Issues and discussions
Please directly report any issues in [Issues](https://github.com/instill-ai/cli/issues) or [Pull requests](https://github.com/instill-ai/cli/pulls), or raise a topic in [Discussions](https://github.com/instill-ai/cli/discussions).

Expand Down
25 changes: 17 additions & 8 deletions cmd/instill/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"log"
"net"
"os"
"os/exec"
Expand All @@ -15,15 +14,15 @@ import (
surveyCore "github.com/AlecAivazis/survey/v2/core"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/cli/safeexec"
"github.com/mattn/go-colorable"

"github.com/dotenv-org/godotenvvault"
"github.com/mattn/go-colorable"
"github.com/mgutz/ansi"
"github.com/spf13/cobra"

"github.com/instill-ai/cli/api"
"github.com/instill-ai/cli/internal/build"
"github.com/instill-ai/cli/internal/config"
"github.com/instill-ai/cli/internal/oauth2"
"github.com/instill-ai/cli/internal/update"
"github.com/instill-ai/cli/pkg/cmd/factory"
"github.com/instill-ai/cli/pkg/cmd/root"
Expand All @@ -48,12 +47,9 @@ func main() {
}

func mainRun() exitCode {
// load .env in dev mode
// optionally load .env in dev mode
if build.Version == "" {
err := godotenvvault.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
_ = godotenvvault.Load()
}

buildDate := build.Date
Expand Down Expand Up @@ -119,6 +115,19 @@ func mainRun() exitCode {

authError := errors.New("authError")
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
// in case there's no hosts.yml config, create one with the default instance
f, err := os.Stat(config.HostsConfigFile())
exists := err == nil && !f.IsDir()
if !exists {
// get the (hardcoded) default cloud instance
host := oauth2.HostConfigInstillCloud()
err = cfg.SaveTyped(host)
if err != nil {
return err
}
fmt.Fprintln(stderr, cs.Bold("No host.yml config, creating a default one..."))
fmt.Fprintln(stderr, config.HostsConfigFile())
}
// require that the user is authenticated before running most commands
if cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
fmt.Fprintln(stderr, cs.Bold("Welcome to Instill CLI!"))
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "internal/config/stub.go"
99 changes: 63 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,101 @@ module github.com/instill-ai/cli
go 1.20

require (
github.com/AlecAivazis/survey/v2 v2.3.2
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc v1.0.0
github.com/briandowns/spinner v1.18.1
github.com/charmbracelet/glamour v0.3.0
github.com/charmbracelet/glamour v0.6.1-0.20230822193950-b8953ce4af51
github.com/cli/browser v1.1.0
github.com/cli/safeexec v1.0.1
github.com/coreos/go-oidc/v3 v3.6.0
github.com/creack/pty v1.1.18
github.com/dotenv-org/godotenvvault v0.6.0
github.com/go-playground/validator/v10 v10.4.1
github.com/google/go-cmp v0.5.9
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/go-version v1.3.0
github.com/henvic/httpretty v0.0.6
github.com/itchyny/gojq v0.12.13
github.com/itchyny/gojq v0.12.7
github.com/julienschmidt/httprouter v1.3.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.19
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/muesli/reflow v0.2.1-0.20210502190812-c80126ec2ad5
github.com/muesli/termenv v0.9.0
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.2
github.com/olekukonko/tablewriter v0.0.5
github.com/ory/graceful v0.1.3
github.com/ory/x v0.0.364
github.com/spf13/cobra v1.4.0
github.com/ory/x v0.0.589
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.5
golang.org/x/oauth2 v0.6.0
golang.org/x/sys v0.8.0
golang.org/x/term v0.6.0
github.com/stretchr/testify v1.8.4
golang.org/x/oauth2 v0.7.0
golang.org/x/sys v0.12.0
golang.org/x/term v0.12.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/alecthomas/chroma v0.8.2 // indirect
github.com/alecthomas/chroma/v2 v2.9.1 // indirect
github.com/avast/retry-go/v4 v4.3.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-logr/logr v1.2.1 // indirect
github.com/go-logr/stdr v1.2.0 // indirect
github.com/gobuffalo/pop/v6 v6.0.1 // indirect
github.com/goccy/go-yaml v1.9.5 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/gobuffalo/pop/v6 v6.0.8 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-yaml v1.9.6 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/timefmt-go v0.1.3 // indirect
github.com/jandelgado/gcov2lcov v1.0.6 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/microcosm-cc/bluemonday v1.0.16 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/seatgeek/logrus-gelf-formatter v0.0.0-20210414080842-5b05eb8ff761 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/yuin/goldmark v1.4.0 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.25.0 // indirect
go.opentelemetry.io/otel v1.3.0 // indirect
go.opentelemetry.io/otel/trace v1.3.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/gjson v1.14.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/yuin/goldmark v1.5.6 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.36.4 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/metric v0.33.0 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
Loading

0 comments on commit b43100b

Please sign in to comment.