forked from cortexproject/cortex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RPM and deb packaging for cortex binary (cortexproject#2838)
* Use docker containers to build RPM and deb packages for cortex Signed-off-by: Jack Baldry <[email protected]> * Add DISABLE_CLEANUP variable to prevent the removal of testing containers Signed-off-by: Jack Baldry <[email protected]> * Updated RELEASE doc Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Marco Pracucci <[email protected]>
- Loading branch information
Showing
15 changed files
with
320 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
[ -f /etc/sysconfig/cortex ] && . /etc/default/cortex | ||
|
||
# Initial installation: $1 == configure | ||
# Upgrade: $1 == 2, and configured to restart on upgrade | ||
case "$1" in | ||
configure) | ||
[ -z "$CORTEX_USER" ] && CORTEX_USER="cortex" | ||
[ -z "$CORTEX_GROUP" ] && CORTEX_GROUP="cortex" | ||
if ! getent group "$CORTEX_GROUP" > /dev/null 2>&1 ; then | ||
groupadd -r "$CORTEX_GROUP" | ||
fi | ||
if ! getent passwd "$CORTEX_USER" > /dev/null 2>&1 ; then | ||
useradd -m -r -g cortex -d /var/lib/cortex -s /sbin/nologin -c "cortex user" cortex | ||
fi | ||
|
||
chmod 640 /etc/cortex/single-process-config.yaml | ||
chown root:$CORTEX_GROUP /etc/cortex/single-process-config.yaml | ||
|
||
if [ -z ${2+x} ] && [ "$RESTART_ON_UPGRADE" == "true" ]; then | ||
if command -v systemctl 2>/dev/null; then | ||
systemctl daemon-reload | ||
fi | ||
fi | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
[ -f /etc/default/cortex ] && . /etc/default/cortex | ||
|
||
# Final uninstallation $1=0 | ||
# If other copies of this RPM are installed, then $1>0 | ||
if [ $1 -eq 0 ] ; then | ||
if command -v systemctl 2>/dev/null; then | ||
systemctl stop cortex.service > /dev/null 2>&1 || : | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM debian:10 | ||
ENV container docker | ||
ENV LC_ALL C | ||
ENV DEBIAN_FRONTEND noninteractive | ||
RUN apt-get update \ | ||
&& apt-get install -y systemd \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
RUN rm -f /lib/systemd/system/multi-user.target.wants/* \ | ||
/etc/systemd/system/*.wants/* \ | ||
/lib/systemd/system/local-fs.target.wants/* \ | ||
/lib/systemd/system/sockets.target.wants/*udev* \ | ||
/lib/systemd/system/sockets.target.wants/*initctl* \ | ||
/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \ | ||
/lib/systemd/system/systemd-update-utmp* | ||
|
||
VOLUME [ "/sys/fs/cgroup" ] | ||
CMD ["/lib/systemd/systemd"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Log level. Valid levels: [debug, info, warn, error]. Default: "info" | ||
LOG_LEVEL="info" | ||
|
||
# Path to Cortex YAML configuration file. | ||
CONFIG_FILE="/etc/cortex/single-process-config.yaml" | ||
|
||
# Custom user defined arguments. | ||
CUSTOM_ARGS="" | ||
|
||
# Restart on system upgrade. Default: "true". | ||
RESTART_ON_UPGRADE="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=Horizontally scalable, highly available, multi-tenant, long term Prometheus. | ||
Documentation=https://cortexmetrics.io/docs | ||
Wants=network-online.target | ||
After=network-online.target | ||
|
||
[Service] | ||
Restart=always | ||
User=cortex | ||
EnvironmentFile=/etc/default/cortex | ||
ExecStart=/usr/local/bin/cortex --config.file $CONFIG_FILE --log.level $LOG_LEVEL $CUSTOM_ARGS | ||
ExecReload=/bin/kill -HUP $MAINPID | ||
TimeoutStopSec=20s | ||
SendSIGKILL=no | ||
WorkingDirectory=/var/lib/cortex | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM alpine:3.8 | ||
|
||
RUN apk add --no-cache \ | ||
ruby \ | ||
ruby-dev \ | ||
ruby-etc \ | ||
gcc \ | ||
git \ | ||
libc-dev \ | ||
libffi-dev \ | ||
make \ | ||
rpm \ | ||
tar \ | ||
&& gem install --no-ri --no-rdoc fpm | ||
|
||
COPY package.sh / | ||
ENTRYPOINT ["/package.sh"] | ||
|
||
ARG revision | ||
LABEL org.opencontainers.image.title="fpm" \ | ||
# TODO: should this label point to the fpm source code? | ||
org.opencontainers.image.source="https://github.com/cortexproject/cortex/tree/master/packaging/fpm" \ | ||
org.opencontainers.image.revision="${revision}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
SRC_PATH=/src/github.com/cortexproject/cortex | ||
|
||
# If we run make directly, any files created on the bind mount | ||
# will have awkward ownership. So we switch to a user with the | ||
# same user and group IDs as source directory. We have to set a | ||
# few things up so that sudo works without complaining later on. | ||
uid=$(stat -c "%u" $SRC_PATH) | ||
gid=$(stat -c "%g" $SRC_PATH) | ||
echo "cortex:x:$uid:$gid::$SRC_PATH:/bin/sh" >>/etc/passwd | ||
echo "cortex:*:::::::" >>/etc/shadow | ||
echo "cortex ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers | ||
|
||
su cortex -c "PATH=$PATH make -C $SRC_PATH PACKAGE_IN_CONTAINER=false $*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM centos:8 | ||
ENV container docker | ||
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \ | ||
systemd-tmpfiles-setup.service ] || rm -f $i; done); \ | ||
rm -f /lib/systemd/system/multi-user.target.wants/*; \ | ||
rm -f /etc/systemd/system/*.wants/*; \ | ||
rm -f /lib/systemd/system/local-fs.target.wants/*; \ | ||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ | ||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ | ||
rm -f /lib/systemd/system/basic.target.wants/*; \ | ||
rm -f /lib/systemd/system/anaconda.target.wants/*; | ||
|
||
VOLUME [ "/sys/fs/cgroup"] | ||
CMD ["/usr/sbin/init"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
[ -f /etc/sysconfig/cortex ] && . /etc/sysconfig/cortex | ||
|
||
# Initial installation: $1 == 1 | ||
# Upgrade: $1 == 2, and configured to restart on upgrade | ||
if [ $1 -eq 1 ] ; then | ||
[ -z "$CORTEX_USER" ] && CORTEX_USER="cortex" | ||
[ -z "$CORTEX_GROUP" ] && CORTEX_GROUP="cortex" | ||
if ! getent group "$CORTEX_GROUP" > /dev/null 2>&1 ; then | ||
groupadd -r "$CORTEX_GROUP" | ||
fi | ||
if ! getent passwd "$CORTEX_USER" > /dev/null 2>&1 ; then | ||
useradd -m -r -g cortex -d /var/lib/cortex -s /sbin/nologin -c "cortex user" cortex | ||
fi | ||
|
||
chmod 640 /etc/cortex/single-process-config.yaml | ||
chown root:$CORTEX_GROUP /etc/cortex/single-process-config.yaml | ||
|
||
elif [ $1 -ge 2 ] ; then | ||
if [ "$RESTART_ON_UPGRADE" == "true" ]; then | ||
if command -v systemctl 2>/dev/null; then | ||
systemctl daemon-reload | ||
fi | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
[ -f /etc/sysconfig/cortex ] && . /etc/sysconfig/cortex | ||
|
||
# Final uninstallation $1=0 | ||
# If other copies of this RPM are installed, then $1>0 | ||
if [ $1 -eq 0 ] ; then | ||
if command -v systemctl 2>/dev/null; then | ||
systemctl stop cortex.service > /dev/null 2>&1 || : | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Log level. Valid levels: [debug, info, warn, error]. Default: "info" | ||
LOG_LEVEL="info" | ||
|
||
# Path to Cortex YAML configuration file. | ||
CONFIG_FILE="/etc/cortex/single-process-config.yaml" | ||
|
||
# Custom user defined arguments. | ||
CUSTOM_ARGS="" | ||
|
||
# Restart on system upgrade. Default: "true". | ||
RESTART_ON_UPGRADE="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=Horizontally scalable, highly available, multi-tenant, long term Prometheus. | ||
Documentation=https://cortexmetrics.io/docs | ||
Wants=network-online.target | ||
After=network-online.target | ||
|
||
[Service] | ||
Restart=always | ||
User=cortex | ||
EnvironmentFile=/etc/sysconfig/cortex | ||
ExecStart=/usr/local/bin/cortex --config.file $CONFIG_FILE --log.level $LOG_LEVEL $CUSTOM_ARGS | ||
ExecReload=/bin/kill -HUP $MAINPID | ||
TimeoutStopSec=20s | ||
SendSIGKILL=no | ||
WorkingDirectory=/var/lib/cortex | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euf -o pipefail | ||
|
||
readonly IMAGE_PREFIX=$1 | ||
readonly VERSION=$2 | ||
readonly DISABLE_CLEANUP=${DISABLE_CLEANUP:-0} | ||
|
||
declare -a CONTAINERS=() | ||
|
||
function error() { | ||
echo "$@"; exit 1 | ||
} | ||
|
||
function cleanup() { | ||
if [[ "${DISABLE_CLEANUP}" -ne 1 ]]; then | ||
docker rm --force "${CONTAINERS[@]}" &>/dev/null | ||
fi | ||
} | ||
|
||
function ready() { | ||
local -ri max_attempts=$1 | ||
local -ri sleep_interval=$2 | ||
local -ri port=$3 | ||
local -i attempt=1 | ||
|
||
sleep "${sleep_interval}" | ||
until curl -s localhost:"${port}"/ready | grep -q ready; do | ||
if [[ ${attempt} -eq ${max_attempts} ]]; then | ||
echo "Cortex not ready in ${max_attempts} attempts" | ||
return 1 | ||
else | ||
(( attempt++ )) | ||
fi | ||
sleep "${sleep_interval}" | ||
done | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
function test_with_systemd() { | ||
local -r image=$1 | ||
local -r install_command=$2 | ||
local container | ||
|
||
container=$(docker run --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -itd -v "$(pwd)"/dist:/opt/cortex -p 9009 "${image}") | ||
CONTAINERS+=("${container}") | ||
|
||
port=$(docker inspect --format='{{(index (index .NetworkSettings.Ports "9009/tcp") 0).HostPort}}' "${container}") | ||
|
||
docker exec -it "${container}" /bin/bash -c "${install_command}; systemctl start cortex.service; systemctl enable cortex.service" | ||
|
||
ready 10 1 "${port}" || error "Testing image: ${image} with command: '${install_command}' failed" | ||
} | ||
|
||
test_with_systemd "${IMAGE_PREFIX}"debian-systemd "dpkg -i /opt/cortex/cortex-${VERSION}.deb" | ||
test_with_systemd "${IMAGE_PREFIX}"centos-systemd "rpm -i /opt/cortex/cortex-${VERSION}.rpm" |