From 9da282d9615d8f2ac2e410d3a35201cc047c0cd5 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Mon, 15 Dec 2014 19:23:51 -0500 Subject: [PATCH 01/10] Add basic KV REST html UI and embedfile tool This change adds a basic UI for querying the REST API from a web GUI at /kv/rest/. It avoids the external dependency of another file (rest_ui.html) by generating a file through the go generate command and the embedfile tool before compilation. This is all a preamble to a better REST API, but also autogenerated documentation using embedfile and go generate. --- .gitignore | 3 + Makefile | 8 +- bootstrap.sh | 1 + kv/rest.go | 18 ++++ kv/rest_ui.html | 161 +++++++++++++++++++++++++++++++++++ tools/embedfile/embedfile.go | 67 +++++++++++++++ 6 files changed, 254 insertions(+), 4 deletions(-) create mode 100644 kv/rest_ui.html create mode 100644 tools/embedfile/embedfile.go diff --git a/.gitignore b/.gitignore index 203b5fe307da..27929d972537 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ cockroach _vendor/usr + +# Files generated by tools/embedfile +*.embedfile.go diff --git a/Makefile b/Makefile index 073ecb2f57ed..8cdff077a758 100644 --- a/Makefile +++ b/Makefile @@ -59,11 +59,14 @@ endif all: build test -auxiliary: storage/engine/engine.pc roach_proto roach_lib sqlparser +auxiliary: storage/engine/engine.pc roach_proto roach_lib sqlparser embedfiles build: auxiliary $(GO) build $(GOFLAGS) -i -o cockroach +embedfiles: + $(GO) generate ./... + storage/engine/engine.pc: storage/engine/engine.pc.in sed -e "s,@PWD@,$(CURDIR),g" -e "s,@LDEXTRA@,$(LDEXTRA),g" < $^ > $@ @@ -76,9 +79,6 @@ roach_lib: roach_proto sqlparser: make -C $(SQL_PARSER) -goget: - $(GO) get ./... - test: auxiliary $(GO) test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS) diff --git a/bootstrap.sh b/bootstrap.sh index 085bad8b61be..5ae1c83dc3b0 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -26,6 +26,7 @@ function go_get() { # Grab binaries required by git hooks. go_get github.com/golang/lint/golint go_get golang.org/x/tools/cmd/goimports +go_get github.com/cockroachdb/cockroach/tools/embedfile # go vet is special: it installs into $GOROOT (which $USER may not have # write access to) instead of $GOPATH. It is usually but not always # installed along with the rest of the go toolchain. Don't try to diff --git a/kv/rest.go b/kv/rest.go index 3aa54f6df9d9..d0a51c552d66 100644 --- a/kv/rest.go +++ b/kv/rest.go @@ -20,6 +20,7 @@ package kv import ( "encoding/json" "errors" + "html/template" "io/ioutil" "net/http" "net/url" @@ -109,6 +110,10 @@ func (s *RESTServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } } + if r.URL.Path == RESTPrefix { + s.handleRESTUI(w, r) + return + } http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) } @@ -313,3 +318,16 @@ func (s *RESTServer) handleDeleteAction(w http.ResponseWriter, r *http.Request, } writeJSON(w, http.StatusOK, dr) } + +//go:generate embedfile -input=rest_ui.html -constantname=restUI +func (s *RESTServer) handleRESTUI(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html") + tmpl, err := template.New("rest_ui").Parse(restUI) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + if err := tmpl.Execute(w, nil); err != nil { + log.Errorf("could not execute template: %v", err) + } +} diff --git a/kv/rest_ui.html b/kv/rest_ui.html new file mode 100644 index 000000000000..71c1bafd8715 --- /dev/null +++ b/kv/rest_ui.html @@ -0,0 +1,161 @@ + + + +Cockroach Playground + +
+
+

Put K/V Pair

+
+ + → + + +
+
+
+

Get/Head/Delete K/V Pair

+
+ + + + +
+
+
+

K/V Range

+
+ + → + + + +
+
+
+
+

Console

