Merge probe and app binaries, run with ./scope probe or ./scope app.

This commit is contained in:
Tom Wilkie
2015-12-08 11:36:47 +00:00
parent 8db21fbb2d
commit c749f5aa33
9 changed files with 59 additions and 29 deletions

8
.gitignore vendored
View File

@@ -34,12 +34,8 @@ coverage.html
.*.uptodate
scope.tar
scope_ui_build.tar
prog/app/app
prog/app/scope-app
prog/probe/probe
prog/probe/scope-probe
docker/scope-app
docker/scope-probe
prog/scope
docker/scope
docker/docker*
docker/weave
docker/runsvinit

View File

@@ -3,9 +3,7 @@
# If you can use Docker without being root, you can `make SUDO= <target>`
SUDO=sudo -E
DOCKERHUB_USER=weaveworks
APP_EXE=prog/app/scope-app
PROBE_EXE=prog/probe/scope-probe
FIXPROBE_EXE=experimental/fixprobe/fixprobe
SCOPE_EXE=prog/scope
SCOPE_IMAGE=$(DOCKERHUB_USER)/scope
SCOPE_EXPORT=scope.tar
SCOPE_UI_BUILD_IMAGE=$(DOCKERHUB_USER)/scope-ui-build
@@ -30,24 +28,22 @@ docker/weave:
curl -L git.io/weave -o docker/weave
chmod u+x docker/weave
$(SCOPE_EXPORT): $(APP_EXE) $(PROBE_EXE) $(DOCKER_DISTRIB) docker/weave $(RUNSVINIT) docker/Dockerfile docker/run-app docker/run-probe docker/entrypoint.sh
cp $(APP_EXE) $(PROBE_EXE) $(RUNSVINIT) docker/
$(SCOPE_EXPORT): $(SCOPE_EXE) $(DOCKER_DISTRIB) docker/weave $(RUNSVINIT) docker/Dockerfile docker/run-app docker/run-probe docker/entrypoint.sh
cp $(SCOPE_EXE) $(RUNSVINIT) docker/
cp $(DOCKER_DISTRIB) docker/docker.tgz
$(SUDO) docker build -t $(SCOPE_IMAGE) docker/
$(SUDO) docker save $(SCOPE_IMAGE):latest > $@
$(RUNSVINIT): vendor/runsvinit/*.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
$(SCOPE_EXE): $(shell find ./ -type f -name *.go) prog/app/static.go
ifeq ($(BUILD_IN_CONTAINER),true)
$(APP_EXE) $(PROBE_EXE) $(RUNSVINIT): $(SCOPE_BACKEND_BUILD_UPTODATE)
$(SCOPE_EXE) $(RUNSVINIT): $(SCOPE_BACKEND_BUILD_UPTODATE)
$(SUDO) docker run $(RM) $(RUN_FLAGS) -v $(shell pwd):/go/src/github.com/weaveworks/scope -e GOARCH -e GOOS \
$(SCOPE_BACKEND_BUILD_IMAGE) SCOPE_VERSION=$(SCOPE_VERSION) $@
else
$(APP_EXE) $(PROBE_EXE): $(SCOPE_BACKEND_BUILD_UPTODATE)
$(SCOPE_EXE): $(SCOPE_BACKEND_BUILD_UPTODATE)
go build -ldflags "-extldflags \"-static\" -X main.version=$(SCOPE_VERSION)" -tags netgo -o $@ ./$(@D)
@strings $@ | grep cgo_stub\\\.go >/dev/null || { \
rm $@; \
@@ -65,7 +61,7 @@ endif
static: prog/app/static.go
prog/app/static.go: client/build/app.js
esc -o $@ -prefix client/build client/build
esc -o $@ -prefix client/build -pkg app client/build
ifeq ($(BUILD_IN_CONTAINER),true)
client/build/app.js: $(shell find client/app/scripts -type f) $(SCOPE_UI_BUILD_UPTODATE)
@@ -105,7 +101,7 @@ clean:
go clean ./...
$(SUDO) docker rmi $(SCOPE_UI_BUILD_IMAGE) $(SCOPE_BACKEND_BUILD_IMAGE) >/dev/null 2>&1 || true
rm -rf $(SCOPE_EXPORT) $(SCOPE_UI_BUILD_UPTODATE) $(SCOPE_BACKEND_BUILD_UPTODATE) \
$(APP_EXE) $(PROBE_EXE) $(RUNSVINIT) client/build/app.js docker/weave
$(SCOPE_EXE) $(RUNSVINIT) prog/app/static.go client/build/app.js docker/weave
ifeq ($(BUILD_IN_CONTAINER),true)
tests: $(SCOPE_BACKEND_BUILD_UPTODATE)

View File

@@ -39,9 +39,9 @@ test:
parallel: true
- cd $SRCDIR; make RM= static:
parallel: true
- cd $SRCDIR; rm -f prog/app/scope-app prog/probe/scope-probe; if [ "$CIRCLE_NODE_INDEX" = "0" ]; then GOARCH=arm make RM= prog/app/scope-app prog/probe/scope-probe; else GOOS=darwin make RM= prog/app/scope-app prog/probe/scope-probe; fi:
- cd $SRCDIR; rm -f prog/scope; if [ "$CIRCLE_NODE_INDEX" = "0" ]; then GOARCH=arm make RM= prog/scope; else GOOS=darwin make RM= prog/scope; fi:
parallel: true
- cd $SRCDIR; rm -f prog/app/scope-app prog/probe/scope-probe; make RM=:
- cd $SRCDIR; rm -f prog/scope; make RM=:
parallel: true
- cd $SRCDIR/experimental; ./build_on_circle.sh:
parallel: true

View File

@@ -7,7 +7,7 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/edge/testing" >>/etc/apk/repositori
rm -rf /var/cache/apk/*
ADD ./docker.tgz /
ADD ./weave /usr/bin/
COPY ./scope-app ./scope-probe ./runsvinit ./entrypoint.sh /home/weave/
COPY ./scope ./runsvinit ./entrypoint.sh /home/weave/
COPY ./run-app /etc/service/app/run
COPY ./run-probe /etc/service/probe/run
EXPOSE 4040

View File

@@ -1,3 +1,3 @@
#!/bin/sh
exec /home/weave/scope-app $(cat /etc/weave/scope-app.args)
exec /home/weave/scope app $(cat /etc/weave/scope-app.args)

View File

@@ -1,3 +1,3 @@
#!/bin/sh
exec /home/weave/scope-probe $(cat /etc/weave/scope-probe.args) $(cat /etc/weave/apps)
exec /home/weave/scope probe $(cat /etc/weave/scope-probe.args) $(cat /etc/weave/apps)

View File

@@ -1,4 +1,4 @@
package main
package app
import (
"flag"
@@ -6,11 +6,13 @@ import (
"log"
"math/rand"
"net/http"
_ "net/http/pprof"
"strconv"
"strings"
"time"
// a blank import should be only in a main or test package, or have a comment justifying it
_ "net/http/pprof"
"github.com/gorilla/mux"
"github.com/weaveworks/weave/common"
@@ -28,7 +30,8 @@ func Router(c app.Collector) *mux.Router {
return router
}
func main() {
// Main runs the app
func Main() {
var (
window = flag.Duration("window", 15*time.Second, "window")
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")

32
prog/main.go Normal file
View File

@@ -0,0 +1,32 @@
package main
import (
"fmt"
"os"
"github.com/weaveworks/scope/prog/app"
"github.com/weaveworks/scope/prog/probe"
)
func usage() {
fmt.Printf("usage: %s (app|probe) args...\n", os.Args[0])
os.Exit(1)
}
func main() {
if len(os.Args) < 2 {
usage()
}
module := os.Args[1]
os.Args = append([]string{os.Args[0]}, os.Args[2:]...)
switch module {
case "app":
app.Main()
case "probe":
probe.Main()
default:
usage()
}
}

View File

@@ -1,4 +1,4 @@
package main
package probe
import (
"flag"
@@ -7,12 +7,14 @@ import (
"math/rand"
"net"
"net/http"
_ "net/http/pprof"
"os"
"strconv"
"strings"
"time"
// a blank import should be only in a main or test package, or have a comment justifying it
_ "net/http/pprof"
"github.com/armon/go-metrics"
"github.com/weaveworks/weave/common"
@@ -31,7 +33,8 @@ import (
var version = "dev" // set at build time
func main() {
// Main runs the probe
func Main() {
var (
targets = []string{fmt.Sprintf("localhost:%d", xfer.AppPort), fmt.Sprintf("scope.weave.local:%d", xfer.AppPort)}
token = flag.String("token", "default-token", "probe token")