Upgrading prometheus from 2.36.0 to 2.37.0 (#4144)

This commit is contained in:
osamaesmailmsft 2023-01-18 17:04:39 -08:00 коммит произвёл GitHub
Родитель 36d157dd81
Коммит 9df5e2a7bb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 168 добавлений и 41 удалений

Просмотреть файл

@ -0,0 +1,143 @@
#!/bin/bash
# The flow of this script is as such:
# 1. Download prometheus tarball to a temp working directory and extract it.
# 2. Parse prometheus's Makefile.common and grep the promu version from it.
# 3. Make a temp subfolder for the promu vendor cache.
# 4. Download promu & extract it, then build it with `make build`. Then save the go vendor cache.
# 5. Copy the vendor folder from promu to our temp subfolder, then delete the built promu & extract the source tarball again.
# 6. Copy the vendor folder back into the extract promu folder and remove the temp subfolder.
# 7. Reinitialize the temp subfolder and switch back to prometheus. We modify web/ui to add an npm cache, and we modify Makefile.common's promu build to use our local tarball instead of the remote prom.
# 8. Then we run make build on prometheus, and save the go vendor cache after that.
# 9. We copy our npm cache and go vendor cache to the temp subfolder & remove our built prometheus. We re-extract the source tarball and copy the npm cache & go vendor cache into prometheus.
# 10. Make some changes to Makefile.common again and compress our custom prometheus and promu folders into their respective tarballs.
# 11. Print SHA256 of prometheus and promu tarballs
set -e
SRC_TARBALL=""
OUT_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PKG_VERSION=""
# parameters:
#
# --srcTarball : src tarball file
# this file contains the 'initial' source code of the component
# and should be replaced with the new/modified src code
# --outFolder : folder where to copy the new tarball(s)
# --pkgVersion : package version
#
PARAMS=""
while (( "$#" )); do
case "$1" in
--srcTarball)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
SRC_TARBALL=$2
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
--outFolder)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
OUT_FOLDER=$2
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
--pkgVersion)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
PKG_VERSION=$2
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
echo "--srcTarball -> $SRC_TARBALL"
echo "--outFolder -> $OUT_FOLDER"
echo "--pkgVersion -> $PKG_VERSION"
if [ -z "$PKG_VERSION" ]; then
echo "--pkgVersion parameter cannot be empty"
exit 1
fi
echo "-- create temp folder"
TEMPDIR=$(mktemp -d)
function cleanup {
echo "+++ cleanup -> remove $TEMPDIR"
rm -rf $TEMPDIR
}
trap cleanup EXIT
echo "Starting Prometheus source tarball creation"
PROMETHEUS_VERSION=$PKG_VERSION
PROMETHEUS_URL="https://github.com/prometheus/prometheus/archive/refs/tags/v$PROMETHEUS_VERSION.tar.gz"
cd "$TEMPDIR"
wget -c $PROMETHEUS_URL -O "prometheus-$PROMETHEUS_VERSION.tar.gz"
tar -xzf "prometheus-$PROMETHEUS_VERSION.tar.gz"
#PROMU_VERSION is found in prometheus-$PROMETHEUS_VERSION/Makefile.common
PROMU_VERSION=$(cat "prometheus-$PROMETHEUS_VERSION/Makefile.common" | grep "PROMU_VERSION ?= " | cut -d' ' -f3)
PROMU_URL="https://github.com/prometheus/promu/archive/refs/tags/v$PROMU_VERSION.tar.gz"
mkdir temp_vendor
wget -c $PROMU_URL -O "promu-$PROMU_VERSION.tar.gz"
tar -xzf "promu-$PROMU_VERSION.tar.gz"
cd "promu-$PROMU_VERSION"
make build
go mod vendor
cp -r vendor "$TEMPDIR/temp_vendor"
cd "$TEMPDIR"
rm -rf "promu-$PROMU_VERSION"
tar -xzf "promu-$PROMU_VERSION.tar.gz"
cp -r "temp_vendor/vendor" "promu-$PROMU_VERSION"
rm -rf "temp_vendor"
echo "cache=.npm_cache" > "prometheus-$PROMETHEUS_VERSION/web/ui/.npmrc"
sed -i "s/\$(eval PROMU_TMP := \$(shell mktemp -d))/cd ..\/promu-\$(PROMU_VERSION)/g" prometheus-$PROMETHEUS_VERSION/Makefile.common
sed -i "s/curl -s -L \$(PROMU_URL) | tar -xvzf - -C \$(PROMU_TMP)/make build/g" prometheus-$PROMETHEUS_VERSION/Makefile.common
sed -i "s/cp \$(PROMU_TMP)\/promu-\$(PROMU_VERSION).\$(GO_BUILD_PLATFORM)\/promu/cp promu-\$(PROMU_VERSION)/g" prometheus-$PROMETHEUS_VERSION/Makefile.common
sed -i "s/rm -r \$(PROMU_TMP)//g" prometheus-$PROMETHEUS_VERSION/Makefile.common
mkdir temp_vendor
cd "prometheus-$PROMETHEUS_VERSION"
make build
go mod vendor
cd "$TEMPDIR"
cp -r "prometheus-$PROMETHEUS_VERSION/vendor" temp_vendor
cp "prometheus-$PROMETHEUS_VERSION/web/ui/.npmrc" temp_vendor
cp -r "prometheus-$PROMETHEUS_VERSION/web/ui/.npm_cache" temp_vendor
rm -rf "prometheus-$PROMETHEUS_VERSION"
tar -xzf "prometheus-$PROMETHEUS_VERSION.tar.gz"
cp -r "temp_vendor/vendor" "prometheus-$PROMETHEUS_VERSION"
cp "temp_vendor/.npmrc" "prometheus-$PROMETHEUS_VERSION/web/ui"
cp -r "temp_vendor/.npm_cache" "prometheus-$PROMETHEUS_VERSION/web/ui"
rm -rf "temp_vendor"
sed -i "s/\$(eval PROMU_TMP := \$(shell mktemp -d))/cd ..\/promu-\$(PROMU_VERSION)/g" prometheus-$PROMETHEUS_VERSION/Makefile.common
sed -i "s/curl -s -L \$(PROMU_URL) | tar -xvzf - -C \$(PROMU_TMP)//g" prometheus-$PROMETHEUS_VERSION/Makefile.common
sed -i "s/cp \$(PROMU_TMP)\/promu-\$(PROMU_VERSION).\$(GO_BUILD_PLATFORM)\/promu/cp promu-\$(PROMU_VERSION)/g" prometheus-$PROMETHEUS_VERSION/Makefile.common
sed -i "s/rm -r \$(PROMU_TMP)//g" prometheus-$PROMETHEUS_VERSION/Makefile.common
tar -czf "$OUT_FOLDER/prometheus-$PROMETHEUS_VERSION.tar.gz" prometheus-$PROMETHEUS_VERSION
tar -czf "$OUT_FOLDER/promu-$PROMU_VERSION.tar.gz" promu-$PROMU_VERSION
echo "Source tarball $OUT_FOLDER/prometheus-$PROMETHEUS_VERSION.tar.gz successfully created!"

