From 3b08a83ec492e0250c02698ed230e642cca0b260 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@erisindustries.com> Date: Tue, 5 Sep 2017 18:36:20 +0100 Subject: [PATCH] Make sure we check for presence of burrow bin and that build succeeds --- .circleci/config.yml | 52 +++++++++++++++++++++++++++++++--------- Dockerfile | 2 ++ Makefile | 2 +- build_tool.sh | 51 --------------------------------------- scripts/build_tool.sh | 39 ++++++++++++++++++++++++++++++ scripts/local_version.sh | 37 ++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 63 deletions(-) delete mode 100755 build_tool.sh create mode 100755 scripts/build_tool.sh create mode 100755 scripts/local_version.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d122c55..27e3ce0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,6 +10,10 @@ tag_filters: &tags_filters tags: only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ +setup_docker: &setup_docker + version: 17.06.1-ce + +# Start of CircleCI 2.0 config version: 2 jobs: checkout_code: @@ -38,25 +42,44 @@ jobs: at: . - run: make test_integration - build: + build_docker: <<: *defaults steps: - attach_workspace: at: . - - run: make build + # This allows us to perform our docker builds + - setup_remote_docker: + <<: *setup_docker + - run: docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io + # build docker image and tag the docker image(s) depending on branch/tag + - run: make build_docker_db + - run: docker save quay.io/monax/db > db-images.tar + - persist_to_workspace: + root: . + paths: + - db-images.tar - release: + # Simple smoke test to ensure burrow binary has been provisioned to container + test_docker_smoke: <<: *defaults steps: - # restore checkout - attach_workspace: at: . - # This allows us to perform our docker builds - setup_remote_docker: - version: 17.06.1-ce + <<: *setup_docker - run: docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io - # build docker image and tag the image with the version, date, and commit hash - - run: make build_docker_db + - run: docker load -i db-images.tar + - run: docker run quay.io/monax/db:$(./scripts/local_version.sh) burrow -h + + push_docker: + <<: *defaults + steps: + - attach_workspace: + at: . + - setup_remote_docker: + <<: *setup_docker + - run: docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io + - run: docker load -i db-images.tar - run: docker push quay.io/monax/db @@ -72,6 +95,7 @@ workflows: # In contract jobs build against all branches by default filters: <<: *tags_filters + - test: requires: - checkout_code @@ -84,17 +108,23 @@ workflows: filters: <<: *tags_filters - - build: + - build_docker: requires: - checkout_code filters: <<: *tags_filters - - release: + - test_docker_smoke: + requires: + - build_docker + filters: + <<: *tags_filters + + - push_docker: requires: - test - test_integration - - build + - test_docker_smoke filters: # tags filters and branch filters are applied disjunctively, so we # will still build tags not on develop (i.e. including tagged diff --git a/Dockerfile b/Dockerfile index f4850d48..5a3cba14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,8 @@ RUN go build --ldflags '-extldflags "-static"' -o bin/burrow-client ./client/cmd # This will be our base container image FROM alpine:3.6 +ARG REPO=/go/src/github.com/hyperledger/burrow + ENV USER monax ENV MONAX_PATH /home/$USER/.monax RUN addgroup -g 101 -S $USER && adduser -S -D -u 1000 $USER $USER diff --git a/Makefile b/Makefile index 260f0379..9dca14f5 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ test_race: build_race # build docker image for burrow .PHONY: build_docker_db build_docker_db: check - @./build_tool.sh + @scripts/build_tool.sh ### Clean up diff --git a/build_tool.sh b/build_tool.sh deleted file mode 100755 index d9e2570e..00000000 --- a/build_tool.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash -# ---------------------------------------------------------- -# PURPOSE - -# This is the build script for the Monax stack. It will -# build the tool into docker containers in a reliable and -# predictable manner. - -# ---------------------------------------------------------- -# REQUIREMENTS -# -# docker, go, make, and git installed locally - -# ---------------------------------------------------------- -# USAGE - -# build_tool.sh [version tag] - -# ---------------------------------------------------------- - -set -e - -IMAGE=${IMAGE:-"quay.io/monax/db"} -VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+$" - -version=$(go run ./util/version/cmd/main.go) -tag=$(git tag --points-at HEAD) - -if [[ ${tag} =~ ${VERSION_REGEX} ]] ; then - # Only label a build as a release version when the commit is tagged - echo "Building release version (tagged $tag)..." - # Fail noisily when trying to build a release version that does not match code tag - if [[ ! ${tag} = "v$version" ]]; then - echo "Build failure: version tag $tag does not match version/version.go version $version" - exit 1 - fi -else - date=$(date +"%Y%m%d") - commit=$(git rev-parse --short HEAD) - version="$version-dev-$date-$commit" - echo "Building non-release version $version..." -fi - -if [[ "$1" ]] ; then - # If argument provided, use it as the version tag - echo "Overriding detected version $version and tagging image as $1" - version="$1" -fi - -docker build -t ${IMAGE}:${version} . - diff --git a/scripts/build_tool.sh b/scripts/build_tool.sh new file mode 100755 index 00000000..e890e2a0 --- /dev/null +++ b/scripts/build_tool.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# ---------------------------------------------------------- +# PURPOSE + +# This is the build script for the Monax stack. It will +# build the tool into docker containers in a reliable and +# predictable manner. + +# ---------------------------------------------------------- +# REQUIREMENTS +# +# docker, go, make, and git installed locally + +# ---------------------------------------------------------- +# USAGE + +# build_tool.sh [version tag] + +# ---------------------------------------------------------- + +set -e + +IMAGE=${IMAGE:-"quay.io/monax/db"} +REPO=${REPO:-"$GOPATH/src/github.com/hyperledger/burrow"} + +function log() { + echo "$*" >> /dev/stderr +} + +version=$("$REPO/scripts/local_version.sh") + +if [[ "$1" ]] ; then + # If argument provided, use it as the version tag + log "Overriding detected version $version and tagging image as $1" + version="$1" +fi + +docker build -t ${IMAGE}:${version} ${REPO} + diff --git a/scripts/local_version.sh b/scripts/local_version.sh new file mode 100755 index 00000000..4ae67c41 --- /dev/null +++ b/scripts/local_version.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Script that outputs a version identifier based on the in-code version of +# Burrow combined with date and git commit or the git tag if tag is a version. +# +# If working directory is checked out at a version tag then checks that the tag +# matches the in-code version and fails if it does not. +# +set -e + +REPO=${REPO:-"$GOPATH/src/github.com/hyperledger/burrow"} +VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+$" + + +version=$(go run "$REPO/util/version/cmd/main.go") +tag=$(git tag --points-at HEAD) + +function log() { + echo "$*" >> /dev/stderr +} + +if [[ ${tag} =~ ${VERSION_REGEX} ]] ; then + # Only label a build as a release version when the commit is tagged + log "Building release version (tagged $tag)..." + # Fail noisily when trying to build a release version that does not match code tag + if [[ ! ${tag} = "v$version" ]]; then + log "Build failure: version tag $tag does not match version/version.go version $version" + exit 1 + fi +else + date=$(date +"%Y%m%d") + commit=$(git rev-parse --short HEAD) + version="$version-dev-$date-$commit" + log "Building non-release version $version..." +fi + +echo ${version} \ No newline at end of file -- GitLab