+ +
+
+ diff --git a/tools/embedfile/embedfile.go b/tools/embedfile/embedfile.go new file mode 100644 index 000000000000..b65e0478e7cb --- /dev/null +++ b/tools/embedfile/embedfile.go @@ -0,0 +1,67 @@ +// Copyright 2014 The Cockroach Authors. +// +// 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. See the AUTHORS file +// for names of contributors. +// +// Author: Andrew Bonventre (andybons@gmail.com) +// +// embedfile takes an input file and outputs a go source file with the +// input defined as a constant. It is used to eliminate the need for +// extra files (HTML templates, for example) for deployment. +package main + +import ( + "flag" + "fmt" + "io" + "log" + "os" + "path/filepath" + "strings" +) + +func main() { + var ( + inputFile = flag.String("input", "", "input file to embed") + constantName = flag.String("constantname", "", "the name of the constant that will contain the contents of the input file") + ) + flag.Parse() + if len(*inputFile) == 0 || len(*constantName) == 0 { + fmt.Printf("usage: %s\n", os.Args[0]) + flag.PrintDefaults() + os.Exit(1) + } + packageName := os.Getenv("GOPACKAGE") + if len(packageName) == 0 { + log.Fatalln("the $GOPACKAGE environment variable must be set") + } + r, err := os.Open(*inputFile) + if err != nil { + log.Fatalln(err) + } + _, outputFile := filepath.Split(*inputFile) + outputFile = strings.Replace(outputFile, filepath.Ext(outputFile), "", -1) + outputFile += "." + os.Args[0] + ".go" + w, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE, 0666) + if err != nil { + log.Fatalln(err) + } + fmt.Fprintf(w, "// Code generated by %s\n", os.Args[0]) + fmt.Fprintf(w, "// source: %s\n", *inputFile) + fmt.Fprintf(w, "// DO NOT EDIT!\n\npackage %s\n\n", packageName) + fmt.Fprintf(w, "const %s = `", *constantName) + if _, err := io.Copy(w, r); err != nil { + log.Fatalln(err) + } + fmt.Fprintln(w, "`") +} From 1d25902e5fee6547a6dd5c8835bd8c6cad3a6c96 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Mon, 15 Dec 2014 19:28:03 -0500 Subject: [PATCH 02/10] more appropriate naming --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8cdff077a758..2686fbf5ad74 100644 --- a/Makefile +++ b/Makefile @@ -59,12 +59,12 @@ endif all: build test -auxiliary: storage/engine/engine.pc roach_proto roach_lib sqlparser embedfiles +auxiliary: storage/engine/engine.pc roach_proto roach_lib sqlparser gogenerate build: auxiliary $(GO) build $(GOFLAGS) -i -o cockroach -embedfiles: +gogenerate: $(GO) generate ./... storage/engine/engine.pc: storage/engine/engine.pc.in From 43830c62e6a134997a7e2dee9e031cd33ec5813a Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Mon, 15 Dec 2014 20:44:57 -0500 Subject: [PATCH 03/10] use local checkout path for embedfile --- bootstrap.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 5ae1c83dc3b0..2eccc5028031 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -26,7 +26,8 @@ function go_get() { # Grab binaries required by git hooks. go_get github.com/golang/lint/golint go_get golang.org/x/tools/cmd/goimports -go_get github.com/cockroachdb/cockroach/tools/embedfile +# embedfile should use whatever is within the checkout. +go get github.com/cockroachdb/cockroach/tools/embedfile # go vet is special: it installs into $GOROOT (which $USER may not have # write access to) instead of $GOPATH. It is usually but not always # installed along with the rest of the go toolchain. Don't try to From 0f893013f78de9b4ccec21de2f3b35a3f6c9bd66 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Mon, 15 Dec 2014 22:12:04 -0500 Subject: [PATCH 04/10] use go install instead of go get --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 2eccc5028031..31630503035d 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -27,7 +27,7 @@ function go_get() { go_get github.com/golang/lint/golint go_get golang.org/x/tools/cmd/goimports # embedfile should use whatever is within the checkout. -go get github.com/cockroachdb/cockroach/tools/embedfile +go install github.com/cockroachdb/cockroach/tools/embedfile # go vet is special: it installs into $GOROOT (which $USER may not have # write access to) instead of $GOPATH. It is usually but not always # installed along with the rest of the go toolchain. Don't try to From a91c44af69786e72aa519d635d799ab511d84f06 Mon Sep 17 00:00:00 2001 From: Tobias Schottdorf Date: Wed, 17 Dec 2014 09:23:22 +0100 Subject: [PATCH 05/10] fix Docker build the problem was that ./bootstrap.sh is not actually run for the Docker builds; the devbase image is created in ./build/devbase and cannot access anything outside of that directory. It would be better to move embedfile out of ./tools into, say, build/devbase/tools, in which case we could install it in godeps.sh instead --- Dockerfile | 1 + build/devbase/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b4786317a890..91ab06c772b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ RUN ln -s /cockroach/build/devbase/cockroach.sh /cockroach/cockroach.sh # Build the cockroach executable. RUN cd -P /cockroach && git submodule update --init && \ cd -P /cockroach/_vendor/rocksdb && make static_lib +RUN ["go", "install", "github.com/cockroachdb/cockroach/tools/embedfile"] RUN cd -P /cockroach && make build # Expose the http status port. diff --git a/build/devbase/Dockerfile b/build/devbase/Dockerfile index 6e8c7ba5e655..50300faa5b7e 100644 --- a/build/devbase/Dockerfile +++ b/build/devbase/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:latest +FROM golang:1.4.0 MAINTAINER Tobias Schottdorf From 7b6578ae7f54c3e25519c161ee64eaf099a8d5e8 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 17 Dec 2014 19:45:05 -0500 Subject: [PATCH 06/10] no more embedding. Move to AngularJS --- Makefile | 5 +-- kv/rest.go | 18 -------- server/server.go | 7 +-- static/css/main.css | 58 +++++++++++++++++++++++++ static/css/playground.css | 52 ++++++++++++++++++++++ static/index.html | 39 +++++++++++++++++ static/js/controllers/playground.js | 58 +++++++++++++++++++++++++ static/js/main.js | 26 +++++++++++ static/templates/playground.html | 56 ++++++++++++++++++++++++ tools/embedfile/embedfile.go | 67 ----------------------------- 10 files changed, 294 insertions(+), 92 deletions(-) create mode 100644 static/css/main.css create mode 100644 static/css/playground.css create mode 100644 static/index.html create mode 100644 static/js/controllers/playground.js create mode 100644 static/js/main.js create mode 100644 static/templates/playground.html delete mode 100644 tools/embedfile/embedfile.go diff --git a/Makefile b/Makefile index 2686fbf5ad74..389efb0ce1e2 100644 --- a/Makefile +++ b/Makefile @@ -59,14 +59,11 @@ endif all: build test -auxiliary: storage/engine/engine.pc roach_proto roach_lib sqlparser gogenerate +auxiliary: storage/engine/engine.pc roach_proto roach_lib sqlparser build: auxiliary $(GO) build $(GOFLAGS) -i -o cockroach -gogenerate: - $(GO) generate ./... - storage/engine/engine.pc: storage/engine/engine.pc.in sed -e "s,@PWD@,$(CURDIR),g" -e "s,@LDEXTRA@,$(LDEXTRA),g" < $^ > $@ diff --git a/kv/rest.go b/kv/rest.go index d0a51c552d66..3aa54f6df9d9 100644 --- a/kv/rest.go +++ b/kv/rest.go @@ -20,7 +20,6 @@ package kv import ( "encoding/json" "errors" - "html/template" "io/ioutil" "net/http" "net/url" @@ -110,10 +109,6 @@ func (s *RESTServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } } - if r.URL.Path == RESTPrefix { - s.handleRESTUI(w, r) - return - } http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) } @@ -318,16 +313,3 @@ func (s *RESTServer) handleDeleteAction(w http.ResponseWriter, r *http.Request, } writeJSON(w, http.StatusOK, dr) } - -//go:generate embedfile -input=rest_ui.html -constantname=restUI -func (s *RESTServer) handleRESTUI(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/html") - tmpl, err := template.New("rest_ui").Parse(restUI) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - if err := tmpl.Execute(w, nil); err != nil { - log.Errorf("could not execute template: %v", err) - } -} diff --git a/server/server.go b/server/server.go index 912954282038..7894f25b4d77 100644 --- a/server/server.go +++ b/server/server.go @@ -50,8 +50,9 @@ import ( ) var ( - rpcAddr = flag.String("rpc", ":0", "host:port to bind for RPC traffic; 0 to pick unused port") - httpAddr = flag.String("http", ":8080", "host:port to bind for HTTP traffic; 0 to pick unused port") + rpcAddr = flag.String("rpc", ":0", "host:port to bind for RPC traffic; 0 to pick unused port") + httpAddr = flag.String("http", ":8080", "host:port to bind for HTTP traffic; 0 to pick unused port") + staticDir = flag.String("staticdir", "./static/", "directory containing static files for UI") certDir = flag.String("certs", "", "directory containing RSA key and x509 certs") @@ -392,7 +393,7 @@ func (s *server) start(engines []engine.Engine, attrs, httpAddr string, selfBoot } func (s *server) initHTTP() { - // TODO(shawn) pretty "/" landing page + s.mux.Handle("/", http.FileServer(http.Dir(*staticDir))) // Admin handlers. s.admin.RegisterHandlers(s.mux) diff --git a/static/css/main.css b/static/css/main.css new file mode 100644 index 000000000000..058c4a4e19bc --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,58 @@ +/** +Copyright 2014 The Cockroach Authors. + +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. See the AUTHORS file +for names of contributors. + +Author: Andrew Bonventre (andybons@gmail.com) +*/ +* { + margin: 0; + padding: 0; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} +html, +body { + height: 100%; +} +body { + background-color: #f1f2f3; + color: #333; + font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, sans-serif; + font-weight: 400; + font-size: 14px; +} +.fullHeightContainer { + height: calc(100% - 50px); /* Keep in line with height of .appNav */ +} +.appNav { + height: 50px; + background-color: #fff; + border-bottom: 1px solid #ddd; + padding: 10px 20px; +} +.appNav-link:link, +.appNav-link:visited { + text-decoration: none; + text-transform: uppercase; + color: #333; + display: inline-block; + margin-right: 20px; +} +.appNav-link.appNav-homeName { + font-weight: 800; + font-size: 22px; + text-transform: none; +} diff --git a/static/css/playground.css b/static/css/playground.css new file mode 100644 index 000000000000..fdcbf2b5b368 --- /dev/null +++ b/static/css/playground.css @@ -0,0 +1,52 @@ +/** +Copyright 2014 The Cockroach Authors. + +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. See the AUTHORS file +for names of contributors. + +Author: Andrew Bonventre (andybons@gmail.com) +*/ +.playground, +.playgroundControls, +.playgroundLog { + height: 100%; +} +.playgroundControls, +.playgroundLog { + float: left; + padding: 10px 20px; + width: 50%; +} +.playgroundControls { + background-color: #fff; +} +.playgroundControls-control { + margin-bottom: 20px; +} +.playgroundControls-control > h3 { + font-weight: normal; + text-transform: uppercase; + margin-bottom: 3px; +} +.playgroundControls-control input { + font: inherit; +} +.playgroundLog { + position: relative; + font-family: 'Source Code Pro', 'Courier New', Courier, monospace; +} +.playgroundLog-clearButton { + position: absolute; + right: 20px; + top: 10px; +} diff --git a/static/index.html b/static/index.html new file mode 100644 index 000000000000..4b5c1df03c8e --- /dev/null +++ b/static/index.html @@ -0,0 +1,39 @@ + + + + + + + + + + + + + Cockroach + + +
+ Cockroach + Playground +
+
+ + diff --git a/static/js/controllers/playground.js b/static/js/controllers/playground.js new file mode 100644 index 000000000000..d8f412dce69f --- /dev/null +++ b/static/js/controllers/playground.js @@ -0,0 +1,58 @@ +// Copyright 2014 The Cockroach Authors. +// +// 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. See the AUTHORS file +// for names of contributors. +// +// Author: Andrew Bonventre (andybons@gmail.com) + +var crApp = angular.module('cockroach'); +crApp.controller('PlaygroundCtrl', ['$scope', '$http', + function(scope, http) { + scope.responseLog = []; + scope.clearResponseLog = function(e) { + scope.responseLog = []; + }; + scope.requestPending = false; + scope.handleClick = function(e) { + e.preventDefault(); + var method = e.target.getAttribute('data-method'); + var endpoint = e.target.getAttribute('data-endpoint'); + var rangeMethod = endpoint == '/kv/rest/range'; + if (rangeMethod) { + endpoint += '?start=' + encodeURIComponent(scope.kvRangeStart); + if (!!scope.kvRangeEnd) { + endpoint += '&end=' + encodeURIComponent(scope.kvRangeEnd); + } + } else if (!!scope.kvKey) { + endpoint += scope.kvKey; + } + var data = {}; + if (!!scope.kvValue) { + data['value'] = scope.kvValue; + } + var req = { + method: method, + url: endpoint, + data: data, + }; + var responseFn = function(data, status, headers, config) { + if (typeof data == 'object') { + data = JSON.stringify(data); + } + var response = data.length > 0 ? data : '(no response body)'; + var msg = ['[', method, '] ', status, ' ', endpoint, ': ', response].join(''); + scope.responseLog.push(msg); + }; + http(req).success(responseFn).error(responseFn); + }; +}]); diff --git a/static/js/main.js b/static/js/main.js new file mode 100644 index 000000000000..52db1964375a --- /dev/null +++ b/static/js/main.js @@ -0,0 +1,26 @@ +// Copyright 2014 The Cockroach Authors. +// +// 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. See the AUTHORS file +// for names of contributors. +// +// Author: Andrew Bonventre (andybons@gmail.com) + +var crApp = angular.module('cockroach', ['ngRoute']); +crApp.config(['$routeProvider', function(routeProvider) { + routeProvider.when('/playground', { + controller:'PlaygroundCtrl', + templateUrl:'/templates/playground.html' + }).otherwise({ + redirectTo:'/' + }); +}]); diff --git a/static/templates/playground.html b/static/templates/playground.html new file mode 100644 index 000000000000..da2e62e760ce --- /dev/null +++ b/static/templates/playground.html @@ -0,0 +1,56 @@ + +
+
+
+

