Merge pull request #854 from influxdata/feature/yarn-builds

WIP Update builds to use yarn rather than npm install
pull/859/head
Chris Goller 2017-02-08 21:27:30 -06:00 committed by GitHub
commit 0689acf856
12 changed files with 127 additions and 39 deletions

6
.gitignore vendored
View File

@ -11,3 +11,9 @@ chronograf.db
chronograf-v1.db
npm-debug.log
.vscode
.DS_Store
.godep
.jsdep
.jssrc
.dev-jssrc
.bindata

View File

@ -4,6 +4,7 @@
### Upcoming Features
1. [#838](https://github.com/influxdata/chronograf/issues/838): Add detail node to kapacitor alerts
2. [#853](https://github.com/influxdata/chronograf/issues/853): Updated builds to use yarn over npm install
### Upcoming UI Improvements

2
Godeps
View File

@ -6,7 +6,7 @@ github.com/elazarl/go-bindata-assetfs 9a6736ed45b44bf3835afeebb3034b57ed329f3e
github.com/gogo/protobuf 6abcf94fd4c97dcb423fdafd42fe9f96ca7e421b
github.com/google/go-github 1bc362c7737e51014af7299e016444b654095ad9
github.com/google/go-querystring 9235644dd9e52eeae6fa48efd539fdc351a0af53
github.com/influxdata/kapacitor 0eb8c348b210dd3d32cb240a417f9e6ded1b691d
github.com/influxdata/kapacitor 5408057e5a3493d3b5bd38d5d535ea45b587f8ff
github.com/influxdata/usage-client 6d3895376368aa52a3a81d2a16e90f0f52371967
github.com/jessevdk/go-flags 4cc2832a6e6d1d3b815e2b9d544b2a4dfb3ce8fa
github.com/satori/go.uuid b061729afc07e77a8aa4fad0a2fd840958f1942a

View File

@ -1,18 +1,26 @@
.PHONY: assets dep clean test gotest gotestrace jstest run run-dev
VERSION ?= $(shell git describe --always --tags)
COMMIT ?= $(shell git rev-parse --short=8 HEAD)
GDM := $(shell command -v gdm 2> /dev/null)
GOBINDATA := $(shell go list -f {{.Root}} github.com/jteeuwen/go-bindata 2> /dev/null)
YARN := $(shell command -v yarn 2> /dev/null)
SOURCES := $(shell find . -name '*.go')
SOURCES := $(shell find . -name '*.go' ! -name '*_gen.go')
UISOURCES := $(shell find ui -type f -not \( -path ui/build/\* -o -path ui/node_modules/\* -prune \) )
LDFLAGS=-ldflags "-s -X main.version=${VERSION} -X main.commit=${COMMIT}"
BINARY=chronograf
default: dep build
.DEFAULT_GOAL := all
all: dep build
build: assets ${BINARY}
dev: dev-assets ${BINARY}
dev: dep dev-assets ${BINARY}
${BINARY}: $(SOURCES)
${BINARY}: $(SOURCES) .bindata
go build -o ${BINARY} ${LDFLAGS} ./cmd/chronograf/main.go
docker-${BINARY}: $(SOURCES)
@ -22,30 +30,51 @@ docker-${BINARY}: $(SOURCES)
docker: dep assets docker-${BINARY}
docker build -t chronograf .
assets: js bindata
assets: .jssrc .bindata
dev-assets: dev-js bindata
dev-assets: .dev-jssrc .bindata
bindata:
.bindata: server/swagger_gen.go canned/bin_gen.go dist/dist_gen.go
@touch .bindata
dist/dist_gen.go: $(UISOURCES)
go generate -x ./dist
go generate -x ./canned
server/swagger_gen.go: server/swagger.json
go generate -x ./server
js:
canned/bin_gen.go: canned/*.json
go generate -x ./canned
.jssrc: $(UISOURCES)
cd ui && npm run build
@touch .jssrc
dev-js:
.dev-jssrc: $(UISOURCES)
cd ui && npm run build:dev
@touch .dev-jssrc
dep: jsdep godep
dep: .jsdep .godep
godep:
.godep: Godeps
ifndef GDM
@echo "Installing GDM"
go get github.com/sparrc/gdm
gdm restore
endif
ifndef GOBINDATA
@echo "Installing go-bindata"
go get -u github.com/jteeuwen/go-bindata/...
endif
gdm restore
@touch .godep
jsdep:
cd ui && npm install
.jsdep: ui/yarn.lock
ifndef YARN
$(error Please install yarn 0.19.1+)
else
cd ui && yarn --no-progress --no-emoji
@touch .jsdep
endif
gen: bolt/internal/internal.proto
go generate -x ./bolt/internal
@ -71,5 +100,5 @@ clean:
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
cd ui && npm run clean
cd ui && rm -rf node_modules
.PHONY: clean test jstest gotest run
rm -f dist/dist_gen.go canned/bin_gen.go server/swagger_gen.go
@rm -f .godep .jsdep .jssrc .dev-jssrc .bindata

View File

@ -141,11 +141,12 @@ docker pull quay.io/influxdb/chronograf:latest
### From Source
* Chronograf works with go 1.7.x, node 6.x/7.x, and npm 3.x.
* Chronograf works with go 1.7.x, node 6.x/7.x, and yarn 0.18+.
* Chronograf requires [Kapacitor](https://github.com/influxdata/kapacitor) 1.1.x+ to create and store alerts.
1. [Install Go](https://golang.org/doc/install)
1. [Install Node and NPM](https://nodejs.org/en/download/)
1. [Install yarn](https://yarnpkg.com/docs/install)
1. [Setup your GOPATH](https://golang.org/doc/code.html#GOPATH)
1. Run `go get github.com/influxdata/chronograf`
1. Run `cd $GOPATH/src/github.com/influxdata/chronograf`

View File

@ -3,7 +3,7 @@ machine:
services:
- docker
environment:
DOCKER_TAG: chronograf-20170127
DOCKER_TAG: chronograf-20170208
dependencies:
override:
@ -13,6 +13,7 @@ test:
override:
- >
./etc/scripts/docker/run.sh
--debug
--test
--no-build
@ -22,6 +23,7 @@ deployment:
commands:
- >
./etc/scripts/docker/run.sh
--debug
--clean
--package
--platform all
@ -42,6 +44,7 @@ deployment:
- >
./etc/scripts/docker/run.sh
--clean
--debug
--release
--package
--platform all
@ -64,6 +67,7 @@ deployment:
- >
./etc/scripts/docker/run.sh
--clean
--debug
--release
--package
--platform all

View File

@ -1,8 +1,10 @@
FROM ubuntu:trusty
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y \
apt-transport-https \
python-dev \
wget \
curl \
git \
mercurial \
make \
@ -16,9 +18,9 @@ RUN pip install boto requests python-jose --upgrade
RUN gem install fpm
# Install node
RUN wget -q https://nodejs.org/dist/latest-v6.x/node-v6.9.4-linux-x64.tar.gz; \
tar -xvf node-v6.9.4-linux-x64.tar.gz -C / --strip-components=1; \
rm -f node-v6.9.4-linux-x64.tar.gz
RUN wget -q https://nodejs.org/dist/latest-v6.x/node-v6.9.5-linux-x64.tar.gz; \
tar -xvf node-v6.9.5-linux-x64.tar.gz -C / --strip-components=1; \
rm -f node-v6.9.5-linux-x64.tar.gz
# Update npm
RUN cd $(npm root -g)/npm \
@ -26,6 +28,10 @@ RUN cd $(npm root -g)/npm \
&& sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js
RUN npm install npm -g
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && sudo apt-get install yarn
# Install go
ENV GOPATH /root/go
ENV GO_VERSION 1.7.5

View File

@ -6,7 +6,7 @@ Our circle.yml uses this docker container to build, test and create release pack
### Updating new node/go versions
After updating the Dockerfile_build run
`docker build -t quay.io/influxdb/builder:chronograf-$(date "+%Y%m%d") -f Dockerfile_build`
`docker build -t quay.io/influxdb/builder:chronograf-$(date "+%Y%m%d") -f Dockerfile_build .`
and push to quay with:
`docker push quay.io/influxdb/builder:chronograf-$(date "+%Y%m%d")`

View File

@ -3,7 +3,6 @@
import sys
import os
import subprocess
import time
from datetime import datetime
import shutil
import tempfile
@ -46,7 +45,7 @@ MAINTAINER = "contact@influxdb.com"
VENDOR = "InfluxData"
DESCRIPTION = "Open source monitoring and visualization UI for the entire TICK stack."
prereqs = [ 'git', 'go', 'npm' ]
prereqs = [ 'git', 'go', 'npm','yarn' ]
go_vet_command = "go tool vet ./"
optional_prereqs = [ 'fpm', 'rpmbuild', 'gpg' ]
@ -142,29 +141,38 @@ def package_scripts(build_root, config_only=False, windows=False):
run("cp {} {} && chmod 644 {}".format(CANNED_SCRIPTS,
os.path.join(build_root, CANNED_DIR[1:]),
os.path.join(build_root, CANNED_DIR[1:], "*json")),
shell=True)
shell=True, print_output=True)
def run_generate():
"""Generate static assets.
"""
start_time = datetime.utcnow()
logging.info("Generating static assets...")
run("make assets", shell=True)
run("make assets", shell=True, print_output=True)
end_time = datetime.utcnow()
logging.info("Time taken: {}s".format((end_time - start_time).total_seconds()))
return True
def go_get(branch, update=False, no_uncommitted=False):
"""Retrieve build dependencies or restore pinned dependencies.
"""
start_time = datetime.utcnow()
if local_changes() and no_uncommitted:
logging.error("There are uncommitted changes in the current directory.")
return False
run("make dep", shell=True)
run("make dep", shell=True, print_output=True)
end_time = datetime.utcnow()
logging.info("Time taken: {}s".format((end_time - start_time).total_seconds()))
return True
def run_tests(race, parallel, timeout, no_vet):
"""Run the Go test suite on binary output.
"""Run the Go and NPM test suite on binary output.
"""
start_time = datetime.utcnow()
logging.info("Running tests...")
run("make test", shell=True, print_output=True)
end_time = datetime.utcnow()
logging.info("Time taken: {}s".format((end_time - start_time).total_seconds()))
return True
################
@ -497,7 +505,7 @@ def build(version=None,
build_command += "-a -installsuffix cgo "
build_command += path
start_time = datetime.utcnow()
run(build_command, shell=True)
run(build_command, shell=True, print_output=True)
end_time = datetime.utcnow()
logging.info("Time taken: {}s".format((end_time - start_time).total_seconds()))
return True
@ -633,13 +641,13 @@ def package(build_output, pkg_name, version, nightly=False, iteration=1, static=
current_location = os.path.join(os.getcwd(), current_location)
if package_type == 'tar':
tar_command = "cd {} && tar -cvzf {}.tar.gz --owner=root ./*".format(package_build_root, name)
run(tar_command, shell=True)
run(tar_command, shell=True, print_output=True)
run("mv {}.tar.gz {}".format(os.path.join(package_build_root, name), current_location), shell=True)
outfile = os.path.join(current_location, name + ".tar.gz")
outfiles.append(outfile)
elif package_type == 'zip':
zip_command = "cd {} && zip -r {}.zip ./*".format(package_build_root, name)
run(zip_command, shell=True)
run(zip_command, shell=True, print_output=True)
run("mv {}.zip {}".format(os.path.join(package_build_root, name), current_location), shell=True)
outfile = os.path.join(current_location, name + ".zip")
outfiles.append(outfile)
@ -720,7 +728,7 @@ def main(args):
orig_branch = get_current_branch()
if args.platform not in supported_builds and args.platform != 'all':
logging.error("Invalid build platform: {}".format(target_platform))
logging.error("Invalid build platform: {}".format(args.platform))
return 1
build_output = {}
@ -730,10 +738,10 @@ def main(args):
return 1
elif args.branch != orig_branch:
logging.info("Moving to git branch: {}".format(args.branch))
run("git checkout {}".format(args.branch))
run("git checkout {}".format(args.branch), print_output=True)
elif args.commit != orig_commit:
logging.info("Moving to git commit: {}".format(args.commit))
run("git checkout {}".format(args.commit))
run("git checkout {}".format(args.commit), print_output=True)
if not args.no_get:
if not go_get(args.branch, update=args.update, no_uncommitted=args.no_uncommitted):
@ -890,7 +898,7 @@ def main(args):
logging.info(json.dumps(package_output, sort_keys=True, indent=4))
if orig_branch != get_current_branch():
logging.info("Moving back to original git branch: {}".format(orig_branch))
run("git checkout {}".format(orig_branch))
run("git checkout {}".format(orig_branch), print_output=True)
return 0

33
ui/README.md Normal file
View File

@ -0,0 +1,33 @@
## Packages
We are using [yarn](https://yarnpkg.com/en/docs/install) 0.19.1.
### Adding new packages
To add a new package, run
```sh
yarn add packageName
```
### Adding devDependency
```sh
yarn add --dev packageName
```
### Updating a package
First, run
```sh
yarn outdated
```
... to determine which packages may need upgrading.
We _really_ should not upgrade all packages at once, but, one at a time and make darn sure
to test.
To upgrade a single package named `packageName`:
```sh
yarn upgrade packageName
```

View File

@ -1,6 +1,6 @@
{
"name": "chronograf-ui",
"version": "1.1.0",
"version": "1.2.0",
"private": false,
"license": "AGPL-3.0",
"description": "",

View File

@ -8,7 +8,7 @@ var dependencies = package.dependencies;
var config = {
bail: true,
devtool: 'hidden-source-map',
devtool: 'eval',
entry: {
app: path.resolve(__dirname, '..', 'src', 'index.js'),
vendor: Object.keys(dependencies),