master
sh 58 lines 1.71 KB
Raw
1 #!/usr/bin/env bash
2
3 # get-docker-tags.sh
4 #
5 # Usage:
6 # ./get-docker-tags.sh <build number> <git commit sha1> <git branch name> [git tag name]
7 #
8 # Example:
9 #
10 # # get tag for the master branch
11 # ./get-docker-tags.sh $(date -u +%F) testingsha master
12 #
13 # # get tag for a release tag
14 # ./get-docker-tags.sh $(date -u +%F) testingsha release v0.5.0
15 #
16 set -euo pipefail
17
18 if [[ $# -lt 1 ]] ; then
19 echo 'At least 1 arg required.'
20 echo 'Usage:'
21 echo './get-docker-tags.sh <build number> [git commit sha1] [git branch name] [git tag name]'
22 exit 1
23 fi
24
25 BUILD_NUM=$1
26 GIT_SHA1=${2:-$(git rev-parse HEAD)}
27 GIT_SHA1_SHORT=$(echo "$GIT_SHA1" | cut -c 1-7)
28 GIT_BRANCH=${3:-$(git symbolic-ref -q --short HEAD || echo "unknown")}
29 GIT_TAG=${4:-$(git describe --tags --exact-match 2> /dev/null || echo "")}
30
31 IMAGE_NAME=${IMAGE_NAME:-ipfs/kubo}
32
33 echoImageName () {
34 local IMAGE_TAG=$1
35 echo "$IMAGE_NAME:$IMAGE_TAG"
36 }
37
38 if [[ $GIT_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc ]]; then
39 echoImageName "$GIT_TAG"
40
41 elif [[ $GIT_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
42 echoImageName "$GIT_TAG"
43 echoImageName "latest"
44 echoImageName "release" # see: https://github.com/ipfs/kubo/issues/3999#issuecomment-742228981
45
46 elif [[ $GIT_BRANCH =~ ^bifrost-.* ]]; then
47 # sanitize the branch name since docker tags have stricter char limits than git branch names
48 branch=$(echo "$GIT_BRANCH" | tr '/' '-' | tr --delete --complement '[:alnum:]-')
49 echoImageName "${branch}-${BUILD_NUM}-${GIT_SHA1_SHORT}"
50
51 elif [ "$GIT_BRANCH" = "master" ] || [ "$GIT_BRANCH" = "staging" ]; then
52 echoImageName "${GIT_BRANCH}-${BUILD_NUM}-${GIT_SHA1_SHORT}"
53 echoImageName "${GIT_BRANCH}-latest"
54
55 else
56 echo "Nothing to do. No docker tag defined for branch: $GIT_BRANCH, tag: $GIT_TAG"
57
58 fi