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

Save racks installed locally through the CLI #3631

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions ci/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ curl -Ls https://amazon-eks.s3-us-west-2.amazonaws.com/1.12.7/2019-03-27/bin/lin
# download appropriate cli version
curl -o ${GOPATH}/bin/convox https://convox.s3.amazonaws.com/release/${VERSION}/cli/linux/convox
chmod +x ${GOPATH}/bin/convox

# set [email protected] as id
mkdir -p ~/.convox/
echo [email protected] > ~/.convox/id
4 changes: 4 additions & 0 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ else
fi

convox instances

# set [email protected] as id
# convox config dir path
echo [email protected] > ~/.config/convox2/id
3 changes: 3 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ root="$(cd $(dirname ${0:-})/..; pwd)"
set -ex

provider=$(convox api get /system | jq -r .provider)
source $(dirname $0)/env.sh

# cli
convox version
Expand All @@ -33,6 +34,8 @@ sleep 15
convox rack logs --no-follow | grep service/
convox rack ps | grep rack

convox racks | grep ${RACK_NAME}

# rack (provider-specific)
case $provider in
aws)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/convox/exec v0.0.0-20180905012044-cc13d277f897
github.com/convox/logger v0.0.0-20180522214415-e39179955b52
github.com/convox/stdapi v1.1.3-0.20221110171947-8d98f61e61ed
github.com/convox/stdcli v0.0.0-20221110070640-8f8fb17bfe20
github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51
github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377
github.com/convox/version v0.0.0-20160822184233-ffefa0d565d2
github.com/docker/docker v1.13.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ github.com/convox/logger v0.0.0-20180522214415-e39179955b52 h1:HTaloo6by+4NE1A1m
github.com/convox/logger v0.0.0-20180522214415-e39179955b52/go.mod h1:IcbSD+Pq+bQV2z/otiMCHLAYBrDR/jPFopFatrWjlMM=
github.com/convox/stdapi v1.1.3-0.20221110171947-8d98f61e61ed h1:lsw6qfOktQBaF0FEb32+ogvB1S/H3m1W341TuOQ5jnc=
github.com/convox/stdapi v1.1.3-0.20221110171947-8d98f61e61ed/go.mod h1:7hoZ3oU4j6Zv3V1wRpgUO5eWc+480zYTpYxuTKAbugc=
github.com/convox/stdcli v0.0.0-20221110070640-8f8fb17bfe20 h1:9t+oXf7ycnO1Cz9AnIEqPLdvbE0b0Yf9Pe5NOukvRN0=
github.com/convox/stdcli v0.0.0-20221110070640-8f8fb17bfe20/go.mod h1:kLknwv4KTN9f9fZ2DDvG/L9ndXkcijaexIZ0enACvSc=
github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51 h1:03Yia3LZwsHUovVEPFDGUrTAUg9N844Wvv9PiFQuR0Y=
github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51/go.mod h1:kLknwv4KTN9f9fZ2DDvG/L9ndXkcijaexIZ0enACvSc=
github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377 h1:PuSJ72MD0mYsMCTvTQ1YydIbQUWtEykNHyweI/vA0PY=
github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377/go.mod h1:y1vtmkDKBkWSQ6e2gPXAyz1NCuWZ2x3vrP/SFeDDNco=
github.com/convox/version v0.0.0-20160822184233-ffefa0d565d2 h1:tdp/1KHBnbne0yT1yuKnAdOTBHRue9yQ4oON8rzGgZc=
Expand Down
65 changes: 65 additions & 0 deletions pkg/cli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,68 @@ func localRacks(c *stdcli.Context) ([]rack, error) {
return racks, nil
}

func selfManagedRacks(c *stdcli.Context) ([]rack, error) {
racks := []rack{}

data, err := c.SettingRead("self-managed")
if err != nil {
return nil, err
}
var rs map[string]string

if err := json.Unmarshal([]byte(data), &rs); err != nil {
return nil, err
}

for name, host := range rs {
status := selfManagedStatus(c, host)

racks = append(racks, rack{
Name: name,
Status: status,
})
}

return racks, nil
}

