mirror of https://github.com/grafana/loki
deb and rpm packaging for all binaries (#6456)
* deb and rpm packaging for all binaries There is currently deb and rpm packages being published for logcli amd64 but they aren't signed In this PR: - Add RPM and deb packages for `logcli`, `loki-canary` `loki` and `promtail` for arm, arm64 and amd64 - Sign them with the Grafana GPG key (packages.grafana.com/gpg.key). This will be the same key for all Grafana products - Add CI steps to test the RPM and deb packages. This launches a docker image with systemd installed, then it installs both loki and promtail and does a `logcli` query on the Loki instance * Remove specific version in test scripts * Bump build image to 0.22.0 * Add restart policy for promtail's servicepull/6820/head
parent
c5daa31b65
commit
7b70d3d939
@ -1,18 +0,0 @@ |
|||||||
--- |
|
||||||
name: "logcli" |
|
||||||
arch: "amd64" |
|
||||||
platform: "linux" |
|
||||||
version: ${DRONE_TAG} |
|
||||||
section: "default" |
|
||||||
provides: |
|
||||||
- logcli |
|
||||||
maintainer: "Grafana Labs <support@grafana.com>" |
|
||||||
description: | |
|
||||||
LogCLI is the command-line interface to Loki. |
|
||||||
It facilitates running LogQL queries against a Loki instance. |
|
||||||
vendor: "Grafana Labs Inc" |
|
||||||
homepage: "https://grafana.com/loki" |
|
||||||
license: "AGPL-3.0" |
|
||||||
contents: |
|
||||||
- src: ./dist/tmp/logcli-linux-amd64 |
|
||||||
dst: /usr/local/bin/logcli |
|
||||||
@ -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 | head -1 | sed 's/systemd //g') |
||||||
|
fi |
||||||
|
|
||||||
|
cleanInstall() { |
||||||
|
printf "\033[32m Post Install of a clean install\033[0m\n" |
||||||
|
|
||||||
|
# Create the user |
||||||
|
if ! id loki > /dev/null 2>&1 ; then |
||||||
|
adduser --system --shell /bin/false "loki" |
||||||
|
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/loki.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 loki ||: |
||||||
|
printf "\033[32m Set the preset flag for the service unit\033[0m\n" |
||||||
|
systemctl preset loki ||: |
||||||
|
printf "\033[32m Set the enabled flag for the service unit\033[0m\n" |
||||||
|
systemctl enable loki ||: |
||||||
|
systemctl restart loki ||: |
||||||
|
} |
||||||
|
|
||||||
|
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 |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
[Unit] |
||||||
|
Description=Loki service |
||||||
|
After=network.target |
||||||
|
|
||||||
|
[Service] |
||||||
|
Type=simple |
||||||
|
User=loki |
||||||
|
ExecStart=/usr/bin/loki -config.file /etc/loki/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 |
||||||
@ -0,0 +1,90 @@ |
|||||||
|
local overrides = { |
||||||
|
logcli: { |
||||||
|
description: |
||||||
|
||| |
||||||
|
LogCLI is the command-line interface to Loki. |
||||||
|
It facilitates running LogQL queries against a Loki instance. |
||||||
|
|||, |
||||||
|
}, |
||||||
|
|
||||||
|
'loki-canary': { |
||||||
|
description: 'Loki Canary is a standalone app that audits the log-capturing performance of a Grafana Loki cluster.', |
||||||
|
}, |
||||||
|
|
||||||
|
loki: { |
||||||
|
description: ||| |
||||||
|
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. |
||||||
|
It is designed to be very cost effective and easy to operate. |
||||||
|
It does not index the contents of the logs, but rather a set of labels for each log stream. |
||||||
|
|||, |
||||||
|
contents+: [ |
||||||
|
{ |
||||||
|
src: './tools/packaging/loki.service', |
||||||
|
dst: '/etc/systemd/system/loki.service', |
||||||
|
}, |
||||||
|
{ |
||||||
|
src: './cmd/loki/loki-local-config.yaml', |
||||||
|
dst: '/etc/loki/config.yml', |
||||||
|
type: 'config|noreplace', |
||||||
|
}, |
||||||
|
], |
||||||
|
scripts: { |
||||||
|
postinstall: './tools/packaging/loki-postinstall.sh', |
||||||
|
}, |
||||||
|
}, |
||||||
|
|
||||||
|
promtail: { |
||||||
|
description: ||| |
||||||
|
Promtail is an agent which ships the contents of local logs to a private Grafana Loki instance or Grafana Cloud. |
||||||
|
It is usually deployed to every machine that has applications needed to be monitored. |
||||||
|
|||, |
||||||
|
license: 'Apache-2.0', |
||||||
|
contents+: [ |
||||||
|
{ |
||||||
|
src: './tools/packaging/promtail.service', |
||||||
|
dst: '/etc/systemd/system/promtail.service', |
||||||
|
}, |
||||||
|
{ |
||||||
|
src: './clients/cmd/promtail/promtail-local-config.yaml', |
||||||
|
dst: '/etc/promtail/config.yml', |
||||||
|
type: 'config|noreplace', |
||||||
|
}, |
||||||
|
], |
||||||
|
scripts: { |
||||||
|
postinstall: './tools/packaging/promtail-postinstall.sh', |
||||||
|
}, |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
local name = std.extVar('name'); |
||||||
|
local arch = std.extVar('arch'); |
||||||
|
|
||||||
|
{ |
||||||
|
name: name, |
||||||
|
arch: arch, |
||||||
|
platform: 'linux', |
||||||
|
version: '${DRONE_TAG}', |
||||||
|
section: 'default', |
||||||
|
provides: [name], |
||||||
|
maintainer: 'Grafana Labs <support@grafana.com>', |
||||||
|
vendor: 'Grafana Labs Inc', |
||||||
|
homepage: 'https://grafana.com/loki', |
||||||
|
license: 'AGPL-3.0', |
||||||
|
contents: [{ |
||||||
|
src: './dist/tmp/packages/%s-linux-%s' % [name, arch], |
||||||
|
dst: '/usr/bin/%s' % name, |
||||||
|
}], |
||||||
|
|
||||||
|
deb: { |
||||||
|
signature: { |
||||||
|
// Also set ${NFPM_PASSPHRASE} |
||||||
|
key_file: '${NFPM_SIGNING_KEY_FILE}', |
||||||
|
}, |
||||||
|
}, |
||||||
|
rpm: { |
||||||
|
signature: { |
||||||
|
// Also set ${NFPM_PASSPHRASE} |
||||||
|
key_file: '${NFPM_SIGNING_KEY_FILE}', |
||||||
|
}, |
||||||
|
}, |
||||||
|
} + overrides[name] |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
|
||||||
|
if [[ -z "${NFPM_SIGNING_KEY_FILE}" ]]; then |
||||||
|
echo "NFPM_SIGNING_KEY_FILE is not set" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
if [[ -z "${NFPM_PASSPHRASE}" ]]; then |
||||||
|
echo "NFPM_PASSPHRASE is not set" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
rm -rf dist/tmp && mkdir -p dist/tmp/packages |
||||||
|
unzip dist/\*.zip -d dist/tmp/packages |
||||||
|
|
||||||
|
for name in loki loki-canary logcli promtail; do |
||||||
|
for arch in amd64 arm64 arm; do |
||||||
|
config_path="dist/tmp/config-${name}-${arch}.json" |
||||||
|
jsonnet -V "name=${name}" -V "arch=${arch}" "tools/packaging/nfpm.jsonnet" > "${config_path}" |
||||||
|
nfpm package -f "${config_path}" -p rpm -t dist/ |
||||||
|
nfpm package -f "${config_path}" -p deb -t dist/ |
||||||
|
done |
||||||
|
done |
||||||
|
|
||||||
|
rm -rf dist/tmp |
||||||
@ -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 | head -1 | sed 's/systemd //g') |
||||||
|
fi |
||||||
|
|
||||||
|
cleanInstall() { |
||||||
|
printf "\033[32m Post Install of a clean install\033[0m\n" |
||||||
|
|
||||||
|
# Create the user |
||||||
|
if ! id promtail > /dev/null 2>&1 ; then |
||||||
|
adduser --system --shell /bin/false "promtail" |
||||||
|
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/promtail.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 promtail ||: |
||||||
|
printf "\033[32m Set the preset flag for the service unit\033[0m\n" |
||||||
|
systemctl preset promtail ||: |
||||||
|
printf "\033[32m Set the enabled flag for the service unit\033[0m\n" |
||||||
|
systemctl enable promtail ||: |
||||||
|
systemctl restart promtail ||: |
||||||
|
} |
||||||
|
|
||||||
|
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 |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
[Unit] |
||||||
|
Description=Promtail service |
||||||
|
After=network.target |
||||||
|
|
||||||
|
[Service] |
||||||
|
Type=simple |
||||||
|
User=promtail |
||||||
|
ExecStart=/usr/bin/promtail -config.file /etc/promtail/config.yml |
||||||
|
# Give a reasonable amount of time for promtail to start up/shut down |
||||||
|
TimeoutSec = 60 |
||||||
|
Restart = on-failure |
||||||
|
RestartSec = 2 |
||||||
|
|
||||||
|
[Install] |
||||||
|
WantedBy=multi-user.target |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
docker ps |
||||||
|
image="$(docker ps --filter ancestor=jrei/systemd-debian:12 --latest --format "{{.ID}}")" |
||||||
|
echo "Running on container: ${image}" |
||||||
|
|
||||||
|
dir="." |
||||||
|
if [ -n "${CI}" ]; then |
||||||
|
dir="/drone/src" |
||||||
|
fi |
||||||
|
echo "Running on directory: ${dir}" |
||||||
|
|
||||||
|
cat <<EOF | docker exec --interactive "${image}" sh |
||||||
|
# Install loki and check it's running |
||||||
|
dpkg -i ${dir}/dist/loki_*_amd64.deb |
||||||
|
[ "\$(systemctl is-active loki)" = "active" ] || (echo "loki is inactive" && exit 1) |
||||||
|
|
||||||
|
# Install promtail and check it's running |
||||||
|
dpkg -i ${dir}/dist/promtail_*_amd64.deb |
||||||
|
[ "\$(systemctl is-active promtail)" = "active" ] || (echo "promtail is inactive" && exit 1) |
||||||
|
|
||||||
|
# Write some logs |
||||||
|
mkdir -p /var/log/ |
||||||
|
echo "blablabla" > /var/log/test.log |
||||||
|
|
||||||
|
# Install logcli |
||||||
|
dpkg -i ${dir}/dist/logcli_*_amd64.deb |
||||||
|
|
||||||
|
# Check that there are labels |
||||||
|
sleep 5 |
||||||
|
labels_found=\$(logcli labels) |
||||||
|
echo "Found labels: \$labels_found" |
||||||
|
[ "\$labels_found" != "" ] || (echo "no logs found with logcli" && exit 1) |
||||||
|
EOF |
||||||
@ -0,0 +1,37 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
docker ps |
||||||
|
image="$(docker ps --filter ancestor=jrei/systemd-centos:8 --latest --format "{{.ID}}")" |
||||||
|
echo "Running on container: ${image}" |
||||||
|
|
||||||
|
dir="." |
||||||
|
if [ -n "${CI}" ]; then |
||||||
|
dir="/drone/src" |
||||||
|
fi |
||||||
|
echo "Running on directory: ${dir}" |
||||||
|
|
||||||
|
cat <<EOF | docker exec --interactive "${image}" sh |
||||||
|
# Import the Grafana GPG key |
||||||
|
rpm --import https://packages.grafana.com/gpg.key |
||||||
|
|
||||||
|
# Install loki and check it's running |
||||||
|
rpm -i ${dir}/dist/loki-*.x86_64.rpm |
||||||
|
[ "\$(systemctl is-active loki)" = "active" ] || (echo "loki is inactive" && exit 1) |
||||||
|
|
||||||
|
# Install promtail and check it's running |
||||||
|
rpm -i ${dir}/dist/promtail-*.x86_64.rpm |
||||||
|
[ "\$(systemctl is-active promtail)" = "active" ] || (echo "promtail is inactive" && exit 1) |
||||||
|
|
||||||
|
# Write some logs |
||||||
|
mkdir -p /var/log/ |
||||||
|
echo "blablabla" > /var/log/test.log |
||||||
|
|
||||||
|
# Install logcli |
||||||
|
rpm -i ${dir}/dist/logcli-*.x86_64.rpm |
||||||
|
|
||||||
|
# Check that there are labels |
||||||
|
sleep 5 |
||||||
|
labels_found=\$(logcli labels) |
||||||
|
echo "Found labels: \$labels_found" |
||||||
|
[ "\$labels_found" != "" ] || (echo "no labels found with logcli" && exit 1) |
||||||
|
EOF |
||||||
Loading…
Reference in new issue