mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 21:09:38 +00:00
Use image-tag from build-tools (#1785)
* Squashed 'tools/' changes from e9e7e6b..db5efc0db5efc0Merge pull request #28 from weaveworks/mike/add-image-tag5312c40Import image-tag script into build tools so it can be shared7e850f8Fix logs pathdda9785Update deploy apif2f4e5bFix the wcloud client3925eb6Merge pull request #27 from weaveworks/wcloud-events77355b9Lintd9a1c6cAdd wcloud events, update flags and error nicely when there is no config git-subtree-dir: tools git-subtree-split:db5efc0537* Remove ./image-tag and use ./tools/image-tag instead image-tag is now shared code from the build-tools repo
This commit is contained in:
2
Makefile
2
Makefile
@@ -30,7 +30,7 @@ WITH_GO_HOST_ENV=$(NO_CROSS_COMP); $(GO_ENV)
|
||||
GO_BUILD_INSTALL_DEPS=-i
|
||||
GO_BUILD_TAGS='netgo unsafe'
|
||||
GO_BUILD_FLAGS=$(GO_BUILD_INSTALL_DEPS) -ldflags "-extldflags \"-static\" -X main.version=$(SCOPE_VERSION) -s -w" -tags $(GO_BUILD_TAGS)
|
||||
IMAGE_TAG=$(shell ./image-tag)
|
||||
IMAGE_TAG=$(shell ./tools/image-tag)
|
||||
|
||||
all: $(SCOPE_EXPORT)
|
||||
|
||||
|
||||
@@ -69,12 +69,12 @@ deployment:
|
||||
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS &&
|
||||
(test "${DOCKER_ORGANIZATION:-$DOCKER_USER}" == "weaveworks" || (
|
||||
docker tag weaveworks/scope:latest ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope:latest &&
|
||||
docker tag weaveworks/scope:$(./image-tag) ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope:$(./image-tag)
|
||||
docker tag weaveworks/scope:$(./tools/image-tag) ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope:$(./tools/image-tag)
|
||||
)) &&
|
||||
docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope &&
|
||||
docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope:$(./image-tag) &&
|
||||
docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope:$(./tools/image-tag) &&
|
||||
(test "${DOCKER_ORGANIZATION:-$DOCKER_USER}" != "weaveworks" || (
|
||||
wcloud deploy weaveworks/scope:$(./image-tag)
|
||||
wcloud deploy weaveworks/scope:$(./tools/image-tag)
|
||||
))
|
||||
)
|
||||
hub-dev:
|
||||
|
||||
@@ -52,6 +52,8 @@ func main() {
|
||||
config(c, os.Args[2:])
|
||||
case "logs":
|
||||
logs(c, os.Args[2:])
|
||||
case "events":
|
||||
events(c, os.Args[2:])
|
||||
case "help":
|
||||
usage()
|
||||
default:
|
||||
@@ -80,14 +82,17 @@ func deploy(c Client, args []string) {
|
||||
}
|
||||
|
||||
func list(c Client, args []string) {
|
||||
flags := flag.NewFlagSet("list", flag.ContinueOnError)
|
||||
page := flags.Int("page", 0, "Zero based index of page to list.")
|
||||
pagesize := flags.Int("page-size", 10, "Number of results per page")
|
||||
var (
|
||||
flags = flag.NewFlagSet("", flag.ContinueOnError)
|
||||
since = flags.Duration("since", 7*24*time.Hour, "How far back to fetch results")
|
||||
)
|
||||
if err := flags.Parse(args); err != nil {
|
||||
usage()
|
||||
return
|
||||
}
|
||||
deployments, err := c.GetDeployments(*page, *pagesize)
|
||||
through := time.Now()
|
||||
from := through.Add(-*since)
|
||||
deployments, err := c.GetDeployments(from.Unix(), through.Unix())
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
@@ -109,6 +114,26 @@ func list(c Client, args []string) {
|
||||
table.Render()
|
||||
}
|
||||
|
||||
func events(c Client, args []string) {
|
||||
var (
|
||||
flags = flag.NewFlagSet("", flag.ContinueOnError)
|
||||
since = flags.Duration("since", 7*24*time.Hour, "How far back to fetch results")
|
||||
)
|
||||
if err := flags.Parse(args); err != nil {
|
||||
usage()
|
||||
return
|
||||
}
|
||||
through := time.Now()
|
||||
from := through.Add(-*since)
|
||||
events, err := c.GetEvents(from.Unix(), through.Unix())
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("events: ", string(events))
|
||||
}
|
||||
|
||||
func loadConfig(filename string) (*Config, error) {
|
||||
extension := filepath.Ext(filename)
|
||||
var config Config
|
||||
|
||||
@@ -38,7 +38,7 @@ func (c Client) Deploy(deployment Deployment) error {
|
||||
if err := json.NewEncoder(&buf).Encode(deployment); err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := c.newRequest("POST", "/api/deploy", &buf)
|
||||
req, err := c.newRequest("POST", "/api/deploy/deploy", &buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,8 +53,8 @@ func (c Client) Deploy(deployment Deployment) error {
|
||||
}
|
||||
|
||||
// GetDeployments returns a list of deployments
|
||||
func (c Client) GetDeployments(page, pagesize int) ([]Deployment, error) {
|
||||
req, err := c.newRequest("GET", fmt.Sprintf("/api/deploy?page=%d&pagesize=%d", page, pagesize), nil)
|
||||
func (c Client) GetDeployments(from, through int64) ([]Deployment, error) {
|
||||
req, err := c.newRequest("GET", fmt.Sprintf("/api/deploy/deploy?from=%d&through=%d", from, through), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -74,6 +74,22 @@ func (c Client) GetDeployments(page, pagesize int) ([]Deployment, error) {
|
||||
return response.Deployments, nil
|
||||
}
|
||||
|
||||
// GetEvents returns the raw events.
|
||||
func (c Client) GetEvents(from, through int64) ([]byte, error) {
|
||||
req, err := c.newRequest("GET", fmt.Sprintf("/api/deploy/event?from=%d&through=%d", from, through), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Error making request: %s", res.Status)
|
||||
}
|
||||
return ioutil.ReadAll(res.Body)
|
||||
}
|
||||
|
||||
// GetConfig returns the current Config
|
||||
func (c Client) GetConfig() (*Config, error) {
|
||||
req, err := c.newRequest("GET", "/api/config/deploy", nil)
|
||||
@@ -84,6 +100,9 @@ func (c Client) GetConfig() (*Config, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.StatusCode == 404 {
|
||||
return nil, fmt.Errorf("No configuration uploaded yet.")
|
||||
}
|
||||
if res.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Error making request: %s", res.Status)
|
||||
}
|
||||
@@ -116,7 +135,7 @@ func (c Client) SetConfig(config *Config) error {
|
||||
|
||||
// GetLogs returns the logs for a given deployment.
|
||||
func (c Client) GetLogs(deployID string) ([]byte, error) {
|
||||
req, err := c.newRequest("GET", fmt.Sprintf("/api/deploy/%s/log", deployID), nil)
|
||||
req, err := c.newRequest("GET", fmt.Sprintf("/api/deploy/deploy/%s/log", deployID), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user