func selfManagedStatus(c *stdcli.Context, host string) string {
status := "unknown"

auth, err := c.SettingReadKey("auth", host)
if err != nil {
return status
}

sc, err := sdk.New(fmt.Sprintf("https://convox:%s@%s", auth, host))
if err != nil {
return status
}
sc.Authenticator = authenticator(c)

s, err := sc.SystemGet()
if err != nil {
return status
}

return s.Status
}

func selfManagedRackHost(c *stdcli.Context) map[string]string {
data, err := c.SettingRead("self-managed")
if err != nil {
return map[string]string{}
}

var rs map[string]string

if err := json.Unmarshal([]byte(data), &rs); err != nil {
return map[string]string{}
}

return rs
}

func matchRack(c *stdcli.Context, name string) (*rack, error) {
rs, err := racks(c)
if err != nil {
Expand Down Expand Up @@ -252,6 +314,9 @@ func racks(c *stdcli.Context) ([]rack, error) {

rs = append(rs, lrs...)

sfr, _ := selfManagedRacks(c)
rs = append(rs, sfr...)

sort.Slice(rs, func(i, j int) bool {
return rs[i].Name < rs[j].Name
})
Expand Down
9 changes: 8 additions & 1 deletion pkg/cli/rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func RackInstall(rack sdk.Interface, c *stdcli.Context) error {
return err
}

if err := c.SettingWriteKey("self-managed", *opts.Name, u.Host); err != nil {
return err
}

if host, _ := c.SettingRead("host"); host == "" {
c.SettingWrite("host", u.Host)
}
Expand Down Expand Up @@ -427,6 +431,7 @@ func RackSync(rack sdk.Interface, c *stdcli.Context) error {

func RackUninstall(rack sdk.Interface, c *stdcli.Context) error {
var opts structs.SystemUninstallOptions
name := c.Arg(1)

if err := c.Options(&opts); err != nil {
return err
Expand All @@ -445,7 +450,9 @@ func RackUninstall(rack sdk.Interface, c *stdcli.Context) error {
return err
}

if err := p.SystemUninstall(c.Arg(1), c, opts); err != nil {
c.SettingDeleteKey("self-managed", name)

if err := p.SystemUninstall(name, c, opts); err != nil {
return err
}

Expand Down
13 changes: 12 additions & 1 deletion pkg/cli/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"encoding/json"
"strings"

"github.com/convox/rack/sdk"
"github.com/convox/stdcli"
Expand All @@ -25,7 +26,17 @@ func Switch(rack sdk.Interface, c *stdcli.Context) error {
return err
}

rs := hostRacks(c)
var rs map[string]string
if len(strings.Split(r.Name, "/")) > 1 {
rs = hostRacks(c)
} else {
rs = selfManagedRackHost(c)

hostname := rs[r.Name]
if err := c.SettingWrite("host", hostname); err != nil {
return err
}
}

rs[host] = r.Name

Expand Down
2 changes: 1 addition & 1 deletion provider/aws/formation/resource/redis.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"Version": {
"Type": "String",
"Default": "2.8"
"Default": "3.2.6"
}
},
"Outputs": {
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/convox/stdcli/context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/github.com/convox/stdcli/setting.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ github.com/convox/logger
# github.com/convox/stdapi v1.1.3-0.20221110171947-8d98f61e61ed
## explicit; go 1.12
github.com/convox/stdapi
# github.com/convox/stdcli v0.0.0-20221110070640-8f8fb17bfe20
# github.com/convox/stdcli v0.0.0-20230203181735-23ed17b69b51
## explicit; go 1.13
github.com/convox/stdcli
# github.com/convox/stdsdk v0.0.0-20190422120437-3e80a397e377
Expand Down