Skip to content

Commit

Permalink
Build pipeline and image (#1)
Browse files Browse the repository at this point in the history
* added initial pipeline

* improve(codebase) dependencies tracking and local build environment

* improve(pipeline) support docker publishing

* improve(docker) adjusted base to stretch
  • Loading branch information
Voronenko authored May 27, 2019
1 parent 627f0a5 commit 3cbac56
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.go
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.go
.idea
/trafficmirror
vendor
trafficmirror
50 changes: 50 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
variables:
GL_URL: github.com/rb3ckers
GO_PROJECT_NAMESPACE: trafficmirror
IMAGE_FAMILY: voronenko/trafficmirror
CI_REGISTRY: docker.io

.prep_go: &prep_go
before_script:
# - export GL_URL=$(echo ${CI_PROJECT_URL:-https://github.com/rb3ckers/trafficmirror} | awk -F/ '{print $3}')
- 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
# - taglatest

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:
# - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
- 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}
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM debian:stretch

ADD build/trafficmirror /trafficmirror

CMD ["trafficmirror"]

EXPOSE 8080
17 changes: 17 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/sony/gobreaker"
version = "0.4.0"

[prune]
go-tests = true
unused-packages = true
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions build-env.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3cbac56

Please sign in to comment.