diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5da2aba --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.go diff --git a/.gitignore b/.gitignore index 75761fb..ec87029 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +.go +.idea /trafficmirror +vendor +trafficmirror diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..d0277da --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,47 @@ +variables: + GL_URL: github.com/rb3ckers + GO_PROJECT_NAMESPACE: trafficmirror + IMAGE_FAMILY: stackstate/trafficmirror + CI_REGISTRY: docker.io + +.prep_go: &prep_go + before_script: + - echo export GO_PROJECT_PATH="$GOPATH/src/$GL_URL/$GO_PROJECT_NAMESPACE" + - export GO_PROJECT_PATH="$GOPATH/src/$GL_URL/$GO_PROJECT_NAMESPACE" + - rm -rf $GOPATH/src/$GL_URL + - mkdir -p $GOPATH/src/$GL_URL + - echo ln -s $(pwd) $GO_PROJECT_PATH + - ln -s $(pwd) $GO_PROJECT_PATH + - cd $GO_PROJECT_PATH + +stages: + - build + - docker_build + +go_build: + <<: *prep_go + stage: build + image: golang:1.11 + script: + - go get github.com/golang/dep/cmd/dep + - dep ensure + - mkdir -p build + - env GOOS=linux GOARCH=amd64 go build -o build/trafficmirror + - ls -la $GO_PROJECT_PATH/ + artifacts: + paths: + - build + expire_in: 1 week + +docker_build: + stage: docker_build + image: docker:latest + dependencies: + - go_build + services: + - docker:dind + script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + - docker build -t $IMAGE_FAMILY:${CI_COMMIT_TAG:-dirty} . + - echo docker push $IMAGE_FAMILY:${CI_COMMIT_TAG:-dirty} + - docker push $IMAGE_FAMILY:${CI_COMMIT_TAG:-dirty} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1201dc3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM debian:stretch + +ADD build/trafficmirror /trafficmirror +ADD ./init.sh /init +RUN chmod +x /init + +CMD ["/init"] + +EXPOSE 8080 diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..a89bb45 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,17 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:d3ffbc45dfe6929a4ba313464c2d761d96325d306eda29512da56c034db2a4dd" + name = "github.com/sony/gobreaker" + packages = ["."] + pruneopts = "UT" + revision = "b2a34562d02c4d5fd6645399c69e00141fb24e5a" + version = "0.4.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = ["github.com/sony/gobreaker"] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..6538be0 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,8 @@ + +[[constraint]] + name = "github.com/sony/gobreaker" + version = "0.4.0" + +[prune] + go-tests = true + unused-packages = true diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0761c89 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +SHELL := /bin/bash + +clean: + rm -rf build + +build: + source build-env.sh && \ + cd $(GO_PROJECT_PATH) && \ + dep ensure && \ + mkdir -p build && \ + GOOS=linux GOARCH=amd64 go build -o build/trafficmirror diff --git a/build-env.sh b/build-env.sh new file mode 100644 index 0000000..5cd18a5 --- /dev/null +++ b/build-env.sh @@ -0,0 +1,12 @@ +# use with source +export GL_URL=github.com/rb3ckers +export GO_PROJECT_NAMESPACE=trafficmirror +if [ ! -d $(pwd)/.go ] +then +mkdir -p $(pwd)/.go/src/$GL_URL +ln -s $(pwd) $(pwd)/.go/src/$GL_URL/$GO_PROJECT_NAMESPACE +fi +export GOPATH=$(pwd)/.go +export GOBIN=$GOPATH/bin +export PATH=$GOBIN:$PATH +export GO_PROJECT_PATH=$(pwd)/.go/src/$GL_URL/$GO_PROJECT_NAMESPACE diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..45b048a --- /dev/null +++ b/init.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +LISTEN_PORT=${LISTEN_PORT:-7077} +MAIN=${MAIN:-localhost:8888} +EXTRA_PARAMS=$1 + +echo /trafficmirror /trafficmirror -listen ":${LISTEN_PORT}" -main=${MAIN} $EXTRA_PARAMS +/trafficmirror -listen ":${LISTEN_PORT}" -main=${MAIN} $EXTRA_PARAMS