Просмотреть файл

@ -1,12 +1,11 @@
{
"Signatures": {
"prometheus-2.36.0-vendor.tar.gz": "917be21aabee4404b05115d70d986784807f85e309a469115a87c73b0e0b8319",
"prometheus-2.36.0.tar.gz": "c7b3b17edc22f93c4573b42c7c892123036b518f6058a0a97637b4190f74bc3f",
"prometheus-2.37.0.tar.gz": "98892e82b97004a458e81f03d804859d485323af2d85c34f8a996e25fe1305a9",
"prometheus.conf": "ce522e82dfb2945c520b482b15b5cf591364f7a571f0f28259b64dbeda42b043",
"prometheus.logrotate": "061b92500cd40fcaaf486ff488bcf1b09eac6743d8e840ba6966dc70d4e2067b",
"prometheus.service": "29bf1c886e1d55080e859f2afe112bb7344490e6992e946efe3360fd94d1a604",
"prometheus.sysconfig": "ec89a45641e3411478794106246aa91e7b72f86070a28a4782e3b8be955e4587",
"prometheus.yml": "0112e0bf54660c5e2391fff11a56404a25684c588caa7281677f7f8e19da6f28",
"web-ui-2.36.0.tar.gz": "2be8c2c90dcda39f21c5ef0ce05fcbf1667fbfa53d63930048b84cdb1b2e1044"
"promu-0.13.0.tar.gz": "3473b87214968c79158f553228baef6e9a37ed3e11e1a4f3e7267ffd3180a8b6"
}
}

