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

Make make build ui #728

Merged
merged 3 commits into from
Dec 7, 2015
Merged
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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ coverage.html
.*.uptodate
scope.tar
scope_ui_build.tar
app/app
app/scope-app
prog/app/app
prog/app/scope-app
prog/probe/probe
prog/probe/scope-probe
docker/scope-app
Expand All @@ -54,3 +54,5 @@ experimental/_integration/_integration
*sublime-project
*sublime-workspace
*npm-debug.log
app/static.go
prog/app/static.go
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# If you can use Docker without being root, you can `make SUDO= <target>`
SUDO=sudo -E
DOCKERHUB_USER=weaveworks
APP_EXE=app/scope-app
APP_EXE=prog/app/scope-app
PROBE_EXE=prog/probe/scope-probe
FIXPROBE_EXE=experimental/fixprobe/fixprobe
SCOPE_IMAGE=$(DOCKERHUB_USER)/scope
Expand Down Expand Up @@ -38,7 +38,7 @@ $(SCOPE_EXPORT): $(APP_EXE) $(PROBE_EXE) $(DOCKER_DISTRIB) docker/weave $(RUNSVI

$(RUNSVINIT): vendor/runsvinit/*.go

$(APP_EXE): app/*.go render/*.go report/*.go xfer/*.go common/sanitize/*.go
$(APP_EXE): app/*.go render/*.go report/*.go xfer/*.go common/sanitize/*.go prog/app/*.go prog/app/static.go

$(PROBE_EXE): prog/probe/*.go $(shell find probe/ -type f -name *.go) report/*.go xfer/*.go common/sanitize/*.go common/exec/*.go

Expand All @@ -62,30 +62,35 @@ $(RUNSVINIT):
go build -ldflags "-extldflags \"-static\"" -o $@ ./$(@D)
endif

static: client/build/app.js
esc -o app/static.go -prefix client/build client/build
static: prog/app/static.go

prog/app/static.go: client/build/app.js
esc -o $@ -prefix client/build client/build

ifeq ($(BUILD_IN_CONTAINER),true)
client/build/app.js: $(shell find client/app/scripts -type f)
client/build/app.js: $(shell find client/app/scripts -type f) $(SCOPE_UI_BUILD_UPTODATE)
mkdir -p client/build
$(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \
-v $(shell pwd)/client/build:/home/weave/build \
$(SCOPE_UI_BUILD_IMAGE) npm run build

client-test: $(shell find client/app/scripts -type f)
client-test: $(shell find client/app/scripts -type f) $(SCOPE_UI_BUILD_UPTODATE)
$(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \
-v $(shell pwd)/client/test:/home/weave/test \
$(SCOPE_UI_BUILD_IMAGE) npm test

client-lint:
client-lint: $(SCOPE_UI_BUILD_UPTODATE)
$(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd)/client/app:/home/weave/app \
-v $(shell pwd)/client/test:/home/weave/test \
$(SCOPE_UI_BUILD_IMAGE) npm run lint

client-start:
client-start: $(SCOPE_UI_BUILD_UPTODATE)
$(SUDO) docker run $(RM) $(RUN_FLAGS) --net=host -v $(shell pwd)/client/app:/home/weave/app \
-v $(shell pwd)/client/build:/home/weave/build \
$(SCOPE_UI_BUILD_IMAGE) npm start
else
client/build/app.js:
cd client && npm run build
endif

$(SCOPE_UI_BUILD_UPTODATE): client/Dockerfile client/package.json client/webpack.local.config.js client/webpack.production.config.js client/server.js client/.eslintrc
Expand All @@ -96,8 +101,6 @@ $(SCOPE_BACKEND_BUILD_UPTODATE): backend/*
$(SUDO) docker build -t $(SCOPE_BACKEND_BUILD_IMAGE) backend
touch $@

frontend: $(SCOPE_UI_BUILD_UPTODATE)

clean:
go clean ./...
$(SUDO) docker rmi $(SCOPE_UI_BUILD_IMAGE) $(SCOPE_BACKEND_BUILD_IMAGE) >/dev/null 2>&1 || true
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,14 @@ Kubernetes-specific views "Pods", and "Pods by Service".

## <a name="developing"></a>Developing

The build is in five stages. `make deps` installs some tools we use later in
the build. `make frontend` builds a UI build image with all NPM dependencies.
`make static` compiles the UI into `static.go` which is part of the repository
for convenience. The final `make` builds the app and probe, in a container,
and pushes the lot into a Docker image called **weaveworks/scope**.
The build is in two stages. `make deps` installs some tools we use later in
the build. `make` builds the UI build container, builds the UI in said
container, builds the backend build container, builds the app and probe in a
said container, and finally pushes the lot into a Docker image called
**weaveworks/scope**.

```
make deps
make frontend
make static
make
```

Expand Down
2 changes: 1 addition & 1 deletion app/api_report.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"net/http"
Expand Down
13 changes: 11 additions & 2 deletions app/api_report_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package main
package app_test

import (
"encoding/json"
"net/http/httptest"
"testing"

"github.com/gorilla/mux"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/report"
)

func topologyServer() *httptest.Server {
router := mux.NewRouter()
app.RegisterTopologyRoutes(StaticReport{}, router)
return httptest.NewServer(router)
}

func TestAPIReport(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()

is404(t, ts, "/api/report/foobar")
Expand Down
2 changes: 1 addition & 1 deletion app/api_topologies.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"net/http"
Expand Down
17 changes: 12 additions & 5 deletions app/api_topologies_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package main
package app_test

import (
"bytes"
"encoding/gob"
"encoding/json"
"net/http/httptest"
"testing"
"time"

"github.com/gorilla/mux"
"k8s.io/kubernetes/pkg/api"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test/fixture"
)

func TestAPITopology(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()

body := getRawJSON(t, ts, "/api/topology")

var topologies []APITopologyDesc
var topologies []app.APITopologyDesc
if err := json.Unmarshal(body, &topologies); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand Down Expand Up @@ -48,12 +51,16 @@ func TestAPITopology(t *testing.T) {
}

func TestAPITopologyAddsKubernetes(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
router := mux.NewRouter()
c := app.NewCollector(1 * time.Minute)
app.RegisterTopologyRoutes(c, router)
app.RegisterReportPostHandler(c, router)
ts := httptest.NewServer(router)
defer ts.Close()

body := getRawJSON(t, ts, "/api/topology")

var topologies []APITopologyDesc
var topologies []app.APITopologyDesc
if err := json.Unmarshal(body, &topologies); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/api_topology.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"net/http"
Expand Down
32 changes: 16 additions & 16 deletions app/api_topology_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main
package app_test

import (
"encoding/json"
"fmt"
"net/http/httptest"
"net/url"
"reflect"
"testing"

"github.com/gorilla/websocket"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/render/expected"
"github.com/weaveworks/scope/report"
Expand All @@ -18,25 +18,25 @@ import (
)

func TestAll(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()

body := getRawJSON(t, ts, "/api/topology")
var topologies []APITopologyDesc
var topologies []app.APITopologyDesc
if err := json.Unmarshal(body, &topologies); err != nil {
t.Fatalf("JSON parse error: %s", err)
}

getTopology := func(topologyURL string) {
body := getRawJSON(t, ts, topologyURL)
var topology APITopology
var topology app.APITopology
if err := json.Unmarshal(body, &topology); err != nil {
t.Fatalf("JSON parse error: %s", err)
}

for _, node := range topology.Nodes {
body := getRawJSON(t, ts, fmt.Sprintf("%s/%s", topologyURL, url.QueryEscape(node.ID)))
var node APINode
var node app.APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand All @@ -53,10 +53,10 @@ func TestAll(t *testing.T) {
}

func TestAPITopologyContainers(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
{
body := getRawJSON(t, ts, "/api/topology/containers")
var topo APITopology
var topo app.APITopology
if err := json.Unmarshal(body, &topo); err != nil {
t.Fatal(err)
}
Expand All @@ -73,12 +73,12 @@ func TestAPITopologyContainers(t *testing.T) {
}

func TestAPITopologyApplications(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()
is404(t, ts, "/api/topology/applications/foobar")
{
body := getRawJSON(t, ts, "/api/topology/applications/"+expected.ServerProcessID)
var node APINode
var node app.APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatal(err)
}
Expand All @@ -90,7 +90,7 @@ func TestAPITopologyApplications(t *testing.T) {
}
{
body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/applications/%s/%s", expected.ClientProcess1ID, expected.ServerProcessID))
var edge APIEdge
var edge app.APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand All @@ -104,12 +104,12 @@ func TestAPITopologyApplications(t *testing.T) {
}

func TestAPITopologyHosts(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()
is404(t, ts, "/api/topology/hosts/foobar")
{
body := getRawJSON(t, ts, "/api/topology/hosts")
var topo APITopology
var topo app.APITopology
if err := json.Unmarshal(body, &topo); err != nil {
t.Fatal(err)
}
Expand All @@ -120,7 +120,7 @@ func TestAPITopologyHosts(t *testing.T) {
}
{
body := getRawJSON(t, ts, "/api/topology/hosts/"+expected.ServerHostRenderedID)
var node APINode
var node app.APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatal(err)
}
Expand All @@ -132,7 +132,7 @@ func TestAPITopologyHosts(t *testing.T) {
}
{
body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/hosts/%s/%s", expected.ClientHostRenderedID, expected.ServerHostRenderedID))
var edge APIEdge
var edge app.APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand All @@ -146,7 +146,7 @@ func TestAPITopologyHosts(t *testing.T) {

// Basic websocket test
func TestAPITopologyWebsocket(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()
url := "/api/topology/applications/ws"

Expand Down
18 changes: 12 additions & 6 deletions app/collector.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"sync"
Expand All @@ -21,9 +21,15 @@ type Adder interface {
Add(report.Report)
}

// A Collector is a Reporter and an Adder
type Collector interface {
Reporter
Adder
}

// Collector receives published reports from multiple producers. It yields a
// single merged report, representing all collected reports.
type Collector struct {
type collector struct {
mtx sync.Mutex
reports []timestampReport
window time.Duration
Expand Down Expand Up @@ -60,8 +66,8 @@ func (wc *waitableCondition) Broadcast() {
}

// NewCollector returns a collector ready for use.
func NewCollector(window time.Duration) *Collector {
return &Collector{
func NewCollector(window time.Duration) Collector {
return &collector{
window: window,
waitableCondition: waitableCondition{
waiters: map[chan struct{}]struct{}{},
Expand All @@ -72,7 +78,7 @@ func NewCollector(window time.Duration) *Collector {
var now = time.Now

// Add adds a report to the collector's internal state. It implements Adder.
func (c *Collector) Add(rpt report.Report) {
func (c *collector) Add(rpt report.Report) {
c.mtx.Lock()
defer c.mtx.Unlock()
c.reports = append(c.reports, timestampReport{now(), rpt})
Expand All @@ -84,7 +90,7 @@ func (c *Collector) Add(rpt report.Report) {

// Report returns a merged report over all added reports. It implements
// Reporter.
func (c *Collector) Report() report.Report {
func (c *collector) Report() report.Report {
c.mtx.Lock()
defer c.mtx.Unlock()

Expand Down
Loading