forked from deis/deis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joshua Anderson
committed
Jul 17, 2015
1 parent
352575c
commit 3b5bb9c
Showing
50 changed files
with
4,181 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2015 Engine Yard, Inc. | ||
|
||
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 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
include ../includes.mk | ||
|
||
# the filepath to this repository, relative to $GOPATH/src | ||
repo_path = github.com/deis/deis/client-go | ||
|
||
GO_FILES = $(wildcard *.go) | ||
GO_PACKAGES = parser cmd controller/api controller/client $(wildcard controller/models/*) | ||
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES)) | ||
|
||
COMPONENT = $(notdir $(repo_path)) | ||
IMAGE = $(IMAGE_PREFIX)/$(COMPONENT):$(BUILD_TAG) | ||
|
||
build: | ||
CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o deis . | ||
$(call check-static-binary,deis) | ||
|
||
install: | ||
godep go install -v . | ||
|
||
setup-root-gotools: | ||
sudo GOPATH=/tmp/tmpGOPATH go get -u -v golang.org/x/tools/cmd/cover | ||
sudo GOPATH=/tmp/tmpGOPATH go get -u -v golang.org/x/tools/cmd/vet | ||
sudo rm -rf /tmp/tmpGOPATH | ||
|
||
setup-gotools: | ||
go get -u github.com/golang/lint/golint | ||
go get -u golang.org/x/tools/cmd/cover | ||
go get -u golang.org/x/tools/cmd/vet | ||
|
||
test: test-style test-unit | ||
|
||
test-style: | ||
# display output, then check | ||
$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | ||
@$(GOFMT) $(GO_PACKAGES) $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi | ||
$(GOVET) $(repo_path) $(GO_PACKAGES_REPO_PATH) | ||
$(GOLINT) ./... | ||
|
||
test-unit: | ||
$(GOTEST) ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Deis Client | ||
|
||
`deis` is a command line utility used to interact with a Deis Cluster. | ||
|
||
This is a WIP rewrite of the client in go. | ||
|
||
## License | ||
|
||
Copyright 2015, Engine Yard, Inc. | ||
|
||
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> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"github.com/deis/deis/pkg/prettyprint" | ||
|
||
"github.com/deis/deis/client-go/controller/client" | ||
"github.com/deis/deis/client-go/controller/models/apps" | ||
"github.com/deis/deis/client-go/controller/models/config" | ||
) | ||
|
||
// AppCreate creates an app. | ||
func AppCreate(id string, buildpack string, remote string, noRemote bool) error { | ||
c, err := client.New() | ||
|
||
fmt.Print("Creating Application... ") | ||
quit := progress() | ||
app, err := apps.New(c, id) | ||
|
||
quit <- true | ||
<-quit | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("done, created %s\n", app.ID) | ||
|
||
if buildpack != "" { | ||
configValues := map[string]string{ | ||
"BUILDPACK_URL": buildpack, | ||
} | ||
if err = config.Set(c, app.ID, configValues); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if !noRemote { | ||
return c.CreateRemote(remote, app.ID) | ||
} | ||
|
||
fmt.Println("remote available at", c.RemoteURL(app.ID)) | ||
|
||
return nil | ||
} | ||
|
||
// AppsList lists apps on the Deis controller. | ||
func AppsList() error { | ||
c, err := client.New() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
apps, err := apps.List(c) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("=== Apps") | ||
|
||
for _, app := range apps { | ||
fmt.Println(app.ID) | ||
} | ||
return nil | ||
} | ||
|
||
// AppInfo prints info about app. | ||
func AppInfo(appID string) error { | ||
c, appID, err := load(appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
app, err := apps.Get(c, appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("=== %s Application\n", app.ID) | ||
fmt.Println("updated: ", app.Updated) | ||
fmt.Println("uuid: ", app.UUID) | ||
fmt.Println("created: ", app.Created) | ||
fmt.Println("url: ", app.URL) | ||
fmt.Println("owner: ", app.Owner) | ||
fmt.Println("id: ", app.ID) | ||
|
||
return nil | ||
} | ||
|
||
// AppOpen opens an app in the default webbrowser. | ||
func AppOpen(appID string) error { | ||
c, appID, err := load(appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
app, err := apps.Get(c, appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
u, err := url.Parse(app.URL) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
u.Scheme = "http" | ||
|
||
return client.Webbrowser(u.String()) | ||
} | ||
|
||
// AppLogs returns the logs from an app. | ||
func AppLogs(appID string, lines int) error { | ||
c, appID, err := load(appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
logs, err := apps.Logs(c, appID, lines) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, log := range strings.Split(strings.Trim(logs, `\n`), `\n`) { | ||
catagory := strings.Split(strings.Split(log, ": ")[0], " ")[1] | ||
colorVars := map[string]string{ | ||
"Color": chooseColor(catagory), | ||
"Log": log, | ||
} | ||
fmt.Println(prettyprint.ColorizeVars("{{.V.Color}}{{.V.Log}}{{.C.Default}}", colorVars)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// AppRun runs a one time command in the app. | ||
func AppRun(appID, command string) error { | ||
c, appID, err := load(appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Running '%s'...\n", command) | ||
|
||
out, err := apps.Run(c, appID, command) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Print(out.Output) | ||
os.Exit(out.ReturnCode) | ||
return nil | ||
} | ||
|
||
// AppDestroy destroys an app. | ||
func AppDestroy(appID, confirm string) error { | ||
gitSession := false | ||
|
||
c, err := client.New() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if appID == "" { | ||
appID, err = c.DetectApp() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
gitSession = true | ||
} | ||
|
||
if confirm == "" { | ||
fmt.Printf(` ! WARNING: Potentially Destructive Action | ||
! This command will destroy the application: %s | ||
! To proceed, type "%s" or re-run this command with --confirm=%s | ||
>`, appID, appID, appID) | ||
|
||
fmt.Scanln(&confirm) | ||
} | ||
|
||
if confirm != appID { | ||
return fmt.Errorf("App %s does not match confirm %s, aborting.", appID, confirm) | ||
} | ||
|
||
fmt.Printf("Destroying %s...", appID) | ||
|
||
if err = apps.Delete(c, appID); err != nil { | ||
return err | ||
} | ||
|
||
if gitSession { | ||
return c.DeleteRemote(appID) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.