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 if [ "${tag_json}" == "" ]; then
39 error "The Docker Image ${docker_image} does not have a TAG with base version ${BASE_VERSION}"
41 tag=$(echo $tag_json | awk '{print $2}' | sed 's/\,//' | sed 's/\"//g')
42 #e.g.: tag=brahmaputra.0.2
43 tag_current_version=$(echo $tag | sed 's/.*\.//')
44 tag_new_version=$(($tag_current_version+1))
45 #e.g.: tag=brahmaputra.0.3
46 echo ${BASE_VERSION}.${tag_new_version}
50 function artifact_version() {
52 error "Not supported yet..."
56 STORAGE_TYPES=(docker artifactrepo)
61 usage="Calculates the version text of one of the following objects.
64 bash $(basename "$0") [-h|--help] -t|--type docker|artifactrepo -n|--name <object_name>
67 -h|--help show this help text
68 -t|--type specify the storage location
69 -n|--name name of the repository/object
72 $(basename "$0") -t docker -n opnfv/functest
73 $(basename "$0") -t artifactrepo -n fuel"
97 error "unknown option $1"
101 shift # past argument or value
104 if [ -z "$BASE_VERSION" ]; then
105 error "Base version must be specified as environment variable. Ex.: export BASE_VERSION='brahmaputra.0'"
108 if [ "${TYPE}" == "" ]; then
109 error "Please specify the type of object to get the version from. $usage"
112 if [ "${NAME}" == "" ]; then
113 error "Please specify the name for the given storage type. $usage"
117 for i in "${STORAGE_TYPES[@]}"; do
118 if [[ "${TYPE}" == "$i" ]]; then
122 if [ ${not_in} == 1 ]; then
123 error "Unknown type: ${TYPE}. Available storage types are: [${STORAGE_TYPES[@]}]"
127 #info "Calculating version for object '${TYPE}' with arguments '${INFO}'..."
128 if [ "${TYPE}" == "docker" ]; then
131 elif [ "${TYPE}" == "artifactrepo" ]; then
132 artifact_version $NAME