Skip to content

Commit 6d0b02b

Browse files
committed
PMM-12899 extract server rpm script
1 parent 42a02a9 commit 6d0b02b

File tree

5 files changed

+115
-48
lines changed

5 files changed

+115
-48
lines changed

build/local/build.sh

+60-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
#!/bin/bash -e
22

3-
# Update submodules and PR branches
4-
/bin/bash $(dirname $0)/update.sh
3+
# Define global variables
4+
NO_UPDATE=0
5+
NO_CLIENT=0
6+
NO_CLIENT_DOCKER=0
7+
NO_SERVER_RPM=0
8+
9+
while test "$#" -gt 0; do
10+
case "$1" in
11+
--no-update)
12+
NO_UPDATE=1
13+
;;
14+
--no-client)
15+
NO_CLIENT=1
16+
;;
17+
--no-client-docker)
18+
NO_CLIENT_DOCKER=1
19+
;;
20+
--no-server-rpm)
21+
NO_SERVER_RPM=1
22+
;;
23+
*)
24+
echo "Unknown argument: $1"
25+
echo "Usage: $0 [--no-update] [--no-client] [--no-client-docker] [--no-server-rpm]"
26+
exit 1
27+
;;
28+
esac
29+
shift
30+
done
31+
32+
if [ "$NO_UPDATE" -eq 0 ]; then
33+
# Update submodules and PR branches
34+
/bin/bash $(dirname $0)/update.sh
35+
fi
536

