Skip to content

Commit

Permalink
Merge pull request #35 from cloudflare/version3-merge
Browse files Browse the repository at this point in the history
Version 3
  • Loading branch information
lspgn authored Aug 7, 2019
2 parents f5dccb5 + 1de649b commit 5351f6c
Show file tree
Hide file tree
Showing 37 changed files with 2,387 additions and 1,306 deletions.
42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
17 changes: 6 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
ARG src_dir="/go/src/github.com/cloudflare/goflow"

FROM golang:alpine as builder
ARG src_dir
ARG LDFLAGS=""

RUN apk --update --no-cache add git && \
mkdir -p ${src_dir}
RUN apk --update --no-cache add git build-base gcc

WORKDIR ${src_dir}
COPY . .
COPY . /build
WORKDIR /build

RUN go get -u github.com/golang/dep/cmd/dep && \
dep ensure && \
go build
RUN go build -ldflags "${LDFLAGS}" -o goflow cmd/goflow/goflow.go

FROM alpine:latest
ARG src_dir

RUN apk update --no-cache && \
adduser -S -D -H -h / flow
USER flow
COPY --from=builder ${src_dir}/goflow /
COPY --from=builder /build/goflow /

ENTRYPOINT ["./goflow"]
46 changes: 0 additions & 46 deletions Gopkg.toml

This file was deleted.

92 changes: 90 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,92 @@
EXTENSION ?=
DIST_DIR ?= dist/
GOOS ?= linux
ARCH ?= $(shell uname -m)
BUILDINFOSDET ?=

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)'

OUTPUT_GOFLOW := $(DIST_DIR)goflow-$(GOFLOW_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)

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: all
all: test-race vet test

.PHONY: proto
proto:
@echo generating protobuf
protoc --go_out=. --plugin=$(PROTOCPATH)protoc-gen-go pb/*.proto

.PHONY: test
test:
@echo testing code
go test ./...

.PHONY: vet
vet:
@echo checking code is vetted
go vet $(shell go list ./...)

.PHONY: test-race
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

proto:
protoc $$PROTO_PATH --go_out=. pb/flow.proto
.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
Loading

0 comments on commit 5351f6c

Please sign in to comment.