2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 # Calculates and generates the version tag for the OPNFV objects:
17 logger -s -t "Calculate_version.info" "$*"
22 logger -s -t "Calculate_version.error" "$*"
27 #Functions which calculate the version
28 function docker_version() {
30 url_repo="https://registry.hub.docker.com/v2/repositories/${docker_image}/"
31 url_tag="https://registry.hub.docker.com/v2/repositories/${docker_image}/tags/"
32 status=$(curl -s --head -w %{http_code} ${url_repo} -o /dev/null)
33 if [ "${status}" != "200" ]; then
34 error "Cannot access ${url_repo}. Does the image ${docker_image} exist?"
36 tag_json=$(curl $url_tag 2>/dev/null | python -mjson.tool | grep ${BASE_VERSION} | head -1)
37 #e.g. tag_json= "name": "brahmaputra.0.2",
38 #special case, for dovetail, not sync with release, tag_json name not headed with arno, etc
39 if [ "${tag_json}" == "" ]; then
40 echo ${BASE_VERSION}.0
42 tag=$(echo $tag_json | awk '{print $2}' | sed 's/\,//' | sed 's/\"//g')
43 #e.g.: tag=brahmaputra.0.2
44 #special case, for dovetail, not sync with release
45 tag_current_version=$(echo $tag | sed 's/.*\.//')
46 tag_new_version=$(($tag_current_version+1))
47 #e.g.: tag=brahmaputra.0.3
48 echo ${BASE_VERSION}.${tag_new_version}
53 function artifact_version() {
55 error "Not supported yet..."
59 STORAGE_TYPES=(docker artifactrepo)
64 usage="Calculates the version text of one of the following objects.
67 bash $(basename "$0") [-h|--help] -t|--type docker|artifactrepo -n|--name <object_name>
70 -h|--help show this help text
71 -t|--type specify the storage location
72 -n|--name name of the repository/object
75 $(basename "$0") -t docker -n opnfv/functest
76 $(basename "$0") -t artifactrepo -n fuel"
100 error "unknown option $1"
104 shift # past argument or value
107 if [ -z "$BASE_VERSION" ]; then
108 error "Base version must be specified as environment variable. Ex.: export BASE_VERSION='brahmaputra.0'"
111 if [ "${TYPE}" == "" ]; then
112 error "Please specify the type of object to get the version from. $usage"
115 if [ "${NAME}" == "" ]; then
116 error "Please specify the name for the given storage type. $usage"
120 for i in "${STORAGE_TYPES[@]}"; do
121 if [[ "${TYPE}" == "$i" ]]; then
125 if [ ${not_in} == 1 ]; then
126 error "Unknown type: ${TYPE}. Available storage types are: [${STORAGE_TYPES[@]}]"
130 #info "Calculating version for object '${TYPE}' with arguments '${INFO}'..."
131 if [ "${TYPE}" == "docker" ]; then
134 elif [ "${TYPE}" == "artifactrepo" ]; then
135 artifact_version $NAME