Skip to content

Commit bc8eff8

Browse files
committed
feat(local): complete deploy/undeploy cycle for local instance (#188)
Because - `local undeploy` is needed to tear down local instance This commit - add `local undeploy` - move state file from `~/.local/state` to `~/.local/instill/state`
1 parent b892cc5 commit bc8eff8

File tree

20 files changed

+671
-187
lines changed

20 files changed

+671
-187
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ clean:
2727
# just a convenience task around `go test`
2828
.PHONY: test
2929
test:
30-
go test -race ./...
31-
30+
@go test -v -race -coverpkg=./... -coverprofile=coverage.out ./...
31+
@go tool cover -func=coverage.out
32+
@go tool cover -html=coverage.out
33+
@rm coverage.out
3234
## Install/uninstall tasks are here for use on *nix platform. On Windows, there is no equivalent.
3335
DESTDIR :=
3436
prefix := /usr/local

cmd/instill/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func mainRun() exitCode {
168168
return exitOK
169169
}
170170
fmt.Fprintf(stderr, "\n\n%s %s → %s\n",
171-
ansi.Color("A new release of instill is available:", "yellow"),
171+
ansi.Color("A new release of Instill CLI is available:", "yellow"),
172172
ansi.Color(buildVersion, "cyan"),
173173
ansi.Color(newRelease.Version, "cyan"))
174174
if isHomebrew {
@@ -241,7 +241,7 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) {
241241
return update.CheckForUpdate(client, stateFilePath, repo, currentVersion)
242242
}
243243

244-
// BasicClient returns an API client for instill.tech only that borrows from but
244+
// basicClient returns an API client for instill.tech only that borrows from but
245245
// does not depend on user configuration
246246
func basicClient(currentVersion string) (*api.Client, error) {
247247
var opts []api.ClientOption

internal/config/config_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func StateDir() string {
6060
path = filepath.Join(b, "Instill CLI")
6161
} else {
6262
c, _ := os.UserHomeDir()
63-
path = filepath.Join(c, ".local", "state", "instill")
63+
path = filepath.Join(c, ".local", "instill", "state")
6464
}
6565

6666
// If the path does not exist try migrating state from default paths

internal/config/config_file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func Test_StateDir(t *testing.T) {
366366
"USERPROFILE": tempDir,
367367
"HOME": tempDir,
368368
},
369-
output: filepath.Join(tempDir, ".local", "state", "instill"),
369+
output: filepath.Join(tempDir, ".local", "instill", "state"),
370370
},
371371
{
372372
name: "XDG_STATE_HOME specified",
@@ -462,7 +462,7 @@ func Test_autoMigrateStateDir_migration(t *testing.T) {
462462
homeDir := t.TempDir()
463463
migrateDir := t.TempDir()
464464
homeConfigDir := filepath.Join(homeDir, ".config", "instill")
465-
migrateStateDir := filepath.Join(migrateDir, ".local", "state", "instill")
465+
migrateStateDir := filepath.Join(migrateDir, ".local", "instill")
466466

467467
homeEnvVar := "HOME"
468468
if runtime.GOOS == "windows" {

internal/config/from_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_HostsTyped(t *testing.T) {
2424
}
2525

2626
func Test_fileConfig_Typed(t *testing.T) {
27-
configDir := filepath.Join(t.TempDir(), ".config", "instill")
27+
configDir := filepath.Join(t.TempDir(), ".local", "instill")
2828
_ = os.MkdirAll(configDir, 0755)
2929
os.Setenv(INSTILL_CONFIG_DIR, configDir)
3030
defer os.Unsetenv(INSTILL_CONFIG_DIR)

internal/update/update.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010
"time"
1111

1212
"github.com/hashicorp/go-version"
13-
"github.com/instill-ai/cli/api"
1413
"gopkg.in/yaml.v3"
14+
15+
"github.com/instill-ai/cli/api"
1516
)
1617

1718
var gitDescribeSuffixRE = regexp.MustCompile(`\d+-\d+-g[a-f0-9]{8}$`)

pkg/cmd/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var logger *slog.Logger
5353

5454
func init() {
5555
var lvl = new(slog.LevelVar)
56-
if os.Getenv("INSTILL_DEBUG") != "" {
56+
if os.Getenv("DEBUG") != "" {
5757
lvl.Set(slog.LevelDebug)
5858
} else {
5959
lvl.Set(slog.LevelError + 1)

pkg/cmd/auth/login/login.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import (
1717
"github.com/instill-ai/cli/internal/instance"
1818
"github.com/instill-ai/cli/internal/oauth2"
1919
"github.com/instill-ai/cli/pkg/cmd/factory"
20-
instances "github.com/instill-ai/cli/pkg/cmd/local"
2120
"github.com/instill-ai/cli/pkg/cmdutil"
2221
"github.com/instill-ai/cli/pkg/iostreams"
2322
"github.com/instill-ai/cli/pkg/prompt"
23+
24+
"github.com/instill-ai/cli/pkg/cmd/local"
2425
)
2526

2627
type LoginOptions struct {
@@ -186,7 +187,7 @@ type localLoginRequest struct {
186187
func loginLocal(transport http.RoundTripper, hostname, password string) (string, error) {
187188
url := instance.GetProtocol(hostname) + "base/v1alpha/auth/login"
188189
data := &localLoginRequest{
189-
Name: instances.DefUsername,
190+
Name: local.DefUsername,
190191
Pass: password,
191192
}
192193
jsonData, err := json.Marshal(data)

pkg/cmd/instances/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ func NewRemoveCmd(f *cmdutil.Factory, runF func(*RemoveOptions) error) *cobra.Co
6060
return runF(opts)
6161
}
6262

63-
return runRemove(opts)
63+
return RunRemove(opts)
6464
},
6565
}
6666

6767
return cmd
6868
}
6969

70-
func runRemove(opts *RemoveOptions) error {
70+
func RunRemove(opts *RemoveOptions) error {
7171
hosts, err := opts.Config.HostsTyped()
7272
if err != nil {
7373
return err

pkg/cmd/instances/remove_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestInstancesRemoveCmdRun(t *testing.T) {
112112
tt.input.IO = io
113113

114114
t.Run(tt.name, func(t *testing.T) {
115-
err := runRemove(tt.input)
115+
err := RunRemove(tt.input)
116116
if tt.isErr {
117117
assert.Error(t, err)
118118
} else {

0 commit comments

Comments
 (0)