Skip to content

Commit

Permalink
*: fix web UI build failure (#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunDunDM authored and sre-bot committed Dec 24, 2019
1 parent 71d95d6 commit 4336d59
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "pkg/ui/pd-web"]
path = pkg/ui/pd-web
url = https://github.com/pingcap-fe/pd-web.git
url = https://github.com/pingcap/pd-web.git
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-alpine as builder
FROM golang:1.13-alpine as builder
MAINTAINER siddontang

RUN apk add --no-cache \
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ ci: build check basic-test
build: pd-server pd-ctl
tools: pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench
pd-server: export GO111MODULE=on
pd-server:
ifeq ("$(WITH_RACE)", "1")
pd-server:
CGO_ENABLED=1 go build -race -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o bin/pd-server cmd/pd-server/main.go
else ifeq ("$(PD_WEB)", "1")
pd-server: retool-setup
@./scripts/build-ui.sh
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o bin/pd-server cmd/pd-server/main.go
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -tags web -o bin/pd-server cmd/pd-server/main.go
else
pd-server:
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o bin/pd-server cmd/pd-server/main.go
endif

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PD supports distribution and fault-tolerance by embedding [etcd](https://github.

## Build

1. Make sure [*Go*](https://golang.org/) (version 1.12) is installed.
1. Make sure [*Go*](https://golang.org/) (version 1.13) is installed.
2. Use `make` to install PD. PD is installed in the `bin` directory.

## Usage
Expand Down
2 changes: 0 additions & 2 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import (

// Register schedulers.
_ "github.com/pingcap/pd/server/schedulers"
// Register UI
_ "github.com/pingcap/pd/pkg/ui/dist"
)

func main() {
Expand Down
12 changes: 12 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ You can build your changes with

make

### Building with [PD-Web](https://github.com/pingcap/pd-web)

It is difficult to ensure dependencies in a production environment, so it is recommended to try in a development environment.

* Make sure [*Go*](https://golang.org/) (version 1.13) is installed.
* Make sure [*Git*](https://git-scm.com/) and [*Git LFS*](https://git-lfs.github.com/) are installed.
* Make sure [*Node*](https://nodejs.org/) and [*Yarn*](https://yarnpkg.com/en/docs/install) are installed.

Then you can build your changes with

PD_WEB=1 make

## Linting

Run linters as you make your changes.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/pd-web
24 changes: 24 additions & 0 deletions pkg/ui/web.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019 PingCAP, 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,
// See the License for the specific language governing permissions and
// limitations under the License.

// +build web

package ui

import "github.com/pingcap/pd/pkg/ui/dist"

func init() {
Asset = dist.Asset
AssetDir = dist.AssetDir
AssetInfo = dist.AssetInfo
}
3 changes: 1 addition & 2 deletions scripts/build-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ set -euo pipefail
# Make sure docker is installed before executing it.

docker pull mattjtodd/raml2html:latest
docker run --rm -v $PWD:/raml mattjtodd/raml2html -i /raml/server/api/api.raml -o /raml/docs/api.html

docker run --rm -v "$PWD:/raml" mattjtodd/raml2html -i /raml/server/api/api.raml -o /raml/docs/api.html
25 changes: 14 additions & 11 deletions scripts/build-ui.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/env bash
git submodule update --remote
BASEDIR=$(git rev-parse --show-toplevel)
UI_DIR="$BASEDIR/pkg/ui/pd-web"
TARGET_DIST="$BASEDIR/pkg/ui/dist"
SCRIPTS_DIR="$BASEDIR/scripts"
set -euo pipefail

git submodule update --init --recursive
git submodule foreach --recursive git lfs pull

BASE_DIR=$(git rev-parse --show-toplevel)
WEB_DIR="$BASE_DIR/pkg/ui/pd-web"
TARGET_DIST="$BASE_DIR/pkg/ui/dist"
SCRIPTS_DIR="$BASE_DIR/scripts"

echo "##### Build Web UI"
cd $UI_DIR
yarn
cd "$WEB_DIR" || { echo "No such directory: $WEB_DIR"; exit 1; }
yarn install --frozen-lockfile
PUBLIC_URL=/web yarn build

echo "##### Build Binary With UI"
$SCRIPTS_DIR/retool do go-bindata -o $TARGET_DIST/bindata.go -pkg dist -prefix=$UI_DIR/build $UI_DIR/build/...
echo 'func init() { ui.Asset = Asset; ui.AssetDir = AssetDir; ui.AssetInfo = AssetInfo }' >> $TARGET_DIST/bindata.go
gofmt -s -w $TARGET_DIST/bindata.go
$SCRIPTS_DIR/retool do goimports -w $TARGET_DIST/bindata.go
"$SCRIPTS_DIR/retool" "do" go-bindata -o "$TARGET_DIST/bindata.go" -pkg dist -prefix="$WEB_DIR/build" "$WEB_DIR/build/..."
3 changes: 1 addition & 2 deletions scripts/retool
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
# Add standard retool options
set -euo pipefail


cd $(dirname "$0")/..
cd "$(dirname "$0")/.."
exec retool -tool-dir "$PWD/.retools" "$@"
6 changes: 3 additions & 3 deletions scripts/retool-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -euo pipefail
# This script generates tools.json
# It helps record what releases/branches are being used

cd $(dirname "$0")/..
which retool >/dev/null || go get github.com/twitchtv/retool
cd "$(dirname "$0")/.."
command -v retool >/dev/null || go get github.com/twitchtv/retool

# tool environment
# check runner
Expand All @@ -26,4 +26,4 @@ which retool >/dev/null || go get github.com/twitchtv/retool
# deadlock detection
./scripts/retool add golang.org/x/tools/cmd/goimports 04b5d21e00f1f47bd824a6ade581e7189bacde87
# bindata
./scripts/retool add github.com/kevinburke/go-bindata v3.16.0
./scripts/retool add github.com/kevinburke/go-bindata/go-bindata v3.16.0
4 changes: 2 additions & 2 deletions tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"Commit": "04b5d21e00f1f47bd824a6ade581e7189bacde87"
},
{
"Repository": "github.com/kevinburke/go-bindata",
"Commit": "f6a432f39fbebd7aaaf4f29ca1aac539edbf6834"
"Repository": "github.com/kevinburke/go-bindata/go-bindata",
"Commit": "c7c189834d8e8384b8aa7428c02e4deee6df6b17"
},
{
"Repository": "gopkg.in/alecthomas/gometalinter.v2",
Expand Down

0 comments on commit 4336d59

Please sign in to comment.