forked from pixie-io/pixie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_build_release.sh
executable file
·141 lines (118 loc) · 5.54 KB
/
cli_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/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
repo_path=$(bazel info workspace)
# shellcheck source=ci/gcs_utils.sh
. "${repo_path}/ci/gcs_utils.sh"
printenv
release_tag=${TAG_NAME##*/v}
linux_arch=x86_64
pkg_prefix="pixie-px-${release_tag}.${linux_arch}"
versions_file="${repo_path}/src/utils/artifacts/artifact_db_updater/VERSIONS.json"
echo "The release tag is: ${release_tag}"
linux_binary=$(bazel cquery //src/pixie_cli:px -c opt --output starlark --starlark:expr "target.files.to_list()[0].path" 2> /dev/null)
darwin_amd64_binary=$(bazel cquery -c opt //src/pixie_cli:px_darwin_amd64 --output starlark --starlark:expr "target.files.to_list()[0].path" 2> /dev/null)
darwin_arm64_binary=$(bazel cquery -c opt //src/pixie_cli:px_darwin_arm64 --output starlark --starlark:expr "target.files.to_list()[0].path" 2> /dev/null)
docker_repo="pixielabs/px"
bazel run -c opt //src/utils/artifacts/versions_gen:versions_gen -- \
--repo_path "${repo_path}" --artifact_name cli --versions_file "${versions_file}"
bazel build -c opt --stamp //src/pixie_cli:px_darwin_amd64 //src/pixie_cli:px_darwin_arm64 //src/pixie_cli:px
# Create and push docker image.
bazel run -c opt --stamp //src/pixie_cli:push_px_image
if [[ ! "$release_tag" == *"-"* ]]; then
# Make tmp directory, because the binary path is a symlink.
# We need to move the tmp directory to a shared location between the mounted
# docker volume and the host.
tmp_dir="$(mktemp -d)"
cp -RaL "${linux_binary}" "${tmp_dir}"
mv "${tmp_dir}" /mnt/disks/jenkins/sharedDir
tmp_subpath="$(echo "${tmp_dir}" | cut -d'/' -f3-)"
mkdir -p /mnt/disks/jenkins/sharedDir/image
# Create rpm package.
docker run -i --rm \
-v "/mnt/disks/jenkins/sharedDir/${tmp_subpath}:/src/" \
-v "/mnt/disks/jenkins/sharedDir/image:/image" \
cdrx/fpm-fedora:24 \
fpm \
-f \
-p "/image/${pkg_prefix}.rpm" \
-s dir \
-t rpm \
-n pixie-px \
-v "${release_tag}" \
--prefix /usr/local/bin \
px
# Create deb package.
docker run -i --rm \
-v "/mnt/disks/jenkins/sharedDir/${tmp_subpath}:/src/" \
-v "/mnt/disks/jenkins/sharedDir/image:/image" \
cdrx/fpm-ubuntu:18.04 \
fpm \
-f \
-p "/image/${pkg_prefix}.deb" \
-s dir \
-t deb \
-n pixie-px \
-v "${release_tag}" \
--prefix /usr/local/bin \
px
# Push officially releases to docker hub.
bazel run -c opt --stamp //src/pixie_cli:push_px_image_to_docker
# Update latest tag.
docker pull "${docker_repo}:${release_tag}"
docker tag "${docker_repo}:${release_tag}" "${docker_repo}:latest"
docker push "${docker_repo}:latest"
fi
gpg --no-tty --batch --yes --import "${BUILDBOT_GPG_KEY_FILE}"
write_artifacts_to_gcs() {
output_path=$1
copy_artifact_to_gcs "${output_path}" "${darwin_amd64_binary}" "cli_darwin_amd64_unsigned"
copy_artifact_to_gcs "${output_path}" "${darwin_arm64_binary}" "cli_darwin_arm64_unsigned"
copy_artifact_to_gcs "${output_path}" "${linux_binary}" "cli_linux_amd64"
if [[ ! "$release_tag" == *"-"* ]]; then
# RPM/DEB only exists for release builds.
copy_artifact_to_gcs "${output_path}" "/mnt/disks/jenkins/sharedDir/image/${pkg_prefix}.deb" "pixie-px.${linux_arch}.deb"
copy_artifact_to_gcs "${output_path}" "/mnt/disks/jenkins/sharedDir/image/${pkg_prefix}.rpm" "pixie-px.${linux_arch}.rpm"
fi
}
write_artifacts_to_gh() {
gh release create "${TAG_NAME}" --repo=pixie-io/pixie --notes "Pixie CLI Release"
tmp_dir="$(mktemp -d)"
cp "${linux_binary}" "${tmp_dir}/cli_linux_amd64"
cp "/mnt/disks/jenkins/sharedDir/image/${pkg_prefix}.deb" "${tmp_dir}/pixie-px.${linux_arch}.deb"
cp "/mnt/disks/jenkins/sharedDir/image/${pkg_prefix}.rpm" "${tmp_dir}/pixie-px.${linux_arch}.rpm"
pushd "${tmp_dir}"
gpg --no-tty --batch --yes --local-user "${BUILDBOT_GPG_KEY_ID}" --armor --detach-sign "cli_linux_amd64"
gpg --no-tty --batch --yes --local-user "${BUILDBOT_GPG_KEY_ID}" --armor --detach-sign "pixie-px.${linux_arch}.deb"
gpg --no-tty --batch --yes --local-user "${BUILDBOT_GPG_KEY_ID}" --armor --detach-sign "pixie-px.${linux_arch}.rpm"
gh release upload "${TAG_NAME}" --repo=pixie-io/pixie "cli_linux_amd64" "cli_linux_amd64.asc" "pixie-px.${linux_arch}.deb" "pixie-px.${linux_arch}.deb.asc" "pixie-px.${linux_arch}.rpm" "pixie-px.${linux_arch}.rpm.asc"
popd
}
public="True"
bucket="pixie-dev-public"
if [[ $release_tag == *"-"* ]]; then
public="False"
bucket="pixie-prod-artifacts"
fi
output_path="gs://${bucket}/cli/${release_tag}"
write_artifacts_to_gcs "${output_path}"
# Check to see if it's production build. If so we should also write it to the latest directory.
if [[ $public == "True" ]]; then
output_path="gs://pixie-dev-public/cli/latest"
write_artifacts_to_gcs "${output_path}"
write_artifacts_to_gh
fi