Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
lspgn committed May 26, 2021
0 parents commit e4bacbc
Show file tree
Hide file tree
Showing 63 changed files with 12,636 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14

- name: Check out code into the Go module directory
uses: actions/checkout@v1
# note: @v2 seem to be https://github.com/actions/checkout/issues/290
# which only works IF the tags are pushed before/same time as the commit
# otherwise, display previous tag
with:
fetch-depth: 0

- name: Test & Vet
run: make test vet

- name: Build
run: |
GOOS=linux make build
GOOS=darwin make build
GOOS=windows EXTENSION=.exe make build
- name: Install fpm
run: |
sudo apt-get update
sudo apt-get install -y rpm ruby ruby-dev
sudo gem install fpm
- name: Package
run: make package-deb package-rpm

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/*
retention-days: 14
40 changes: 40 additions & 0 deletions .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: DockerRelease

on:
push:
tags:
- 'v*'

jobs:
build:
name: DockerRelease
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14

- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build
run: |
export VERSION=$(git describe --tags --abbrev=0 HEAD)
make docker
make push-docker-release
38 changes: 38 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Docker

on:
push:
branches: [ main ]

jobs:
build:
name: Docker
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14

- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build
run: |
make docker
make push-docker
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
build:
name: Release
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14

- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Install fpm
run: |
sudo apt-get update
sudo apt-get install -y rpm ruby ruby-dev
sudo gem install fpm
- name: Build
run: |
export VERSION=$(git describe --tags --abbrev=0 HEAD)
GOOS=linux make build
GOOS=darwin make build
GOOS=windows EXTENSION=.exe make build
make package-deb package-rpm
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/github-script@v2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs').promises;
const upload_url = '${{ steps.create_release.outputs.upload_url }}';
for (let file of await fs.readdir('./dist')) {
console.log('uploading', file);
await github.repos.uploadReleaseAsset({
url: upload_url,
name: file,
data: await fs.readFile(`./dist/${file}`)
});
}
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM golang:alpine as builder
ARG LDFLAGS=""

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

COPY . /build
WORKDIR /build

RUN go build -ldflags "${LDFLAGS}" -o goflow2 cmd/goflow2/main.go

FROM alpine:latest
ARG src_dir
ARG VERSION=""
ARG CREATED=""
ARG DESCRIPTION=""
ARG NAME=""
ARG MAINTAINER=""
ARG URL=""
ARG LICENSE=""
ARG REV=""

LABEL org.opencontainers.image.created="${CREATED}"
LABEL org.opencontainers.image.authors="${MAINTAINER}"
LABEL org.opencontainers.image.url="${URL}"
LABEL org.opencontainers.image.title="${NAME}"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.description="${DESCRIPTION}"
LABEL org.opencontainers.image.licenses="${LICENSE}"
LABEL org.opencontainers.image.revision="${REV}"

RUN apk update --no-cache && \
adduser -S -D -H -h / flow
USER flow
COPY --from=builder /build/goflow2 /

ENTRYPOINT ["./goflow2"]
100 changes: 100 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
EXTENSION ?=
DIST_DIR ?= dist/
GOOS ?= linux
ARCH ?= $(shell uname -m)
BUILDINFOSDET ?=

DOCKER_REPO := netsampler/
NAME := goflow2
VERSION ?= $(shell git describe --abbrev --long HEAD)
ABBREV ?= $(shell git rev-parse --short HEAD)
COMMIT ?= $(shell git rev-parse HEAD)
TAG ?= $(shell git describe --tags --abbrev=0 HEAD)
VERSION_PKG ?= $(shell echo $(VERSION) | sed 's/^v//g')
ARCH := x86_64
LICENSE := BSD-3-Clause
URL := https://github.com/netsampler/goflow2
DESCRIPTION := GoFlow2: Open-Source and Scalable Network Sample Collector
DATE := $(shell date +%FT%T%z)
BUILDINFOS ?= ($(DATE)$(BUILDINFOSDET))
LDFLAGS ?= '-X main.version=$(VERSION) -X main.buildinfos=$(BUILDINFOS)'
MAINTAINER := [email protected]

OUTPUT := $(DIST_DIR)goflow2-$(VERSION_PKG)-$(GOOS)-$(ARCH)$(EXTENSION)

.PHONY: proto
proto:
@echo generating protobuf
protoc --go_out=. pb/*.proto
protoc --go_out=. cmd/enricher/pb/*.proto

.PHONY: vet
vet:
go vet cmd/goflow2/main.go

.PHONY: test
test:
go test -v ./...

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

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

.PHONY: build
build: prepare
go build -ldflags $(LDFLAGS) -o $(OUTPUT) cmd/goflow2/main.go

.PHONY: docker
docker:
docker build \
--build-arg LDFLAGS=$(LDFLAGS) \
--build-arg CREATED="$(DATE)" \
--build-arg MAINTAINER="$(MAINTAINER)" \
--build-arg URL="$(URL)" \
--build-arg NAME="$(NAME)" \
--build-arg DESCRIPTION="$(DESCRIPTION)" \
--build-arg LICENSE="$(LICENSE)" \
--build-arg VERSION="$(VERSION)" \
--build-arg REV="$(COMMIT)" \
-t $(DOCKER_REPO)$(NAME):$(ABBREV) .

.PHONY: push-docker
push-docker:
docker push $(DOCKER_REPO)$(NAME):$(ABBREV)
docker tag $(DOCKER_REPO)$(NAME):$(ABBREV) $(DOCKER_REPO)$(NAME):latest
docker push $(DOCKER_REPO)$(NAME):latest

.PHONY: push-docker-release
push-docker-release:
docker tag $(DOCKER_REPO)$(NAME):$(ABBREV) $(DOCKER_REPO)$(NAME):$(VERSION)
docker push $(DOCKER_REPO)$(NAME):$(VERSION)

.PHONY: package-deb
package-deb: prepare
fpm -s dir -t deb -n $(NAME) -v $(VERSION_PKG) \
--maintainer "$(MAINTAINER)" \
--description "$(DESCRIPTION)" \
--url "$(URL)" \
--architecture $(ARCH) \
--license "$(LICENSE)" \
--package $(DIST_DIR) \
$(OUTPUT)=/usr/bin/goflow2 \
package/goflow2.service=/lib/systemd/system/goflow2.service \
package/goflow2.env=/etc/default/goflow2

.PHONY: package-rpm
package-rpm: prepare
fpm -s dir -t rpm -n $(NAME) -v $(VERSION_PKG) \
--maintainer "$(MAINTAINER)" \
--description "$(DESCRIPTION)" \
--url "$(URL)" \
--architecture $(ARCH) \
--license "$(LICENSE) "\
--package $(DIST_DIR) \
$(OUTPUT)=/usr/bin/goflow2 \
package/goflow2.service=/lib/systemd/system/goflow2.service \
package/goflow2.env=/etc/default/goflow2
Loading

0 comments on commit e4bacbc

Please sign in to comment.