-
Notifications
You must be signed in to change notification settings - Fork 71
/
workspace_status.sh
executable file
·74 lines (64 loc) · 2.31 KB
/
workspace_status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Usage: workspace_status.sh [inject]
set -o errexit
set -o nounset
set -o pipefail
INJECTION=false
# By specifying the injection argument, variables will separated by
# their values with an '=', instead of a ' '. This allows for easier
# variable injection when consuming this script in shell environments.
if (( $# == 1 )) && [ "$1" == "inject" ]; then
INJECTION=true
fi
#`p_` takes two arguments to define a workspace status variable:
#
# * the name of the variable
# * a default value
#
# If an environment variable with the corresponding name is set, its value is
# used. Otherwise, the provided default value is used.
p_() {
if (( $# == 2 )); then
if [ "$INJECTION" = true ]; then
echo "$1"=\""${!1:-$2}"\"
else
echo "$1" "${!1:-$2}"
fi
else
return 1
fi
}
build_date="$(date -u '+%Y%m%d')"
# Create a placeholder git commit value if the git env cannot be found
null_git_commit="no-git-env"
git_commit="$(git describe --tags --always --dirty)" || \
git_commit="$null_git_commit"
image_tag="v${build_date}-${git_commit}"
if [[ ${git_commit} == "$null_git_commit" ]]; then
image_tag="${GIT_TAG}"
fi
p_ GIT_COMMIT "${git_commit}"
p_ IMG_REGISTRY gcr.io
p_ IMG_REPOSITORY k8s-staging-artifact-promoter
p_ IMG_NAME kpromo
p_ IMG_TAG "${image_tag}"
p_ IMG_VERSION v4.0.5-0
p_ TEST_AUDIT_PROD_IMG_REPOSITORY us.gcr.io/k8s-gcr-audit-test-prod
p_ TEST_AUDIT_STAGING_IMG_REPOSITORY gcr.io/k8s-gcr-audit-test-prod
p_ TEST_AUDIT_PROJECT_ID k8s-gcr-audit-test-prod
p_ TEST_AUDIT_PROJECT_NUMBER 375340694213
p_ TEST_AUDIT_INVOKER_SERVICE_ACCOUNT k8s-infra-gcr-promoter@k8s-gcr-audit-test-prod.iam.gserviceaccount.com
p_ TEST_STAGING_IMG_REPOSITORY gcr.io/k8s-staging-cip-test