forked from pixie-io/pixie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_build_release.sh
executable file
·103 lines (83 loc) · 3.83 KB
/
cloud_build_release.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# Copyright 2018- The Pixie 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.
#
# SPDX-License-Identifier: Apache-2.0
set -ex
printenv
usage() {
echo "Usage: $0 [-r]"
echo " -r : Create a prod proprietary cloud release."
echo " -p : Create a public cloud release."
}
parse_args() {
while test $# -gt 0; do
case "$1" in
-r) RELEASE=true
prod="True"
shift
;;
-p) PUBLIC=true
shift
;;
*) usage ;;
esac
done
}
prod="False"
parse_args "$@"
repo_path=$(pwd)
if [[ -z "${TAG_NAME}" ]]; then
image_tag=$(date +%s)
else
image_tag=$(echo "${TAG_NAME}" | awk -F/ '{print $NF}')
fi
echo "The image tag is: ${image_tag}"
# We are building the OSS images/YAMLs. In this case, we only want to push the images but not deploy the YAMLs.
if [[ "$PUBLIC" == "true" ]]; then
bazel run --stamp -c opt --action_env=GOOGLE_APPLICATION_CREDENTIALS --define BUNDLE_VERSION="${image_tag}" \
--define public=True //k8s/cloud:cloud_images_push
bazel build //tools/licenses:all_licenses --action_env=GOOGLE_APPLICATION_CREDENTIALS
gsutil cp "${repo_path}/bazel-bin/tools/licenses/all_licenses.json" "gs://pixie-dev-public/oss-licenses/${image_tag}.json"
gsutil cp "${repo_path}/bazel-bin/tools/licenses/all_licenses.json" "gs://pixie-dev-public/oss-licenses/latest.json"
# Write YAMLs + image paths to a tar file to support easy deployment.
mkdir -p "${repo_path}/pixie_cloud"
mkdir -p "${repo_path}/pixie_cloud/yamls"
image_list_file="${repo_path}/pixie_cloud/cloud_image_list.txt"
kustomize build "k8s/cloud_deps/public/" > "${repo_path}/pixie_cloud/yamls/cloud_deps.yaml"
kustomize build "k8s/cloud_deps/base/elastic/operator" >> "${repo_path}/pixie_cloud/yamls/cloud_deps_elastic_operator.yaml"
kustomize build "k8s/cloud/public/" > "${repo_path}/pixie_cloud/yamls/cloud.yaml"
#shellcheck disable=SC2002
cat "${repo_path}/pixie_cloud/yamls/cloud_deps.yaml" | yq e '.. | .image? | select(.)' -o=json - | jq 'strings' | sort | uniq > "${image_list_file}"
#shellcheck disable=SC2002
cat "${repo_path}/pixie_cloud/yamls/cloud_deps_elastic_operator.yaml" | yq e '.. | .image? | select(.)' -o=json - | jq 'strings' | sort | uniq > "${image_list_file}"
#shellcheck disable=SC2002
cat "${repo_path}/pixie_cloud/yamls/cloud.yaml" | yq e '.. | .image? | select(.)' -o=json - | jq 'strings' | sort | uniq >> "${image_list_file}"
cd "${repo_path}"
tar -czvf "${repo_path}/pixie_cloud.tar.gz" "pixie_cloud"
gsutil cp "${repo_path}/pixie_cloud.tar.gz" "gs://pixie-dev-public/cloud/${image_tag}/pixie_cloud.tar.gz"
gsutil cp "${repo_path}/pixie_cloud.tar.gz" "gs://pixie-dev-public/cloud/latest/pixie_cloud.tar.gz"
exit 0
fi
bazel run --stamp -c opt --action_env=GOOGLE_APPLICATION_CREDENTIALS --define BUNDLE_VERSION="${image_tag}" \
--define prod="${prod}" //k8s/cloud:cloud_images_push
yaml_path="${repo_path}/bazel-bin/k8s/cloud/pixie_staging_cloud.yaml"
# Build prod YAMLs.
if [[ "$RELEASE" == "true" ]]; then
yaml_path="${repo_path}/bazel-bin/k8s/cloud/pixie_prod_cloud.yaml"
bazel build --stamp -c opt --define BUNDLE_VERSION="${image_tag}" //k8s/cloud:prod_cloud_yamls
else # Build staging YAMLs.
bazel build --stamp -c opt --define BUNDLE_VERSION="${image_tag}" //k8s/cloud:staging_cloud_yamls
fi
kubectl apply -f "$yaml_path"