Require dep to be installed before building (#4461)

This commit is contained in:
Daniel Nelson 2018-07-24 14:57:24 -07:00 committed by Greg
parent d95824a9c1
commit 9051ea9dc0
10 changed files with 204 additions and 86 deletions

View File

@ -4,10 +4,10 @@ defaults:
working_directory: '/go/src/github.com/influxdata/telegraf'
go-1_9: &go-1_9
docker:
- image: 'circleci/golang:1.9.7'
- image: 'quay.io/influxdb/telegraf-ci:1.9.7'
go-1_10: &go-1_10
docker:
- image: 'circleci/golang:1.10.3'
- image: 'quay.io/influxdb/telegraf-ci:1.10.3'
version: 2
jobs:
@ -27,53 +27,98 @@ jobs:
root: '/go/src'
paths:
- '*'
test-go-1.9:
<<: [ *defaults, *go-1_9 ]
steps:
- attach_workspace:
at: '/go/src'
- run: 'make test-ci'
- run: 'make check'
- run: 'make test'
test-go-1.10:
<<: [ *defaults, *go-1_10 ]
steps:
- attach_workspace:
at: '/go/src'
- run: 'make test-ci'
- run: 'GOARCH=386 make test-ci'
- run: 'make check'
- run: 'make test'
test-go-1.10-386:
<<: [ *defaults, *go-1_10 ]
steps:
- attach_workspace:
at: '/go/src'
- run: 'GOARCH=386 make check'
- run: 'GOARCH=386 make test'
package:
<<: [ *defaults, *go-1_10 ]
steps:
- attach_workspace:
at: '/go/src'
- run: 'make package'
- store_artifacts:
path: './build'
destination: 'build'
release:
<<: [ *defaults, *go-1_10 ]
steps:
- attach_workspace:
at: '/go/src'
- run: './scripts/release.sh'
- run: 'make package-release'
- store_artifacts:
path: './artifacts'
destination: '.'
path: './build'
destination: 'build'
nightly:
<<: [ *defaults, *go-1_10 ]
steps:
- attach_workspace:
at: '/go/src'
- run: './scripts/release.sh'
- run: 'make package-nightly'
- store_artifacts:
path: './artifacts'
destination: '.'
path: './build'
destination: 'build'
workflows:
version: 2
build_and_release:
check:
jobs:
- 'deps'
- 'deps':
filters:
tags:
only: /.*/
- 'test-go-1.9':
requires:
- 'deps'
filters:
tags:
only: /.*/
- 'test-go-1.10':
requires:
- 'deps'
filters:
tags:
only: /.*/
- 'test-go-1.10-386':
requires:
- 'deps'
filters:
tags:
only: /.*/
- 'package':
requires:
- 'test-go-1.9'
- 'test-go-1.10'
- 'test-go-1.10-386'
- 'release':
requires:
- 'test-go-1.9'
- 'test-go-1.10'
- 'test-go-1.10-386'
filters:
tags:
only: /.*/
branches:
ignore: /.*/
nightly:
jobs:
- 'deps'
@ -83,10 +128,14 @@ workflows:
- 'test-go-1.10':
requires:
- 'deps'
- 'test-go-1.10-386':
requires:
- 'deps'
- 'nightly':
requires:
- 'test-go-1.9'
- 'test-go-1.10'
- 'test-go-1.10-386'
triggers:
- schedule:
cron: "0 7 * * *"

View File

@ -30,9 +30,8 @@ which can be found [on our website](http://influxdb.com/community/cla.html)
Assuming you can already build the project, run these in the telegraf directory:
1. `go get -u github.com/golang/dep/cmd/dep`
2. `dep ensure -vendor-only`
3. `dep ensure -add github.com/[dependency]/[new-package]`
1. `dep ensure -vendor-only`
2. `dep ensure -add github.com/[dependency]/[new-package]`
## Input Plugins

View File

@ -17,10 +17,8 @@ BUILDFLAGS ?=
ifdef GOBIN
PATH := $(GOBIN):$(PATH)
else ifdef GOPATH
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
else
PATH := $(HOME)/go/bin:$(PATH)
PATH := $(subst :,/bin:,$(shell go env GOPATH))/bin:$(PATH)
endif
LDFLAGS := $(LDFLAGS) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)
@ -28,33 +26,39 @@ ifdef VERSION
LDFLAGS += -X main.version=$(VERSION)
endif
.PHONY: all
all:
$(MAKE) deps
$(MAKE) telegraf
@$(MAKE) --no-print-directory deps
@$(MAKE) --no-print-directory telegraf
.PHONY: deps
deps:
go get -u github.com/golang/lint/golint
go get -u github.com/golang/dep/cmd/dep
dep ensure -vendor-only
.PHONY: telegraf
telegraf:
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
.PHONY: go-install
go-install:
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/telegraf
.PHONY: install
install: telegraf
mkdir -p $(DESTDIR)$(PREFIX)/bin/
cp telegraf $(DESTDIR)$(PREFIX)/bin/
.PHONY: test
test:
go test -short ./...
.PHONY: fmt
fmt:
@gofmt -w $(filter-out plugins/parsers/influx/machine.go, $(GOFILES))
.PHONY: fmtcheck
fmtcheck:
@echo '[INFO] running gofmt to identify incorrectly formatted code...'
@if [ ! -z "$(GOFMT)" ]; then \
echo "[ERROR] gofmt has found errors in the following files:" ; \
echo "$(GOFMT)" ; \
@ -62,8 +66,8 @@ fmtcheck:
echo "Run make fmt to fix them." ; \
exit 1 ;\
fi
@echo '[INFO] done.'
.PHONY: test-windows
test-windows:
go test -short ./plugins/inputs/ping/...
go test -short ./plugins/inputs/win_perf_counters/...
@ -71,8 +75,7 @@ test-windows:
go test -short ./plugins/inputs/procstat/...
go test -short ./plugins/inputs/ntpq/...
# vet runs the Go source code static analysis tool `vet` to find
# any common errors.
.PHONY: vet
vet:
@echo 'go vet $$(go list ./... | grep -v ./plugins/parsers/influx)'
@go vet $$(go list ./... | grep -v ./plugins/parsers/influx) ; if [ $$? -ne 0 ]; then \
@ -82,19 +85,33 @@ vet:
exit 1; \
fi
test-ci: fmtcheck vet
go test -short ./...
.PHONY: check
check: fmtcheck vet
.PHONY: test-all
test-all: fmtcheck vet
go test ./...
.PHONY: package
package:
./scripts/build.py --package --platform=all --arch=all
.PHONY: package-release
package-release:
./scripts/build.py --release --package --platform=all --arch=all \
--upload --bucket=dl.influxdata.com/telegraf/releases
.PHONY: package-nightly
package-nightly:
./scripts/build.py --nightly --package --platform=all --arch=all \
--upload --bucket=dl.influxdata.com/telegraf/nightlies
.PHONY: clean
clean:
rm -f telegraf
rm -f telegraf.exe
.PHONY: docker-image
docker-image:
./scripts/build.py --package --platform=linux --arch=amd64
cp build/telegraf*$(COMMIT)*.deb .
@ -103,6 +120,7 @@ docker-image:
plugins/parsers/influx/machine.go: plugins/parsers/influx/machine.go.rl
ragel -Z -G2 $^ -o $@
.PHONY: static
static:
@echo "Building static linux binary..."
@CGO_ENABLED=0 \
@ -110,8 +128,17 @@ static:
GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
.PHONY: plugin-%
plugin-%:
@echo "Starting dev environment for $${$(@)} input plugin..."
@docker-compose -f plugins/inputs/$${$(@)}/dev/docker-compose.yml up
.PHONY: deps telegraf install test test-windows lint vet test-all package clean docker-image fmtcheck uint64 static
.PHONY: ci-1.10
ci-1.10:
docker build -t quay.io/influxdb/telegraf-ci:1.10.3 - < scripts/ci-1.10.docker
docker push quay.io/influxdb/telegraf-ci:1.10.3
.PHONY: ci-1.9
ci-1.9:
docker build -t quay.io/influxdb/telegraf-ci:1.9.7 - < scripts/ci-1.9.docker
docker push quay.io/influxdb/telegraf-ci:1.9.7

View File

@ -42,14 +42,17 @@ Ansible role: https://github.com/rossmcdonald/telegraf
Telegraf requires golang version 1.9 or newer, the Makefile requires GNU make.
Dependencies are managed with [dep](https://github.com/golang/dep),
which is installed by the Makefile if you don't have it already.
1. [Install Go](https://golang.org/doc/install)
2. [Setup your GOPATH](https://golang.org/doc/code.html#GOPATH)
3. Run `go get -d github.com/influxdata/telegraf`
4. Run `cd $GOPATH/src/github.com/influxdata/telegraf`
5. Run `make`
1. [Install Go](https://golang.org/doc/install) >=1.9
2. [Install dep](https://golang.github.io/dep/docs/installation.html) ==v0.4.1
3. Download Telegraf source:
```
go get -d github.com/influxdata/telegraf
```
4. Run make from the source directory
```
cd "$HOME/go/src/github.com/influxdata/telegraf"
make
```
### Nightly Builds

View File

@ -12,22 +12,27 @@ platform: x64
install:
- IF NOT EXIST "C:\Cache" mkdir C:\Cache
- IF NOT EXIST "C:\Cache\go1.10.1.msi" curl -o "C:\Cache\go1.10.1.msi" https://storage.googleapis.com/golang/go1.10.1.windows-amd64.msi
- IF NOT EXIST "C:\Cache\go1.10.3.msi" curl -o "C:\Cache\go1.10.3.msi" https://storage.googleapis.com/golang/go1.10.3.windows-amd64.msi
- IF NOT EXIST "C:\Cache\gnuwin32-bin.zip" curl -o "C:\Cache\gnuwin32-bin.zip" https://dl.influxdata.com/telegraf/ci/make-3.81-bin.zip
- IF NOT EXIST "C:\Cache\gnuwin32-dep.zip" curl -o "C:\Cache\gnuwin32-dep.zip" https://dl.influxdata.com/telegraf/ci/make-3.81-dep.zip
- IF EXIST "C:\Go" rmdir /S /Q C:\Go
- msiexec.exe /i "C:\Cache\go1.10.1.msi" /quiet
- msiexec.exe /i "C:\Cache\go1.10.3.msi" /quiet
- 7z x "C:\Cache\gnuwin32-bin.zip" -oC:\GnuWin32 -y
- 7z x "C:\Cache\gnuwin32-dep.zip" -oC:\GnuWin32 -y
- go get -d github.com/golang/dep
- cd "%GOPATH%\src\github.com\golang\dep"
- git checkout -q v0.4.1
- go install -ldflags="-X main.version=v0.4.1" ./cmd/dep
- cd "%GOPATH%\src\github.com\influxdata\telegraf"
- git config --system core.longpaths true
- go version
- go env
- git config --system core.longpaths true
build_script:
- cmd: C:\GnuWin32\bin\make deps
- cmd: C:\GnuWin32\bin\make telegraf
- cmd: C:\GnuWin32\bin\make
test_script:
- cmd: C:\GnuWin32\bin\make check
- cmd: C:\GnuWin32\bin\make test-windows
artifacts:

View File

@ -5,12 +5,13 @@ package win_services
import (
"errors"
"fmt"
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/mgr"
"testing"
)
//testData is DD wrapper for unit testing of WinServices
@ -84,14 +85,31 @@ func (m *FakeWinSvc) Config() (mgr.Config, error) {
if m.testData.serviceConfigError != nil {
return mgr.Config{}, m.testData.serviceConfigError
} else {
return mgr.Config{0, uint32(m.testData.startUpMode), 0, "", "", 0, nil, m.testData.serviceName, m.testData.displayName, "", ""}, nil
return mgr.Config{
ServiceType: 0,
StartType: uint32(m.testData.startUpMode),
ErrorControl: 0,
BinaryPathName: "",
LoadOrderGroup: "",
TagId: 0,
Dependencies: nil,
ServiceStartName: m.testData.serviceName,
DisplayName: m.testData.displayName,
Password: "",
Description: "",
}, nil
}
}
func (m *FakeWinSvc) Query() (svc.Status, error) {
if m.testData.serviceQueryError != nil {
return svc.Status{}, m.testData.serviceQueryError
} else {
return svc.Status{svc.State(m.testData.state), 0, 0, 0}, nil
return svc.Status{
State: svc.State(m.testData.state),
Accepts: 0,
CheckPoint: 0,
WaitHint: 0,
}, nil
}
}

View File

@ -155,12 +155,8 @@ def go_get(branch, update=False, no_uncommitted=False):
if local_changes() and no_uncommitted:
logging.error("There are uncommitted changes in the current directory.")
return False
if not check_path_for("dep"):
logging.info("Downloading `dep`...")
get_command = "go get -u github.com/golang/dep/cmd/dep"
run(get_command)
logging.info("Retrieving dependencies with `dep`...")
run("{}/bin/dep ensure -v".format(os.environ.get("GOPATH",
run("{}/bin/dep ensure -v -vendor-only".format(os.environ.get("GOPATH",
os.path.expanduser("~/go"))))
return True

28
scripts/ci-1.10.docker Normal file
View File

@ -0,0 +1,28 @@
FROM golang:1.10.3
RUN chmod -R 755 "$GOPATH"
RUN DEBIAN_FRONTEND=noninteractive \
apt update && apt install -y --no-install-recommends \
autoconf \
git \
libtool \
locales \
make \
python-boto \
rpm \
ruby \
ruby-dev \
zip && \
rm -rf /var/lib/apt/lists/*
RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN locale-gen C.UTF-8 || true
ENV LANG=C.UTF-8
RUN gem install fpm
RUN go get -d github.com/golang/dep && \
cd src/github.com/golang/dep && \
git checkout -q v0.4.1 && \
go install -ldflags="-X main.version=v0.4.1" ./cmd/dep

28
scripts/ci-1.9.docker Normal file
View File

@ -0,0 +1,28 @@
FROM golang:1.9.7
RUN chmod -R 755 "$GOPATH"
RUN DEBIAN_FRONTEND=noninteractive \
apt update && apt install -y --no-install-recommends \
autoconf \
git \
libtool \
locales \
make \
python-boto \
rpm \
ruby \
ruby-dev \
zip && \
rm -rf /var/lib/apt/lists/*
RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN locale-gen C.UTF-8 || true
ENV LANG=C.UTF-8
RUN gem install fpm
RUN go get -d github.com/golang/dep && \
cd src/github.com/golang/dep && \
git checkout -q v0.4.1 && \
go install -ldflags="-X main.version=v0.4.1" ./cmd/dep

View File

@ -1,35 +0,0 @@
#!/bin/bash
ARTIFACT_DIR='artifacts'
run()
{
"$@"
ret=$?
if [[ $ret -eq 0 ]]
then
echo "[INFO] [ $@ ]"
else
echo "[ERROR] [ $@ ] returned $ret"
exit $ret
fi
}
run make
run mkdir -p ${ARTIFACT_DIR}
run gzip telegraf -c > "$ARTIFACT_DIR/telegraf.gz"
# RPM is used to build packages for Enterprise Linux hosts.
# Boto is used to upload packages to S3.
run sudo apt-get update
run sudo apt-get install -y rpm python-boto ruby ruby-dev autoconf libtool
run sudo gem install fpm
if git describe --exact-match HEAD 2>&1 >/dev/null; then
run ./scripts/build.py --release --package --platform=all --arch=all --upload --bucket=dl.influxdata.com/telegraf/releases
elif [ "${CIRCLE_STAGE}" = nightly ]; then
run ./scripts/build.py --nightly --package --platform=all --arch=all --upload --bucket=dl.influxdata.com/telegraf/nightlies
else
run ./scripts/build.py --package --platform=all --arch=all
fi
run mv build $ARTIFACT_DIR