Skip to content

Introduce pyroscope packaging via nfpm #2424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ docker_manifests:
- grafana/{{ .ProjectName }}:latest-arm64v8
- grafana/{{ .ProjectName }}:latest-armv6
- grafana/{{ .ProjectName }}:latest-armv7
nfpms:
- id: pyroscope
formats:
- deb
- rpm
section: default
maintainer: Grafana Labs <[email protected]>
vendor: Grafana Labs Inc
homepage: https://grafana.com/pyroscope
license: AGPL-3.0
contents:
- src: ./tools/packaging/pyroscope.service
dst: /etc/systemd/system/pyroscope.service
- src: ./cmd/pyroscope/pyroscope.yaml
dst: /etc/pyroscope/config.yml
type: config|noreplace
scripts:
postinstall: ./tools/packaging/postinstall.sh

archives:
- id: pyroscope
builds:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ $(BIN)/updater: Makefile

$(BIN)/goreleaser: Makefile go.mod
@mkdir -p $(@D)
GOBIN=$(abspath $(@D)) $(GO) install github.com/goreleaser/goreleaser@v1.14.1
GOBIN=$(abspath $(@D)) $(GO) install github.com/goreleaser/goreleaser@v1.20.0

$(BIN)/gotestsum: Makefile go.mod
@mkdir -p $(@D)
Expand Down
62 changes: 62 additions & 0 deletions tools/packaging/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

# Based on https://nfpm.goreleaser.com/tips/

if ! command -V systemctl >/dev/null 2>&1; then
echo "Could not find systemd. Skipping system installation." && exit 0
else
systemd_version=$(systemctl --version | awk '/systemd /{print $2}')
fi

cleanInstall() {
printf "\033[32m Post Install of a clean install\033[0m\n"

# Create the user
if ! id pyroscope > /dev/null 2>&1 ; then
adduser --system --shell /bin/false "pyroscope"
fi

# rhel/centos7 cannot use ExecStartPre=+ to specify the pre start should be run as root
# even if you want your service to run as non root.
if [ "${systemd_version}" -lt 231 ]; then
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
sed -i "s/=+/=/g" /etc/systemd/system/pyroscope.service
fi
printf "\033[32m Reload the service unit from disk\033[0m\n"
systemctl daemon-reload ||:
printf "\033[32m Unmask the service\033[0m\n"
systemctl unmask pyroscope ||:
printf "\033[32m Set the preset flag for the service unit\033[0m\n"
systemctl preset pyroscope ||:
printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
systemctl enable pyroscope ||:
systemctl restart pyroscope ||:
}

upgrade() {
:
# printf "\033[32m Post Install of an upgrade\033[0m\n"
}

action="$1"
if [ "$1" = "configure" ] && [ -z "$2" ]; then
# Alpine linux does not pass args, and deb passes $1=configure
action="install"
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
# deb passes $1=configure $2=<current version>
action="upgrade"
fi

case "${action}" in
"1" | "install")
cleanInstall
;;
"2" | "upgrade")
upgrade
;;
*)
# $1 == version being installed
printf "\033[32m Alpine\033[0m"
cleanInstall
;;
esac
15 changes: 15 additions & 0 deletions tools/packaging/pyroscope.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Pyroscope service
After=network.target

[Service]
Type=simple
User=pyroscope
ExecStart=/usr/bin/pyroscope -config.file /etc/pyroscope/config.yml
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec = 120
Restart = on-failure
RestartSec = 2

[Install]
WantedBy=multi-user.target