Fix OS_CLOUD export for image validation
[releng/global-jjb.git] / shell / docker-get-container-tag.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 echo "---> docker-get-container-tag.sh"
13
14 # Gets the container tag per $CONTAINER_TAG_METHOD
15 # For YAML file use directory $CONTAINER_TAG_YAML_DIR
16 # if a value is provided, else fall back to $DOCKER_ROOT
17 # use login flag to get $HOME/.local/bin in PATH
18
19 set -feu -o pipefail
20
21 tag=""
22 if [[ $CONTAINER_TAG_METHOD == "latest" ]]; then
23     tag="latest"
24 elif [[ $CONTAINER_TAG_METHOD == "git-describe" ]]; then
25     tag=$(git describe)
26 elif [[ $CONTAINER_TAG_METHOD == "yaml-file" ]]; then
27     dir=${CONTAINER_TAG_YAML_DIR:-$DOCKER_ROOT}
28     tag_file=$dir/container-tag.yaml
29     if [[ -f $tag_file ]]; then
30         # pip installs yq to $HOME/.local/bin
31         tag=$(yq -r .tag "$tag_file")
32     else
33         echo "File $tag_file not found."
34     fi
35 else
36     echo "Method $CONTAINER_TAG_METHOD not implemented (yet)"
37 fi
38 if [[ -z $tag ]]; then
39     echo "Failed to get a container tag using method $CONTAINER_TAG_METHOD"
40     exit 1
41 fi
42 echo "---> Docker image tag found: $tag"
43 # Write DOCKER_IMAGE_TAG information to a file so it can be
44 # injected into the environment for following steps
45 echo "DOCKER_IMAGE_TAG=$tag" >> "$WORKSPACE/env_docker_inject.txt"