Skip to content

Commit 3b5bb9c

Browse files
author
Joshua Anderson
committed
ref(client): rewrite client in go.
1 parent 352575c commit 3b5bb9c

50 files changed

Lines changed: 4181 additions & 7 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ builder/rootfs/usr/bin
2626
cache/image/bin/
2727
client/dist/
2828
client/makeself/
29+
client-go/deis
2930
contrib/azure/azure-user-data
3031
contrib/bumpver/bumpver
3132
deisctl/deisctl

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
1212

1313
COMPONENTS=builder cache controller database logger logspout publisher registry router store swarm
1414
START_ORDER=publisher store logger logspout database cache registry controller builder router
15-
CLIENTS=client deisctl
15+
CLIENTS=client client-go deisctl
1616

1717
all: build run
1818

client-go/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2015 Engine Yard, Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

client-go/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
include ../includes.mk
2+
3+
# the filepath to this repository, relative to $GOPATH/src
4+
repo_path = github.com/deis/deis/client-go
5+
6+
GO_FILES = $(wildcard *.go)
7+
GO_PACKAGES = parser cmd controller/api controller/client $(wildcard controller/models/*)
8+
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
9+
10+
COMPONENT = $(notdir $(repo_path))
11+
IMAGE = $(IMAGE_PREFIX)/$(COMPONENT):$(BUILD_TAG)
12+
13+
build:
14+
CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o deis .
15+
$(call check-static-binary,deis)
16+
17+
install:
18+
godep go install -v .
19+
20+
setup-root-gotools:
21+
sudo GOPATH=/tmp/tmpGOPATH go get -u -v golang.org/x/tools/cmd/cover
22+
sudo GOPATH=/tmp/tmpGOPATH go get -u -v golang.org/x/tools/cmd/vet
23+
sudo rm -rf /tmp/tmpGOPATH
24+
25+
setup-gotools:
26+
go get -u github.com/golang/lint/golint
27+
go get -u golang.org/x/tools/cmd/cover
28+
go get -u golang.org/x/tools/cmd/vet
29+
30+
test: test-style test-unit
31+
32+
test-style:
33+
# display output, then check
34+
$(GOFMT) $(GO_PACKAGES) $(GO_FILES)
35+
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi
36+
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH)
37+
$(GOLINT) ./...
38+
39+
test-unit:
40+
$(GOTEST) ./...

client-go/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Deis Client
2+
3+
`deis` is a command line utility used to interact with a Deis Cluster.
4+
5+
This is a WIP rewrite of the client in go.
6+
7+
## License
8+
9+
Copyright 2015, Engine Yard, Inc.
10+
11+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>
12+
13+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

client-go/cmd/apps.go

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
"os"
7+
"strings"
8+
9+
"github.com/deis/deis/pkg/prettyprint"
10+
11+
"github.com/deis/deis/client-go/controller/client"
12+
"github.com/deis/deis/client-go/controller/models/apps"
13+
"github.com/deis/deis/client-go/controller/models/config"
14+
)
15+
16+
// AppCreate creates an app.
17+
func AppCreate(id string, buildpack string, remote string, noRemote bool) error {
18+
c, err := client.New()
19+
20+
fmt.Print("Creating Application... ")
21+
quit := progress()
22+
app, err := apps.New(c, id)
23+
24+
quit <- true
25+
<-quit
26+
27+
if err != nil {
28+
return err
29+
}
30+
31+
fmt.Printf("done, created %s\n", app.ID)
32+
33+
if buildpack != "" {
34+
configValues := map[string]string{
35+
"BUILDPACK_URL": buildpack,
36+
}
37+
if err = config.Set(c, app.ID, configValues); err != nil {
38+
return err
39+
}
40+
}
41+
42+
if !noRemote {
43+
return c.CreateRemote(remote, app.ID)
44+
}
45+
46+
fmt.Println("remote available at", c.RemoteURL(app.ID))
47+
48+
return nil
49+
}
50+
51+
// AppsList lists apps on the Deis controller.
52+
func AppsList() error {
53+
c, err := client.New()
54+
55+
if err != nil {
56+
return err
57+
}
58+
59+
apps, err := apps.List(c)
60+
61+
if err != nil {
62+
return err
63+
}
64+
65+
fmt.Println("=== Apps")
66+
67+
for _, app := range apps {
68+
fmt.Println(app.ID)
69+
}
70+
return nil
71+
}
72+
73+
// AppInfo prints info about app.
74+
func AppInfo(appID string) error {
75+
c, appID, err := load(appID)
76+
77+
if err != nil {
78+
return err
79+
}
80+
81+
app, err := apps.Get(c, appID)
82+
83+
if err != nil {
84+
return err
85+
}
86+
87+
fmt.Printf("=== %s Application\n", app.ID)
88+
fmt.Println("updated: ", app.Updated)
89+
fmt.Println("uuid: ", app.UUID)
90+
fmt.Println("created: ", app.Created)
91+
fmt.Println("url: ", app.URL)
92+
fmt.Println("owner: ", app.Owner)
93+
fmt.Println("id: ", app.ID)
94+
95+
return nil
96+
}
97+
98+
// AppOpen opens an app in the default webbrowser.
99+
func AppOpen(appID string) error {
100+
c, appID, err := load(appID)
101+
102+
if err != nil {
103+
return err
104+
}
105+
106+
app, err := apps.Get(c, appID)
107+
108+
if err != nil {
109+
return err
110+
}
111+
112+
u, err := url.Parse(app.URL)
113+
114+
if err != nil {
115+
return err
116+
}
117+
118+
u.Scheme = "http"
119+
120+
return client.Webbrowser(u.String())
121+
}
122+
123+
// AppLogs returns the logs from an app.
124+
func AppLogs(appID string, lines int) error {
125+
c, appID, err := load(appID)
126+
127+
if err != nil {
128+
return err
129+
}
130+
131+
logs, err := apps.Logs(c, appID, lines)
132+
133+
if err != nil {
134+
return err
135+
}
136+
137+
for _, log := range strings.Split(strings.Trim(logs, `\n`), `\n`) {
138+
catagory := strings.Split(strings.Split(log, ": ")[0], " ")[1]
139+
colorVars := map[string]string{
140+
"Color": chooseColor(catagory),
141+
"Log": log,
142+
}
143+
fmt.Println(prettyprint.ColorizeVars("{{.V.Color}}{{.V.Log}}{{.C.Default}}", colorVars))
144+
}
145+
146+
return nil
147+
}
148+
149+
// AppRun runs a one time command in the app.
150+
func AppRun(appID, command string) error {
151+
c, appID, err := load(appID)
152+
153+
if err != nil {
154+
return err
155+
}
156+
157+
fmt.Printf("Running '%s'...\n", command)
158+
159+
out, err := apps.Run(c, appID, command)
160+
161+
if err != nil {
162+
return err
163+
}
164+
165+
fmt.Print(out.Output)
166+
os.Exit(out.ReturnCode)
167+
return nil
168+
}
169+
170+
// AppDestroy destroys an app.
171+
func AppDestroy(appID, confirm string) error {
172+
gitSession := false
173+
174+
c, err := client.New()
175+
176+
if err != nil {
177+
return err
178+
}
179+
180+
if appID == "" {
181+
appID, err = c.DetectApp()
182+
183+
if err != nil {
184+
return err
185+
}
186+
187+
gitSession = true
188+
}
189+
190+
if confirm == "" {
191+
fmt.Printf(` ! WARNING: Potentially Destructive Action
192+
! This command will destroy the application: %s
193+
! To proceed, type "%s" or re-run this command with --confirm=%s
194+
195+
>`, appID, appID, appID)
196+
197+
fmt.Scanln(&confirm)
198+
}
199+
200+
if confirm != appID {
201+
return fmt.Errorf("App %s does not match confirm %s, aborting.", appID, confirm)
202+
}
203+
204+
fmt.Printf("Destroying %s...", appID)
205+
206+
if err = apps.Delete(c, appID); err != nil {
207+
return err
208+
}
209+
210+
if gitSession {
211+
return c.DeleteRemote(appID)
212+
}
213+
214+
return nil
215+
}

0 commit comments

Comments
 (0)