Put K/V Pair

+
+ + → + + +
+
+
+

Get/Head/Delete K/V Pair

+
+ + + + +
+
+
+

K/V Range

+
+ + → + + + +
+
+
+
+

Console

+ +
{{log}}
+
+
+ diff --git a/tools/embedfile/embedfile.go b/tools/embedfile/embedfile.go deleted file mode 100644 index b65e0478e7cb..000000000000 --- a/tools/embedfile/embedfile.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2014 The Cockroach Authors. -// -// 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. See the AUTHORS file -// for names of contributors. -// -// Author: Andrew Bonventre (andybons@gmail.com) -// -// embedfile takes an input file and outputs a go source file with the -// input defined as a constant. It is used to eliminate the need for -// extra files (HTML templates, for example) for deployment. -package main - -import ( - "flag" - "fmt" - "io" - "log" - "os" - "path/filepath" - "strings" -) - -func main() { - var ( - inputFile = flag.String("input", "", "input file to embed") - constantName = flag.String("constantname", "", "the name of the constant that will contain the contents of the input file") - ) - flag.Parse() - if len(*inputFile) == 0 || len(*constantName) == 0 { - fmt.Printf("usage: %s\n", os.Args[0]) - flag.PrintDefaults() - os.Exit(1) - } - packageName := os.Getenv("GOPACKAGE") - if len(packageName) == 0 { - log.Fatalln("the $GOPACKAGE environment variable must be set") - } - r, err := os.Open(*inputFile) - if err != nil { - log.Fatalln(err) - } - _, outputFile := filepath.Split(*inputFile) - outputFile = strings.Replace(outputFile, filepath.Ext(outputFile), "", -1) - outputFile += "." + os.Args[0] + ".go" - w, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE, 0666) - if err != nil { - log.Fatalln(err) - } - fmt.Fprintf(w, "// Code generated by %s\n", os.Args[0]) - fmt.Fprintf(w, "// source: %s\n", *inputFile) - fmt.Fprintf(w, "// DO NOT EDIT!\n\npackage %s\n\n", packageName) - fmt.Fprintf(w, "const %s = `", *constantName) - if _, err := io.Copy(w, r); err != nil { - log.Fatalln(err) - } - fmt.Fprintln(w, "`") -} From f3eea5216c5d4614f7db98b912d2c365d0b900b6 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 17 Dec 2014 19:48:47 -0500 Subject: [PATCH 07/10] remove embedfile stuff --- .gitignore | 3 --- Dockerfile | 1 - bootstrap.sh | 2 -- 3 files changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index 27929d972537..203b5fe307da 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,3 @@ cockroach _vendor/usr - -# Files generated by tools/embedfile -*.embedfile.go diff --git a/Dockerfile b/Dockerfile index 91ab06c772b5..b4786317a890 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,6 @@ RUN ln -s /cockroach/build/devbase/cockroach.sh /cockroach/cockroach.sh # Build the cockroach executable. RUN cd -P /cockroach && git submodule update --init && \ cd -P /cockroach/_vendor/rocksdb && make static_lib -RUN ["go", "install", "github.com/cockroachdb/cockroach/tools/embedfile"] RUN cd -P /cockroach && make build # Expose the http status port. diff --git a/bootstrap.sh b/bootstrap.sh index 31630503035d..085bad8b61be 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -26,8 +26,6 @@ function go_get() { # Grab binaries required by git hooks. go_get github.com/golang/lint/golint go_get golang.org/x/tools/cmd/goimports -# embedfile should use whatever is within the checkout. -go install github.com/cockroachdb/cockroach/tools/embedfile # go vet is special: it installs into $GOROOT (which $USER may not have # write access to) instead of $GOPATH. It is usually but not always # installed along with the rest of the go toolchain. Don't try to From e6411272cd3cb76277b3d68d20d9f0603ef8214c Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 17 Dec 2014 19:49:30 -0500 Subject: [PATCH 08/10] remove original rest UI file --- kv/rest_ui.html | 161 ------------------------------------------------ 1 file changed, 161 deletions(-) delete mode 100644 kv/rest_ui.html diff --git a/kv/rest_ui.html b/kv/rest_ui.html deleted file mode 100644 index 71c1bafd8715..000000000000 --- a/kv/rest_ui.html +++ /dev/null @@ -1,161 +0,0 @@ - - - -Cockroach Playground - -
-
-