Просмотреть файл

@ -1,37 +1,27 @@
%global builddate $(date +"%%Y%%m%%d-%%T")
%global commit_version "d48f381d9a4e68c83283ce5233844807dfdc5ba5"
Name: prometheus
Version: 2.36.0
Release: 5%{?dist}
# When upgrading Prometheus, run `./generate_source_tarball.sh --pkgVersion <version>`
# The script will spit out custom tarballs for `prometheus` and `promu` (More details in the script)
%global promu_version 0.13.0
Summary: Prometheus monitoring system and time series database
Name: prometheus
Version: 2.37.0
Release: 1%{?dist}
License: ASL 2.0
Vendor: Microsoft Corporation
Distribution: Mariner
License: ASL 2.0
URL: https://github.com/prometheus/prometheus
Source0: https://github.com/prometheus/prometheus/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
# unzip Source0
# run 'make build' in it
# tar --sort=name \
# --mtime="2021-04-26 00:00Z" \
# --owner=0 --group=0 --numeric-owner \
# --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
# -cf web-ui-%%{version}.tar.gz web/ui
Source10: web-ui-%{version}.tar.gz
Source1: prometheus.service
Source2: prometheus.sysconfig
Source3: prometheus.yml
Source4: prometheus.conf
Source5: prometheus.logrotate
# On version updates run "toolkit/scripts/build_go_vendor_cache.sh %%{name}-%%{version}.tar.gz"
Source6: %{name}-%{version}-vendor.tar.gz
Source6: promu-%{promu_version}.tar.gz
# Debian patch for default settings
Patch0: 02-Default_settings.patch
BuildRequires: systemd-rpm-macros
BuildRequires: golang
Requires(pre): /usr/bin/systemd-sysusers
BuildRequires: nodejs
BuildRequires: systemd-rpm-macros
Requires(pre): %{_bindir}/systemd-sysusers
%description
The Prometheus monitoring system and time series database
@ -40,21 +30,11 @@ The Prometheus monitoring system and time series database
%autosetup -p1
%build
rm -rf web/ui
tar -xf %{SOURCE10}
rm -rf vendor
tar -xf %{SOURCE6} --no-same-owner
export LDFLAGS="-X github.com/prometheus/common/version.Version=%{version} \
-X github.com/prometheus/common/version.Revision=%{commit_version} \
-X github.com/prometheus/common/version.Branch=master \
-X github.com/prometheus/common/version.BuildUser=mockbuild \
-X github.com/prometheus/common/version.BuildDate=%{builddate} "
export BUILDTAGS="netgo builtinassets"
for cmd in cmd/* ; do
go build -ldflags "$LDFLAGS" -mod=vendor -v -a -tags "$BUILDTAGS" -o $(basename $cmd) ./$cmd
done
tar -xf %{SOURCE6} -C ..
cd ../promu-%{promu_version}
make build
cd ../%{name}-%{version}
make build
%install
install -m 0755 -vd %{buildroot}%{_bindir}
@ -142,6 +122,11 @@ fi
%attr(0755,prometheus,prometheus) %{_sharedstatedir}/prometheus
%changelog
* Tue Jan 18 2022 Osama Esmail <osamaesmail@microsoft.com> - 2.37.0-1
- Upgrade to LTS v2.37.0 (next LTS is v2.41.0)
- Created generate_source_tarball.sh for handling the custom tarballs for prometheus/promu
- Simplified %build section to use the custom tarballs
* Fri Dec 16 2022 Daniel McIlvaney <damcilva@microsoft.com> - 2.36.0-5
- Bump release to rebuild with go 1.18.8 with patch for CVE-2022-41717

Просмотреть файл

@ -20204,8 +20204,8 @@
"type": "other",
"other": {
"name": "prometheus",
"version": "2.36.0",
"downloadUrl": "https://github.com/prometheus/prometheus/archive/refs/tags/v2.36.0.tar.gz"
"version": "2.37.0",
"downloadUrl": "https://github.com/prometheus/prometheus/archive/refs/tags/v2.37.0.tar.gz"
}
}
},