diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..fe11b42 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,82 @@ +version: 2.1 + +executors: + go: + docker: + - image: circleci/golang:latest + working_directory: ~/repo + +workflows: + version: 2 + ci: + jobs: + - checkout + - linting + requires: + - checkout + - testing + requires: + - checkout + - building + requires: + - testing + - linting + - building + requires: + - publishing + - publishing + requires: + - building +jobs: + checkout: + executor: go + steps: + - checkout + - persist_to_workspace: + paths: + - . + root: ~/repo + linting: + executor: go + steps: + - attach_workspace: + at: . + - run: go build . + - run: go get -u golang.org/x/lint/golint + - run: golint ./... + testing: + executor: go + steps: + - attach_workspace: + at: . + - run: go build ./... + - run: go test ./... + +# version: 2 +# jobs: +# build: +# docker: +# - image: v2tec/gobuilder:0.5.0_go1.7.4-glide0.12.3-goreleaser0.59.0-docker17.05.0 +# working_directory: /src +# steps: +# - checkout +# - setup_remote_docker: +# version: 17.05.0-ce +# - run: git fetch --tags +# - run: | +# docker login -u $DOCKER_USER -p $DOCKER_PASS +# IS_RELEASE=$(if [ "$CIRCLE_TAG" != "" ] ; then echo release; else echo ci; fi;) +# /build.sh $IS_RELEASE || exit 1 +# chmod 755 /src/dockerfile/push_containers.sh +# if [ "$CIRCLE_TAG" != "" ] ; then /src/dockerfile/push_containers.sh $CIRCLE_TAG; fi; + +# - store_artifacts: +# path: /src/dist/ +# workflows: +# version: 2 +# build-deploy: +# jobs: +# - build: +# filters: +# tags: +# only: /.*/ \ No newline at end of file diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 6cbcc39..0000000 --- a/circle.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: v2tec/gobuilder:0.5.0_go1.7.4-glide0.12.3-goreleaser0.59.0-docker17.05.0 - working_directory: /src - steps: - - checkout - - setup_remote_docker: - version: 17.05.0-ce - - run: git fetch --tags - - run: | - docker login -u $DOCKER_USER -p $DOCKER_PASS - IS_RELEASE=$(if [ "$CIRCLE_TAG" != "" ] ; then echo release; else echo ci; fi;) - /build.sh $IS_RELEASE || exit 1 - chmod 755 /src/dockerfile/push_containers.sh - if [ "$CIRCLE_TAG" != "" ] ; then /src/dockerfile/push_containers.sh $CIRCLE_TAG; fi; - - - store_artifacts: - path: /src/dist/ -workflows: - version: 2 - build-deploy: - jobs: - - build: - filters: - tags: - only: /.*/ \ No newline at end of file diff --git a/dockerfile/build/Dockerfile b/dockerfile/build/Dockerfile new file mode 100644 index 0000000..a887634 --- /dev/null +++ b/dockerfile/build/Dockerfile @@ -0,0 +1,54 @@ +FROM golang:1.7.4 +MAINTAINER Fabrizio Steiner + +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION + +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/stffabi/docker-gobuilder" \ + org.label-schema.version="$VERSION" \ + org.label-schema.schema-version="1.0" + +ARG glide=0.12.3 +ARG goreleaser=0.59.0 +ARG docker=17.05.0-ce + +# Install glide binary +RUN curl --silent --show-error --fail --location \ + --header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \ + "https://github.com/Masterminds/glide/releases/download/v${glide}/glide-v${glide}-linux-amd64.tar.gz" \ + | tar --no-same-owner -xz linux-amd64/glide -O > /usr/bin/glide \ + && chmod 0755 /usr/bin/glide \ + && /usr/bin/glide -v + +# Install goreleaser binary +RUN curl --silent --show-error --fail --location \ + --header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \ + "https://github.com/goreleaser/goreleaser/releases/download/v${goreleaser}/goreleaser_Linux_x86_64.tar.gz" \ + | tar --no-same-owner -C /usr/bin/ -xz goreleaser \ + && chmod 0755 /usr/bin/goreleaser \ + && /usr/bin/goreleaser -v + +# Install docker binary +RUN mkdir -p /tmp \ + && curl --silent --show-error --fail --location \ + --header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \ + "https://get.docker.com/builds/Linux/x86_64/docker-${docker}.tgz" \ + | tar -xz -C /tmp \ + && mv /tmp/docker/* /usr/bin \ + && rm -rf /tmp \ + && chmod 0755 /usr/bin/docker \ + && chmod 0755 /usr/bin/docker* \ + && /usr/bin/docker -v + +VOLUME /src +WORKDIR /src + +COPY build_environment.sh / +COPY build.sh / + +RUN chmod 0755 /*.sh + +ENTRYPOINT ["/build.sh"] \ No newline at end of file diff --git a/dockerfile/build/build.sh b/dockerfile/build/build.sh new file mode 100644 index 0000000..8a09b5a --- /dev/null +++ b/dockerfile/build/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash -e + +if [ -z "$1" ] +then + echo "No argument supplied, please either supply 'release' for a release build or 'ci' for ci build." + exit 1 +fi + +source /build_environment.sh + +# Grab the last segment from the package name +name=${pkgName##*/} + +echo "Running Tests $pkgName..." +( + go test -v $(glide novendor) || exit 1 +) + +if [ "$1" == "release" ] +then + echo "Release Building $pkgName..." + CGO_ENABLED=${CGO_ENABLED:-0} \ + goreleaser +else + echo "Snapshot Building $pkgName..." + CGO_ENABLED=${CGO_ENABLED:-0} \ + goreleaser --snapshot --skip-publish +fi \ No newline at end of file diff --git a/dockerfile/build/build_environment.sh b/dockerfile/build/build_environment.sh new file mode 100644 index 0000000..71a713c --- /dev/null +++ b/dockerfile/build/build_environment.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +files=$(ls -1 /src | wc -l) +if [ "$files" == "0" ]; +then + echo "Error: Must mount Go source code into /src directory" + exit 990 +fi + +# Grab Go package name +pkgName="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)" + +if [ -z "$pkgName" ]; +then + echo "Error: Must add canonical import path to root package" + exit 992 +fi + +# Grab just first path listed in GOPATH +goPath="${GOPATH%%:*}" + +# Construct Go package path +pkgPath="$goPath/src/$pkgName" + +# Set-up src directory tree in GOPATH +mkdir -p "$(dirname "$pkgPath")" + +# Link source dir into GOPATH +ln -sf /src "$pkgPath" +cd "$pkgPath" + +echo "Restoring dependencies..." +if [ -e glide.yaml ]; +then + # Install dependencies with glide... + glide install +else + # Get all package dependencies + go get -t -d -v ./... +fi \ No newline at end of file diff --git a/goreleaser.yml b/goreleaser.yml index c0ea4c3..2941451 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -1,39 +1,15 @@ -# Build customization build: - # Path to main.go file. - # Default is `main.go` main: ./main.go - - # GOOS list to build in. - # For more info refer to https://golang.org/doc/install/source#environment - # Defaults are darwin and linux goos: - linux - windows - - # GOARCH to build in. - # For more info refer to https://golang.org/doc/install/source#environment - # Defaults are 386 and amd64 goarch: - amd64 - arm - arm64 - -# Archive customization archive: - # You can change the name of the archive. - # This is parsed with Golang template engine and the following variables. name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}" - - # Archive format. Valid options are `tar.gz` and `zip`. - # Default is `zip` format: tar.gz - - # Replacements for GOOS and GOARCH on the archive name. - # The keys should be valid GOOS or GOARCH values followed by your custom - # replacements. - # By default, `replacements` replace GOOS and GOARCH values with valid outputs - # of `uname -s` and `uname -m` respectively. replacements: arm: armhf arm64: arm64v8 @@ -41,17 +17,11 @@ archive: 386: 386 darwin: macOS linux: linux - format_overrides: - goos: windows format: zip - - # Additional files you want to add to the archive. - # Defaults are any files matching `LICENCE*`, `LICENSE*`, - # `README*` and `CHANGELOG*` (case-insensitive) files: - LICENSE.md - dockers: - goos: linux