Put K/V Pair

-
- - → - - -
-
-
-

Get/Head/Delete K/V Pair

-
- - - - -
-
-
-

K/V Range

-
- - → - - - -
-
-
-
-

Console

- -
-
- From e272a304cb631d5ea6d3a11a137b94051187a551 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 17 Dec 2014 21:46:06 -0500 Subject: [PATCH 09/10] rename to rest explorer. add todo --- .../css/{playground.css => rest_explorer.css} | 22 +++++++++---------- static/index.html | 6 ++--- .../{playground.js => rest_explorer.js} | 2 +- static/js/main.js | 6 ++--- .../{playground.html => rest_explorer.html} | 16 ++++++++------ 5 files changed, 27 insertions(+), 25 deletions(-) rename static/css/{playground.css => rest_explorer.css} (78%) rename static/js/controllers/{playground.js => rest_explorer.js} (97%) rename static/templates/{playground.html => rest_explorer.html} (85%) diff --git a/static/css/playground.css b/static/css/rest_explorer.css similarity index 78% rename from static/css/playground.css rename to static/css/rest_explorer.css index fdcbf2b5b368..ef853f81005f 100644 --- a/static/css/playground.css +++ b/static/css/rest_explorer.css @@ -16,36 +16,36 @@ for names of contributors. Author: Andrew Bonventre (andybons@gmail.com) */ -.playground, -.playgroundControls, -.playgroundLog { +.restExplorer, +.restExplorerControls, +.restExplorerLog { height: 100%; } -.playgroundControls, -.playgroundLog { +.restExplorerControls, +.restExplorerLog { float: left; padding: 10px 20px; width: 50%; } -.playgroundControls { +.restExplorerControls { background-color: #fff; } -.playgroundControls-control { +.restExplorerControls-control { margin-bottom: 20px; } -.playgroundControls-control > h3 { +.restExplorerControls-control > h3 { font-weight: normal; text-transform: uppercase; margin-bottom: 3px; } -.playgroundControls-control input { +.restExplorerControls-control input { font: inherit; } -.playgroundLog { +.restExplorerLog { position: relative; font-family: 'Source Code Pro', 'Courier New', Courier, monospace; } -.playgroundLog-clearButton { +.restExplorerLog-clearButton { position: absolute; right: 20px; top: 10px; diff --git a/static/index.html b/static/index.html index 4b5c1df03c8e..f5a4aa868ebc 100644 --- a/static/index.html +++ b/static/index.html @@ -22,17 +22,17 @@ - + - + Cockroach
Cockroach - Playground + REST Explorer
diff --git a/static/js/controllers/playground.js b/static/js/controllers/rest_explorer.js similarity index 97% rename from static/js/controllers/playground.js rename to static/js/controllers/rest_explorer.js index d8f412dce69f..27b4bfb9204a 100644 --- a/static/js/controllers/playground.js +++ b/static/js/controllers/rest_explorer.js @@ -16,7 +16,7 @@ // Author: Andrew Bonventre (andybons@gmail.com) var crApp = angular.module('cockroach'); -crApp.controller('PlaygroundCtrl', ['$scope', '$http', +crApp.controller('RestExplorerCtrl', ['$scope', '$http', function(scope, http) { scope.responseLog = []; scope.clearResponseLog = function(e) { diff --git a/static/js/main.js b/static/js/main.js index 52db1964375a..54511a06885a 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -17,9 +17,9 @@ var crApp = angular.module('cockroach', ['ngRoute']); crApp.config(['$routeProvider', function(routeProvider) { - routeProvider.when('/playground', { - controller:'PlaygroundCtrl', - templateUrl:'/templates/playground.html' + routeProvider.when('/rest-explorer', { + controller:'RestExplorerCtrl', + templateUrl:'/templates/rest_explorer.html' }).otherwise({ redirectTo:'/' }); diff --git a/static/templates/playground.html b/static/templates/rest_explorer.html similarity index 85% rename from static/templates/playground.html rename to static/templates/rest_explorer.html index da2e62e760ce..d56354ae3133 100644 --- a/static/templates/playground.html +++ b/static/templates/rest_explorer.html @@ -15,10 +15,12 @@ for names of contributors. Author: Andrew Bonventre (andybons@gmail.com) + +TODO(andybons): Add support for kv/rest/counter. --> -
-
-
+
+
+

Put K/V Pair

@@ -27,7 +29,7 @@

Put K/V Pair

-
+

Get/Head/Delete K/V Pair

@@ -36,7 +38,7 @@

Get/Head/Delete K/V Pair

-
+

K/V Range

@@ -47,9 +49,9 @@

K/V Range

-
+

Console

- +
{{log}}
From e32cc924bce04cf8be7390a4115ebcac0ede196c Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 17 Dec 2014 21:56:36 -0500 Subject: [PATCH 10/10] adjust Dockerfiles --- build/deploy/Dockerfile | 1 + build/deploy/mkimage.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/build/deploy/Dockerfile b/build/deploy/Dockerfile index 3c830966067a..ac2dccca9c38 100644 --- a/build/deploy/Dockerfile +++ b/build/deploy/Dockerfile @@ -7,6 +7,7 @@ ADD cockroach /cockroach/ ADD cockroach.sh /cockroach/ ADD test.sh /test/ ADD resources /cockroach/resources/ +ADD static /cockroach/static/ # Set working directory so that relative paths # are resolved appropriately when passed as args. diff --git a/build/deploy/mkimage.sh b/build/deploy/mkimage.sh index d0cf9c02952b..0a7fa72f92fe 100755 --- a/build/deploy/mkimage.sh +++ b/build/deploy/mkimage.sh @@ -22,5 +22,6 @@ docker run "cockroachdb/cockroach-dev" shell "export STATIC=1 && \ tar -xvC .out/ -f .out/files.tar && rm -f .out/files.tar mv .out/cockroach . cp -r .out/resources ./resources +cp -r .out/static ./static docker build -t cockroachdb/cockroach . docker run -v "${DIR}/.out":/test/.out cockroachdb/cockroach