Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multi instance support #178

Merged
merged 24 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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