5 # Jose Lausuch <jose.lausuch@ericsson.com>
6 # Fatih Degirmenci <fatih.degirmenci@ericsson.com>
8 # Calculates and generates the version tag for the OPNFV objects:
15 logger -s -t "Calculate_version.info" "$*"
20 logger -s -t "Calculate_version.error" "$*"
25 #Functions which calculate the version
26 function docker_version() {
28 url_repo="https://registry.hub.docker.com/v2/repositories/${docker_image}/"
29 url_tag="https://registry.hub.docker.com/v2/repositories/${docker_image}/tags/"
30 status=$(curl -s --head -w %{http_code} ${url_repo} -o /dev/null)
31 if [ "${status}" != "200" ]; then
32 error "Cannot access ${url_repo}. Does the image ${docker_image} exist?"
34 tag_json=$(curl $url_tag 2>/dev/null | python -mjson.tool | grep ${BASE_VERSION} | head -1)
35 #e.g. tag_json= "name": "brahmaputra.0.2",
36 if [ "${tag_json}" == "" ]; then
37 error "The Docker Image ${docker_image} does not have a TAG with base version ${BASE_VERSION}"
39 tag=$(echo $tag_json | awk '{print $2}' | sed 's/\,//' | sed 's/\"//g')
40 #e.g.: tag=brahmaputra.0.2
41 tag_current_version=$(echo $tag | sed 's/.*\.//')
42 tag_new_version=$(($tag_current_version+1))
43 #e.g.: tag=brahmaputra.0.3
44 echo ${BASE_VERSION}.${tag_new_version}
48 function artifact_version() {
50 error "Not supported yet..."
54 STORAGE_TYPES=(docker artifactrepo)
59 usage="Calculates the version text of one of the following objects.
62 bash $(basename "$0") [-h|--help] -t|--type docker|artifactrepo -n|--name <object_name>
65 -h|--help show this help text
66 -t|--type specify the storage location
67 -n|--name name of the repository/object
70 $(basename "$0") -t docker -n opnfv/functest
71 $(basename "$0") -t artifactrepo -n fuel"
95 error "unknown option $1"
99 shift # past argument or value
102 if [ -z "$BASE_VERSION" ]; then
103 error "Base version must be specified as environment variable. Ex.: export BASE_VERSION='brahmaputra.0'"
106 if [ "${TYPE}" == "" ]; then
107 error "Please specify the type of object to get the version from. $usage"
110 if [ "${NAME}" == "" ]; then
111 error "Please specify the name for the given storage type. $usage"
115 for i in "${STORAGE_TYPES[@]}"; do
116 if [[ "${TYPE}" == "$i" ]]; then
120 if [ ${not_in} == 1 ]; then
121 error "Unknown type: ${TYPE}. Available storage types are: [${STORAGE_TYPES[@]}]"
125 #info "Calculating version for object '${TYPE}' with arguments '${INFO}'..."
126 if [ "${TYPE}" == "docker" ]; then
129 elif [ "${TYPE}" == "artifactrepo" ]; then
130 artifact_version $NAME