Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Properly version grid artifacts
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Beck-Buysse <[email protected]>
  • Loading branch information
rbuysse committed Dec 12, 2019
1 parent 672ba7a commit 73dd4b0
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ISOLATION_ID=latest
DISTRO=bionic
REPO_VERSION=0.1.0-dev
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.1
82 changes: 82 additions & 0 deletions bin/get_version
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions contracts/pike/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===-------------
Expand Down
2 changes: 2 additions & 0 deletions contracts/product/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===-------------
Expand Down
2 changes: 2 additions & 0 deletions contracts/schema/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===-------------
Expand Down
2 changes: 2 additions & 0 deletions contracts/track_and_trace/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===-------------
Expand Down
8 changes: 6 additions & 2 deletions daemon/Dockerfile-installed-bionic
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-compose-installed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- http_proxy
- https_proxy
- no_proxy
- REPO_VERSION=${REPO_VERSION}

validator:
image: hyperledger/sawtooth-validator:1.1
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
build:
context: .
dockerfile: contracts/track_and_trace/Dockerfile
args:
- REPO_VERSION=${REPO_VERSION}
volumes:
- grid-shared:/grid-shared
entrypoint: |
Expand All @@ -46,6 +48,8 @@ services:
build:
context: .
dockerfile: contracts/schema/Dockerfile
args:
- REPO_VERSION=${REPO_VERSION}
volumes:
- grid-shared:/grid-shared
entrypoint: |
Expand All @@ -65,6 +69,8 @@ services:
build:
context: .
dockerfile: contracts/pike/Dockerfile
args:
- REPO_VERSION=${REPO_VERSION}
volumes:
- grid-shared:/grid-shared
entrypoint: |
Expand All @@ -83,6 +89,8 @@ services:
build:
context: .
dockerfile: contracts/product/Dockerfile
args:
- REPO_VERSION=${REPO_VERSION}
volumes:
- grid-shared:/grid-shared
entrypoint: |
Expand Down

0 comments on commit 73dd4b0

Please sign in to comment.