Skip to content

Commit dd550c5

Browse files
committed
Introduce pyroscope packaging via nfpm
Signed-off-by: Wilfried Roset <[email protected]>
1 parent a9c9c28 commit dd550c5

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,6 @@ docs/%:
421421
.PHONY: run
422422
run: ## Run the pyroscope binary (pass parameters with 'make run PARAMS=-myparam')
423423
./pyroscope $(PARAMS)
424+
425+
packages: build
426+
@tools/packaging/nfpm.sh

tools/packaging/nfpm.jsonnet

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local overrides = {
2+
profilecli: {
3+
description:
4+
|||
5+
profilecli is the command-line interface to pyroscope.
6+
|||,
7+
},
8+
9+
pyroscope: {
10+
description: |||
11+
Grafana Pyroscope is an open source software project for aggregating continuous
12+
profiling data. Continuous profiling is an observability signal that allows you
13+
to understand your workload's resources (CPU, memory, etc...) usage down to the
14+
line number.
15+
|||,
16+
contents+: [
17+
{
18+
src: './tools/packaging/pyroscope.service',
19+
dst: '/etc/systemd/system/pyroscope.service',
20+
},
21+
{
22+
src: './cmd/pyroscope/pyroscope.yaml',
23+
dst: '/etc/pyroscope/config.yml',
24+
type: 'config|noreplace',
25+
},
26+
],
27+
scripts: {
28+
postinstall: './tools/packaging/postinstall.sh',
29+
},
30+
},
31+
};
32+
33+
local name = std.extVar('name');
34+
local arch = std.extVar('arch');
35+
local suffix = std.extVar('suffix');
36+
37+
{
38+
name: name,
39+
arch: arch,
40+
platform: 'linux',
41+
version: '${DRONE_TAG}',
42+
section: 'default',
43+
provides: [name],
44+
maintainer: 'Grafana Labs <[email protected]>',
45+
vendor: 'Grafana Labs Inc',
46+
homepage: 'https://grafana.com/pyroscope',
47+
license: 'AGPL-3.0',
48+
contents: [{
49+
src: './dist/%s_linux_%s%s/%s' % [name, arch, suffix, name],
50+
dst: '/usr/bin/%s' % name,
51+
}],
52+
} + overrides[name]

tools/packaging/nfpm.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z "${NFPM_SIGNING_KEY_FILE}" ]]; then
4+
echo "NFPM_SIGNING_KEY_FILE is not set"
5+
exit 1
6+
fi
7+
if [[ -z "${NFPM_PASSPHRASE}" ]]; then
8+
echo "NFPM_PASSPHRASE is not set"
9+
exit 1
10+
fi
11+
12+
rm -rf dist/tmp && mkdir -p dist/tmp/packages
13+
14+
for name in pyroscope profilecli; do
15+
for arch in amd64 arm64; do
16+
config_path="dist/tmp/config-${name}-${arch}.json"
17+
suffix=""
18+
if [ $arch = "amd64" ]; then
19+
suffix="_v1"
20+
fi
21+
jsonnet -V "name=${name}" -V "arch=${arch}" -V "suffix=${suffix}" "tools/packaging/nfpm.jsonnet" >"${config_path}"
22+
nfpm package -f "${config_path}" -p rpm -t dist/
23+
nfpm package -f "${config_path}" -p deb -t dist/
24+
done
25+
done
26+
27+
rm -rf dist/tmp

tools/packaging/postinstall.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/sh
2+
3+
# Based on https://nfpm.goreleaser.com/tips/
4+
5+
if ! command -V systemctl >/dev/null 2>&1; then
6+
echo "Could not find systemd. Skipping system installation." && exit 0
7+
else
8+
systemd_version=$(systemctl --version | awk '/systemd /{print $2}')
9+
fi
10+
11+
cleanInstall() {
12+
printf "\033[32m Post Install of a clean install\033[0m\n"
13+
14+
# Create the user
15+
if ! id pyroscope > /dev/null 2>&1 ; then
16+
adduser --system --shell /bin/false "pyroscope"
17+
fi
18+
19+
# rhel/centos7 cannot use ExecStartPre=+ to specify the pre start should be run as root
20+
# even if you want your service to run as non root.
21+
if [ "${systemd_version}" -lt 231 ]; then
22+
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
23+
sed -i "s/=+/=/g" /etc/systemd/system/pyroscope.service
24+
fi
25+
printf "\033[32m Reload the service unit from disk\033[0m\n"
26+
systemctl daemon-reload ||:
27+
printf "\033[32m Unmask the service\033[0m\n"
28+
systemctl unmask pyroscope ||:
29+
printf "\033[32m Set the preset flag for the service unit\033[0m\n"
30+
systemctl preset pyroscope ||:
31+
printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
32+
systemctl enable pyroscope ||:
33+
systemctl restart pyroscope ||:
34+
}
35+
36+
upgrade() {
37+
:
38+
# printf "\033[32m Post Install of an upgrade\033[0m\n"
39+
}
40+
41+
action="$1"
42+
if [ "$1" = "configure" ] && [ -z "$2" ]; then
43+
# Alpine linux does not pass args, and deb passes $1=configure
44+
action="install"
45+
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
46+
# deb passes $1=configure $2=<current version>
47+
action="upgrade"
48+
fi
49+
50+
case "${action}" in
51+
"1" | "install")
52+
cleanInstall
53+
;;
54+
"2" | "upgrade")
55+
upgrade
56+
;;
57+
*)
58+
# $1 == version being installed
59+
printf "\033[32m Alpine\033[0m"
60+
cleanInstall
61+
;;
62+
esac

tools/packaging/pyroscope.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Pyroscope service
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=pyroscope
8+
ExecStart=/usr/bin/pyroscope -config.file /etc/pyroscope/config.yml
9+
# Give a reasonable amount of time for the server to start up/shut down
10+
TimeoutSec = 120
11+
Restart = on-failure
12+
RestartSec = 2
13+
14+
[Install]
15+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)