Skip to content

Commit

Permalink
Travis integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lspgn committed Aug 7, 2019
1 parent 2c9c0a6 commit 1de649b
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 43 deletions.
57 changes: 42 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
language: go
go_import_path: github.com/cloudflare/goflow
go:
- 1.12.x

script:
- GO111MODULE=on make

notifications:
email:
recipients:
- [email protected]
on_success: never
on_failure: change

jobs:
include:
# Test
- stage: test
os: linux
language: go
env:
GO111MODULE=on
script:
- make test-race vet test
# Compile
- stage: compile
os: linux
language: go
env:
GO111MODULE=on
BUILDINFOSDET=-travis
before_install:
- sudo apt-get update
- sudo apt-get install -y rpm ruby ruby-dev
- sudo gem install fpm
script:
- GOOS=linux make build-goflow-light
- GOOS=linux make build-goflow
- GOOS=darwin make build-goflow
- GOOS=windows EXTENSION=.exe make build-goflow
- make package-deb-goflow package-rpm-goflow
deploy:
provider: releases
api_key:
secure: eg1OSNzXVSVsCx/n7xSJAtAw7NlgtnK57EyJmrwGgvcs5OUm5cvsnK3isuWwsAFanW6b69UoyyZDayIj72poiTVGo5705lL1sN39LxypmlkpmOFJaMggIdbPAN4fB6anRHp+MBGMvxGjeJP/97JKnPXcyK+QevqxRl2sMFRjLthTBManET7ahAhD5HqsdT/MeFORCymlJ+sIRXkLHrtBdiW/KXLLzsKn3C4/OPP3Z08ggqDix7I3zLaHW7nAvug3h5V5I84FiedEgO+w7McMjX8ri2Fz/sXNz3AaQIgBUxkmnIEvv4b9nFkd3HjIHRyS6iPpcdrqGXcMqW2SVHOJ668t140MLKrZyoCj4yi0UzqjY5F6iBCy5GSz8TBbz1Mo7TF6ieVeAaC0WZImO1aRHQeBNY/5NjvmwCXLDq7sUyxcHbfSa39/Pn6sD5yZkNsSEpTJ9AHxo2/os4NxQJ6l4nV/vseNDUnhcLf3irCBpsv1k1q6EgAO4kCdELSDMaYasZm2p4U9PDiGP1tyxWoglQKzma0sR1FGnOpUQB1Wl6ZWeW4IotHLb6QQRLfERPueWgENi2etDs88lLY1EuCamFoY19nWXROCiUEYFthK6csapgQw7y4hIcup2/gB0eNVoWbGB16MYQD2W47gj6LUGDSQMAjXffymugde71R46JQ=
file_glob: true
file: dist/*
skip_cleanup: true
on:
tags: true
repo: cloudflare/goflow
- dist: trusty
services:
- docker
script:
- make docker-goflow
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM golang:alpine as builder
ARG VERSION=""
ARG LDFLAGS=""

RUN apk --update --no-cache add git build-base gcc

COPY . /build
WORKDIR /build

RUN go build -ldflags "-X main.version=${VERSION}" -o goflow cmd/goflow/goflow.go
RUN go build -ldflags "${LDFLAGS}" -o goflow cmd/goflow/goflow.go

FROM alpine:latest
ARG src_dir
Expand Down
88 changes: 66 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
IMAGE ?= cloudflare/goflow
VERSION ?= $(shell git describe --tags --always --dirty)
VERSION_DOCKER ?= $(shell git describe --tags --abbrev=0 --always --dirty)

EXTENSION ?=
DIST_DIR ?= dist/
GOOS ?= linux
ARCH ?= $(shell uname -m)
BUILDINFOSDET ?=

.PHONY: all
all: test-race vet test
DOCKER_REPO := cloudflare/
GOFLOW_NAME := goflow
GOFLOW_VERSION := $(shell git describe --tags $(git rev-list --tags --max-count=1))
VERSION_PKG := $(shell echo $(GOFLOW_VERSION) | sed 's/^v//g')
ARCH := x86_64
LICENSE := BSD-3
URL := https://github.com/cloudflare/goflow
DESCRIPTION := GoFlow: an sFlow/IPFIX/NetFlow v9/v5 collector to Kafka
BUILDINFOS := ($(shell date +%FT%T%z)$(BUILDINFOSDET))
LDFLAGS := '-X main.version=$(GOFLOW_VERSION) -X main.buildinfos=$(BUILDINFOS)'

.PHONY: clean
clean:
rm -rf bin
OUTPUT_GOFLOW := $(DIST_DIR)goflow-$(GOFLOW_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)

.PHONY: build
build:
@echo compiling code
mkdir bin
GOOS=$(GOOS) go build -ldflags '-X main.version=$(VERSION)' -o bin/goflow-$(GOOS)-$(ARCH) cmd/goflow/goflow.go
GOOS=$(GOOS) go build -ldflags '-X main.version=$(VERSION)' -o bin/goflow-sflow-$(GOOS)-$(ARCH) cmd/csflow/csflow.go
GOOS=$(GOOS) go build -ldflags '-X main.version=$(VERSION)' -o bin/goflow-netflow-$(GOOS)-$(ARCH) cmd/cnetflow/cnetflow.go
GOOS=$(GOOS) go build -ldflags '-X main.version=$(VERSION)' -o bin/goflow-nflegacy-$(GOOS)-$(ARCH) cmd/cnflegacy/cnflegacy.go
OUTPUT_GOFLOW_LIGHT_SFLOW := $(DIST_DIR)goflow-sflow-$(GOFLOW_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)
OUTPUT_GOFLOW_LIGHT_NF := $(DIST_DIR)goflow-netflow-$(GOFLOW_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)
OUTPUT_GOFLOW_LIGHT_NFV5 := $(DIST_DIR)goflow-nflegacy-$(GOFLOW_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)


.PHONY: container
container:
@echo build docker container
docker build --build-arg VERSION=$(VERSION) -t $(IMAGE):$(VERSION_DOCKER) .
.PHONY: all
all: test-race vet test

.PHONY: proto
proto:
Expand All @@ -46,3 +43,50 @@ vet:
test-race:
@echo testing code for races
go test -race ./...

.PHONY: prepare
prepare:
mkdir -p $(DIST_DIR)

.PHONY: clean
clean:
rm -rf $(DIST_DIR)

.PHONY: build-goflow
build-goflow: prepare
go build -ldflags $(LDFLAGS) -o $(OUTPUT_GOFLOW) cmd/goflow/goflow.go

.PHONY: build-goflow-light
build-goflow-light: prepare
go build -ldflags $(LDFLAGS) -o $(OUTPUT_GOFLOW_LIGHT_SFLOW) cmd/csflow/csflow.go
go build -ldflags $(LDFLAGS) -o $(OUTPUT_GOFLOW_LIGHT_NF) cmd/cnetflow/cnetflow.go
go build -ldflags $(LDFLAGS) -o $(OUTPUT_GOFLOW_LIGHT_NFV5) cmd/cnflegacy/cnflegacy.go

.PHONY: docker-goflow
docker-goflow:
docker build -t $(DOCKER_REPO)$(GOFLOW_NAME):$(GOFLOW_VERSION) --build-arg LDFLAGS=$(LDFLAGS) -f Dockerfile .

.PHONY: package-deb-goflow
package-deb-goflow: prepare
fpm -s dir -t deb -n $(GOFLOW_NAME) -v $(VERSION_PKG) \
--description "$(DESCRIPTION)" \
--url "$(URL)" \
--architecture $(ARCH) \
--license "$(LICENSE)" \
--deb-no-default-config-files \
--package $(DIST_DIR) \
$(OUTPUT_GOFLOW)=/usr/bin/goflow \
package/goflow.service=/lib/systemd/system/goflow.service \
package/goflow.env=/etc/default/goflow

.PHONY: package-rpm-goflow
package-rpm-goflow: prepare
fpm -s dir -t rpm -n $(GOFLOW_NAME) -v $(VERSION_PKG) \
--description "$(DESCRIPTION)" \
--url "$(URL)" \
--architecture $(ARCH) \
--license "$(LICENSE) "\
--package $(DIST_DIR) \
$(OUTPUT_GOFLOW)=/usr/bin/goflow \
package/goflow.service=/lib/systemd/system/goflow.service \
package/goflow.env=/etc/default/goflow
3 changes: 2 additions & 1 deletion cmd/cnetflow/cnetflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

var (
version = ""
AppVersion = "GoFlow NetFlow " + version
buildinfos = ""
AppVersion = "GoFlow NetFlow " + version + " " + buildinfos

Addr = flag.String("addr", "", "NetFlow/IPFIX listening address")
Port = flag.Int("port", 2055, "NetFlow/IPFIX listening port")
Expand Down
3 changes: 2 additions & 1 deletion cmd/cnflegacy/cnflegacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

var (
version = ""
AppVersion = "GoFlow NetFlowv5 " + version
buildinfos = ""
AppVersion = "GoFlow NetFlowV5 " + version + " " + buildinfos

Addr = flag.String("addr", "", "NetFlow v5 listening address")
Port = flag.Int("port", 2055, "NetFlow v5 listening port")
Expand Down
3 changes: 2 additions & 1 deletion cmd/csflow/csflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

var (
version = ""
AppVersion = "GoFlow sFlow " + version
buildinfos = ""
AppVersion = "GoFlow sFlow " + version + " " + buildinfos

Addr = flag.String("addr", "", "sFlow listening address")
Port = flag.Int("port", 6343, "sFlow listening port")
Expand Down
3 changes: 2 additions & 1 deletion cmd/goflow/goflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (

var (
version = ""
AppVersion = "GoFlow " + version
buildinfos = ""
AppVersion = "GoFlow " + version + " " + buildinfos

SFlowEnable = flag.Bool("sflow", true, "Enable sFlow")
SFlowAddr = flag.String("sflow.addr", "", "sFlow listening address")
Expand Down
11 changes: 11 additions & 0 deletions docker-compose-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'
services:
packager:
build: package
entrypoint: make
command:
- build-goflow
- package-deb-goflow
- package-rpm-goflow
volumes:
- ./:/work/
9 changes: 9 additions & 0 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ruby

RUN apt-get update && \
apt-get install -y git make rpm golang && \
gem install fpm

WORKDIR /work

ENTRYPOINT [ "/bin/bash" ]
1 change: 1 addition & 0 deletions package/goflow.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GOFLOW_ARGS=
11 changes: 11 additions & 0 deletions package/goflow.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=GoFlow
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/default/goflow
ExecStart=/usr/bin/goflow $GOFLOW_ARGS

[Install]
WantedBy=multi-user.target

0 comments on commit 1de649b

Please sign in to comment.