637
get_branch_name() {
738
local module="${1:-}"
@@ -33,7 +64,7 @@ echo $pmm_ui_tests_commit > pmmUITestsCommitSha
3364
fb_commit_sha=$(git rev-parse HEAD)
3465
echo $fb_commit_sha > fbCommitSha
3566

36-
# We use a special docker image to build various PMM artifacts - `perconalab/rpmbuild:ol9`.
67+
# We use a special docker image to build various PMM artifacts - `perconalab/rpmbuild:3`.
3768
# Important: the docker container's user need to be able to write to these directories.
3869
# The docker container's user is `builder` with uid 1000 and gid 1000. You need to make sure
3970
# that the directories we create on the host are owned by a user with same uid and gid.
@@ -51,22 +82,26 @@ export RPMBUILD_DOCKER_IMAGE=perconalab/rpmbuild:3
5182
# RAM: 16GB
5283
# OS: Ubuntu 22.04.1 LTS
5384

54-
# Build client source: 4m39s from scratch, 0m27s using cache
55-
"$PATH_TO_SCRIPTS/build-client-source"
85+
if [ "$NO_CLIENT" -eq 0 ]; then
86+
# Build client source: 4m39s from scratch, 0m27s using cache
87+
"$PATH_TO_SCRIPTS/build-client-source"
5688

57-
# Build client binary: ??? from scratch, 0m20s using cache
58-
"$PATH_TO_SCRIPTS/build-client-binary"
89+
# Build client binary: ??? from scratch, 0m20s using cache
90+
"$PATH_TO_SCRIPTS/build-client-binary"
5991

60-
# Building client source rpm takes 13s (caching does not apply)
61-
"$PATH_TO_SCRIPTS/build-client-srpm"
92+
# Building client source rpm takes 13s (caching does not apply)
93+
"$PATH_TO_SCRIPTS/build-client-srpm"
6294

63-
# Building client rpm takes 1m40s
64-
"$PATH_TO_SCRIPTS/build-client-rpm"
95+
# Building client rpm takes 1m40s
96+
"$PATH_TO_SCRIPTS/build-client-rpm"
97+
fi
6598

6699
# Building client docker image takes 17s
67100
GIT_COMMIT=$(git rev-parse HEAD | head -c 8)
68101
export DOCKER_CLIENT_TAG=local/pmm-client:${GIT_COMMIT}
69-
"$PATH_TO_SCRIPTS/build-client-docker"
102+
if [ "$NO_CLIENT_DOCKER" -eq 0 ] || [ "$NO_CLIENT" -eq 0 ]; then
103+
"$PATH_TO_SCRIPTS/build-client-docker"
104+
fi
70105

71106
# Building PMM CLient locally (non-CI, i.e. non-Jenkins)
72107
# total time: 6m26s - build from scratch, no initial cache
@@ -79,20 +114,23 @@ export DOCKER_CLIENT_TAG=local/pmm-client:${GIT_COMMIT}
79114

80115
export RPM_EPOCH=1
81116
export RPMBUILD_DIST="el9"
82-
"$PATH_TO_SCRIPTS/build-server-rpm" percona-dashboards grafana-dashboards
83-
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-managed pmm
84-
"$PATH_TO_SCRIPTS/build-server-rpm" percona-qan-api2 pmm
85-
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-update pmm
86-
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-dump
87-
"$PATH_TO_SCRIPTS/build-server-rpm" vmproxy pmm
88117

89-
# 3rd-party
90-
"$PATH_TO_SCRIPTS/build-server-rpm" victoriametrics
91-
"$PATH_TO_SCRIPTS/build-server-rpm" grafana
118+
if [ "$NO_SERVER_RPM" -eq 0 ]; then
119+
"$PATH_TO_SCRIPTS/build-server-rpm" percona-dashboards grafana-dashboards
120+
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-managed pmm
121+
"$PATH_TO_SCRIPTS/build-server-rpm" percona-qan-api2 pmm
122+
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-update pmm
123+
"$PATH_TO_SCRIPTS/build-server-rpm" pmm-dump
124+
"$PATH_TO_SCRIPTS/build-server-rpm" vmproxy pmm
125+
126+
# 3rd-party
127+
"$PATH_TO_SCRIPTS/build-server-rpm" victoriametrics
128+
"$PATH_TO_SCRIPTS/build-server-rpm" grafana
129+
fi
92130

93131
export DOCKER_TAG=local/pmm-server:${GIT_COMMIT}
94132
export RPMBUILD_DIST=el9
95-
export DOCKERFILE=Dockerfile.el9.local
133+
export DOCKERFILE=Dockerfile.el9
96134
${PATH_TO_SCRIPTS}/build-server-docker
97135

98136
# Clean up temporary files

build/scripts/build-rpmbuild-docker

-11
This file was deleted.

build/scripts/build-server-docker

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ if [ -z "${DOCKER_TAG}" ]; then
3232
DOCKER_TAG=perconalab/pmm-server-fb:${full_pmm_version}
3333
fi
3434

35-
IMAGE_VERSION=`echo $DOCKER_TAG | cut -d ':' -f2`
36-
37-
docker build --build-arg BUILD_DATE="`date --rfc-3339=seconds`" \
38-
--build-arg VERSION="$IMAGE_VERSION" \
39-
--squash \
40-
--no-cache \
41-
-f ${docker_root}/${docker_file} \
42-
-t ${DOCKER_TAG} \
43-
${docker_root}/
35+
IMAGE_VERSION=$(echo "$DOCKER_TAG" | cut -d ':' -f2)
36+
37+
docker buildx build \
38+
--build-arg BUILD_DATE=$(date --rfc-3339=seconds) \
39+
--build-arg VERSION="$IMAGE_VERSION" \
40+
--progress plain \
41+
-f ${docker_root}/${docker_file} \
42+
-t ${DOCKER_TAG} \
43+
${docker_root}
4444

4545
if [ -n "${PUSH_DOCKER}" ]; then
4646
mkdir -p $(dirname ${docker_tag_file})

build/scripts/build-server-rpm

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ is_build_needed() {
2424
local spec_name=$1
2525
local rpm_version=$2
2626
local packages=
27-
local cache_dir=RELEASE
27+
local s3_cache_dir=RELEASE
2828

2929
# Structure of S3 build cache
3030
# s3://pmm-build-cache/PR-BUILDS/7 - el7
@@ -36,13 +36,13 @@ is_build_needed() {
3636

3737
# RPM_EPOCH is set to 1 for Feature Builds
3838
if [ "$RPM_EPOCH" = 1 ]; then
39-
cache_dir=PR-BUILDS
39+
s3_cache_dir=PR-BUILDS
4040
fi
4141
if command -v aws &> /dev/null; then
4242
aws s3 sync \
4343
--region us-east-2 \
4444
--no-sign-request \
45-
s3://pmm-build-cache/${cache_dir}/${rpmbuild_dist}/${spec_name}-${rpm_version} \
45+
s3://pmm-build-cache/${s3_cache_dir}/${rpmbuild_dist}/${spec_name}-${rpm_version} \
4646
${rpms_dir}/${spec_name}-${rpm_version}
4747
fi
4848

@@ -102,7 +102,7 @@ build() {
102102
local rpm_version=$(get_rpm_version "${spec_name}")
103103
local CH_VERSION=${rpm_version%-*}
104104
local CH_TAG=${rpm_version#*-}
105-
local cache_dir=RELEASE
105+
local s3_cache_dir=RELEASE
106106
local volume_mounts="-v ${rpmbuild_dir}/SOURCES:/home/builder/rpm/SOURCES -v ${rpms_dir}:/home/builder/rpm/RPMS"
107107

108108
if ! is_build_needed "${spec_name}" "${rpm_version}"; then
@@ -170,12 +170,12 @@ build() {
170170
fi
171171

172172
if [ "$RPM_EPOCH" = 1 ]; then
173-
cache_dir=PR-BUILDS
173+
s3_cache_dir=PR-BUILDS
174174
fi
175175
aws s3 sync \
176176
--region us-east-2 \
177177
${rpms_dir}/${spec_name}-${rpm_version} \
178-
s3://pmm-build-cache/${cache_dir}/${rpmbuild_dist}/${spec_name}-${rpm_version} \
178+
s3://pmm-build-cache/${s3_cache_dir}/${rpmbuild_dist}/${spec_name}-${rpm_version} \
179179
|| :
180180

181181
echo "Finished building Server RPMs, spec_name: ${spec_name}.spec, repo_name: ${repo_name}"

build/scripts/build-server-rpm-script

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o xtrace
5+
6+
. $(dirname $0)/vars
7+
8+
sudo chown -R builder:builder /home/builder/rpm/RPMS /home/builder/rpm/SOURCES /home/builder/.cache
9+
10+
# Add 'Epoch' to spec file to prevent update of rpms which are built in PR build
11+
if [ ${RPM_EPOCH} = 1 ]; then
12+
sed -i '/^Version:.*/i Epoch: 1' /home/builder/rpm/SOURCES/${spec_name}.spec
13+
fi
14+
15+
rm -rf /home/builder/rpm/RPMS/${spec_name}-*
16+
17+
printf '[local]\nname=local\nbaseurl=file:///home/builder/rpm/RPMS\ngpgcheck=0\nenabled=1\n' \
18+
| sudo tee /etc/yum.repos.d/local.repo
19+
20+
until /usr/bin/createrepo_c --update /home/builder/rpm/RPMS; do
21+
echo waiting
22+
sleep 1
23+
done
24+
25+
# Only these two specs have build dependencies
26+
if [[ ${spec_name} =~ ^grafana$|^percona-dashboards$ ]]; then
27+
sleep 5s
28+
sudo yum-builddep -y SOURCES/${spec_name}.spec
29+
fi
30+
31+
spectool -C SOURCES -g SOURCES/${spec_name}.spec
32+
rpmbuild --define '_rpmdir %{_topdir}/RPMS/${spec_name}-${rpm_version}' \
33+
--define 'dist .${rpmbuild_dist}' \
34+
--define 'debug_package %{nil}' \
35+
-ba SOURCES/${spec_name}.spec
36+
37+
rm -f SOURCES/${spec_name}.spec*
38+
sudo chown -R builder:builder /home/builder/rpm/RPMS /home/builder/rpm/SOURCES
39+
40+
# vim: expandtab shiftwidth=4 tabstop=4

0 commit comments

Comments
 (0)