From 73dd4b0ef6439c44c67c714de805aed7112fe7f7 Mon Sep 17 00:00:00 2001 From: Ryan Beck-Buysse Date: Wed, 11 Dec 2019 12:47:36 -0600 Subject: [PATCH] Properly version grid artifacts Signed-off-by: Ryan Beck-Buysse --- .env | 1 + Jenkinsfile | 2 +- VERSION | 1 + bin/get_version | 82 ++++++++++++++++++++++++++++ contracts/pike/Dockerfile | 2 + contracts/product/Dockerfile | 2 + contracts/schema/Dockerfile | 2 + contracts/track_and_trace/Dockerfile | 2 + daemon/Dockerfile-installed-bionic | 8 ++- docker-compose-installed.yaml | 1 + docker-compose.yaml | 8 +++ 11 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 VERSION create mode 100755 bin/get_version diff --git a/.env b/.env index ae5d429850..84ff78db06 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ ISOLATION_ID=latest DISTRO=bionic +REPO_VERSION=0.1.0-dev diff --git a/Jenkinsfile b/Jenkinsfile index 60f96c496f..d5b96bc867 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,7 +71,7 @@ node ('master') { // Use a docker container to build and protogen, so that the Jenkins // environment doesn't need all the dependencies. stage("Build Test Dependencies") { - sh 'docker-compose -f docker-compose-installed.yaml build --force-rm' + sh 'VERSION=AUTO_STRICT REPO_VERSION=$(./bin/get_version) docker-compose -f docker-compose-installed.yaml build --force-rm' sh 'docker-compose -f docker/compose/grid_tests.yaml build --force-rm' } diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..17e51c385e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.1 diff --git a/bin/get_version b/bin/get_version new file mode 100755 index 0000000000..879102c862 --- /dev/null +++ b/bin/get_version @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +# Copyright 2016, 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ------------------------------------------------------------------------------ + +import os +import subprocess +import sys + +top_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + +version_file = top_dir + "/VERSION" + +with open(version_file, 'r') as f: + version_data = f.read().strip() + + +def bump_version(version): + (major, minor, patch) = version.split('.') + if 'rc' in patch: + parts = patch.split('rc') + parts[1] = str(int(parts[1]) + 1) + patch = "rc".join(parts) + else: + patch = str(int(patch) + 1) + return ".".join([major, minor, patch]) + + +def auto_version(default, strict): + output = subprocess.check_output(['git', 'describe', '--dirty']) + parts = output.decode('utf-8').strip().split('-', 3) + parts[0] = parts[0][1:] # strip the leading 'v' + if len(parts) > 1: + parts[0] = bump_version(parts[0]) + if default != parts[0]: + msg = "VERSION file and (bumped?) git describe versions differ: " \ + "{} != {}".format(default, parts[0]) + if strict: + print("ERROR: " + msg, file=sys.stderr) + sys.exit(1) + else: + print("WARNING: " + msg, file=sys.stderr) + print( + "WARNING: using setup.py version {}".format(default), + file=sys.stderr) + parts[0] = default + + if len(parts) > 1: + parts[0] = "-dev".join([parts[0], parts[1].replace("-", ".")]) + if len(parts) == 4: + parts[0] = parts[0] + "-" + parts[3] + return parts[0] + else: + return parts[0] + + +def version(default): + if 'VERSION' in os.environ: + if os.environ['VERSION'] == 'AUTO_STRICT': + version = auto_version(default, strict=True) + elif os.environ['VERSION'] == 'AUTO': + version = auto_version(default, strict=False) + else: + version = os.environ['VERSION'] + else: + version = default + "-dev1" + return version + + +print(version(version_data)) diff --git a/contracts/pike/Dockerfile b/contracts/pike/Dockerfile index 0cba86d543..05a3f54d3f 100644 --- a/contracts/pike/Dockerfile +++ b/contracts/pike/Dockerfile @@ -21,6 +21,8 @@ COPY sdk/ /build/sdk/ WORKDIR /build/contracts/pike # Build the contract +ARG REPO_VERSION +RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${REPO_VERSION}\"/" Cargo.toml RUN cargo build --target wasm32-unknown-unknown --release # -------------=== pike submitter build ===------------- diff --git a/contracts/product/Dockerfile b/contracts/product/Dockerfile index fe83bb996a..9eb3ca745a 100644 --- a/contracts/product/Dockerfile +++ b/contracts/product/Dockerfile @@ -22,6 +22,8 @@ COPY sdk/ /build/sdk/ WORKDIR /build/contracts/product # Build the contract +ARG REPO_VERSION +RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${REPO_VERSION}\"/" Cargo.toml RUN cargo build --target wasm32-unknown-unknown --release # -------------=== product submitter build ===------------- diff --git a/contracts/schema/Dockerfile b/contracts/schema/Dockerfile index 65cb91942e..dd3cadebb8 100644 --- a/contracts/schema/Dockerfile +++ b/contracts/schema/Dockerfile @@ -21,6 +21,8 @@ COPY sdk/ /build/sdk/ WORKDIR /build/contracts/schema # Build the contract +ARG REPO_VERSION +RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${REPO_VERSION}\"/" Cargo.toml RUN cargo build --target wasm32-unknown-unknown --release # -------------=== schema submitter build ===------------- diff --git a/contracts/track_and_trace/Dockerfile b/contracts/track_and_trace/Dockerfile index 548ad16821..40da722790 100644 --- a/contracts/track_and_trace/Dockerfile +++ b/contracts/track_and_trace/Dockerfile @@ -21,6 +21,8 @@ COPY sdk/ /build/sdk/ WORKDIR /build/contracts/track_and_trace # Build the contract +ARG REPO_VERSION +RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${REPO_VERSION}\"/" Cargo.toml RUN cargo build --target wasm32-unknown-unknown --release # -------------=== track_and_trace submitter build ===------------- diff --git a/daemon/Dockerfile-installed-bionic b/daemon/Dockerfile-installed-bionic index 8e878ff9f0..c327149da8 100644 --- a/daemon/Dockerfile-installed-bionic +++ b/daemon/Dockerfile-installed-bionic @@ -20,11 +20,15 @@ COPY sdk /build/sdk # Build the gridd package WORKDIR /build/daemon -RUN cargo deb +ARG REPO_VERSION +RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${REPO_VERSION}\"/" Cargo.toml +RUN cargo deb --deb-version $REPO_VERSION # Build the grid-cli package WORKDIR /build/cli -RUN cargo deb +ARG REPO_VERSION +RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${REPO_VERSION}\"/" Cargo.toml +RUN cargo deb --deb-version $REPO_VERSION # -------------=== gridd docker build ===------------- FROM ubuntu:bionic diff --git a/docker-compose-installed.yaml b/docker-compose-installed.yaml index bb555549fd..6b5de0aa68 100644 --- a/docker-compose-installed.yaml +++ b/docker-compose-installed.yaml @@ -27,6 +27,7 @@ services: - http_proxy - https_proxy - no_proxy + - REPO_VERSION=${REPO_VERSION} validator: image: hyperledger/sawtooth-validator:1.1 diff --git a/docker-compose.yaml b/docker-compose.yaml index b610ff0302..c76436bae5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,6 +26,8 @@ services: build: context: . dockerfile: contracts/track_and_trace/Dockerfile + args: + - REPO_VERSION=${REPO_VERSION} volumes: - grid-shared:/grid-shared entrypoint: | @@ -46,6 +48,8 @@ services: build: context: . dockerfile: contracts/schema/Dockerfile + args: + - REPO_VERSION=${REPO_VERSION} volumes: - grid-shared:/grid-shared entrypoint: | @@ -65,6 +69,8 @@ services: build: context: . dockerfile: contracts/pike/Dockerfile + args: + - REPO_VERSION=${REPO_VERSION} volumes: - grid-shared:/grid-shared entrypoint: | @@ -83,6 +89,8 @@ services: build: context: . dockerfile: contracts/product/Dockerfile + args: + - REPO_VERSION=${REPO_VERSION} volumes: - grid-shared:/grid-shared entrypoint: |