forked from open-telemetry/opentelemetry-collector-contrib
-
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.
Initial deb and rpm packaging (#405)
* wip * Initial deb and rpm packaging - Uses https://github.com/jordansissel/fpm - Adds `deb-package` and `rpm-package` targets to Makefile - Builds simple deb and rpm packages that installs the otelcontribcol binary to `/usr/bin/otelcontribcol` - Adds deb and rpm packages to circleci workspace for github release - TODO: create service scripts * Packaging updates - Add support for arm64 packages - Move files to internal/buildscripts/packaging/ - Use single Dockerfile for local deb and rpm builds - Explicitly set output dir for packages in circleci * Add systemd service to deb and rpm - Install `otel-contrib-collector` systemd service and run as `otel:otel` user:group - Add simple installation test scripts using systemd-in-docker images * Change default output dir to dist Co-authored-by: Owais Lone <[email protected]>
- Loading branch information
Showing
18 changed files
with
481 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ local/ | |
*.so | ||
*.dylib | ||
bin/ | ||
dist/ | ||
|
||
# Emacs | ||
*~ | ||
|
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,16 @@ | ||
FROM debian:9 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y ruby ruby-dev rubygems build-essential git rpm | ||
|
||
RUN gem install --no-document fpm -v 1.11.0 | ||
|
||
VOLUME /repo | ||
WORKDIR /repo | ||
|
||
ENV PACKAGE="deb" | ||
ENV VERSION="" | ||
ENV ARCH="amd64" | ||
ENV OUTPUT_DIR="/repo/dist/" | ||
|
||
CMD ./internal/buildscripts/packaging/fpm/$PACKAGE/build.sh "$VERSION" "$ARCH" "$OUTPUT_DIR" |
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,58 @@ | ||
#!/bin/bash | ||
|
||
FPM_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )" | ||
|
||
PKG_NAME="otel-contrib-collector" | ||
PKG_VENDOR="OpenTelemetry Community" | ||
PKG_MAINTAINER="OpenTelemetry Community <[email protected]>" | ||
PKG_DESCRIPTION="OpenTelemetry Contrib Collector" | ||
PKG_LICENSE="Apache 2.0" | ||
PKG_URL="https://github.com/open-telemetry/opentelemetry-collector-contrib" | ||
PKG_USER="otel" | ||
PKG_GROUP="otel" | ||
|
||
SERVICE_NAME="otel-contrib-collector" | ||
PROCESS_NAME="otelcontribcol" | ||
|
||
SERVICE_PATH="$FPM_DIR/$SERVICE_NAME.service" | ||
PREINSTALL_PATH="$FPM_DIR/preinstall.sh" | ||
POSTINSTALL_PATH="$FPM_DIR/postinstall.sh" | ||
PREUNINSTALL_PATH="$FPM_DIR/preuninstall.sh" | ||
|
||
docker_cp() { | ||
local container="$1" | ||
local src="$2" | ||
local dest="$3" | ||
local dest_dir="$( dirname "$dest" )" | ||
|
||
echo "Copying $src to $container:$dest ..." | ||
docker exec $container mkdir -p "$dest_dir" | ||
docker cp "$src" $container:"$dest" | ||
} | ||
|
||
install_pkg() { | ||
local container="$1" | ||
local pkg_path="$2" | ||
local pkg_base=$( basename "$pkg_path" ) | ||
|
||
echo "Installing $pkg_base ..." | ||
docker_cp $container "$pkg_path" /tmp/$pkg_base | ||
if [[ "${pkg_base##*.}" = "deb" ]]; then | ||
docker exec $container dpkg -i /tmp/$pkg_base | ||
else | ||
docker exec $container rpm -ivh /tmp/$pkg_base | ||
fi | ||
} | ||
|
||
uninstall_pkg() { | ||
local container="$1" | ||
local pkg_type="$2" | ||
local pkg_name="${3:-"$PKG_NAME"}" | ||
|
||
echo "Uninstalling $pkg_name ..." | ||
if [[ "$pkg_type" = "deb" ]]; then | ||
docker exec $container dpkg -r $pkg_name | ||
else | ||
docker exec $container rpm -e $pkg_name | ||
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,22 @@ | ||
# A debian9 image with systemd enabled. Must be run with: | ||
# `-d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro` flags | ||
FROM debian:9 | ||
|
||
RUN apt-get update &&\ | ||
apt-get install -yq ca-certificates procps systemd | ||
|
||
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 /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/anaconda.target.wants/*; | ||
|
||
RUN systemctl set-default multi-user.target | ||
ENV init /lib/systemd/systemd | ||
|
||
VOLUME [ "/sys/fs/cgroup" ] | ||
|
||
ENTRYPOINT ["/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,14 @@ | ||
# Build otel-contrib-collector deb package | ||
|
||
Build the otel-contrib-collector deb package with [fpm](https://github.com/jordansissel/fpm). | ||
|
||
To build the deb package, run `make deb-package` from the repo root directory. The deb package will be written to | ||
`dist/otel-contrib-collector_<version>_<arch>.deb`. | ||
|
||
By default, `<arch>` is `amd64` and `<version>` is the latest git tag with `-post` appended, e.g. `1.2.3-post`. | ||
To override these defaults, set the `ARCH` and `VERSION` environment variables, e.g. | ||
`ARCH=arm64 VERSION=4.5.6 make deb-package`. | ||
|
||
Run `./internal/buildscripts/packaging/fpm/test.sh PATH_TO_DEB_FILE [PATH_TO_CONFIG_FILE]` to run a basic installation | ||
test with the built package. `PATH_TO_CONFIG_FILE` defaults to `examples/tracing/otel-collector-config.yml` if one is | ||
not specified. |
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,35 @@ | ||
#!/bin/bash | ||
|
||
set -euxo pipefail | ||
|
||
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )" | ||
REPO_DIR="$( cd "$SCRIPT_DIR/../../../../../" && pwd )" | ||
VERSION="${1:-}" | ||
ARCH="${2:-"amd64"}" | ||
OUTPUT_DIR="${3:-"$REPO_DIR/dist/"}" | ||
OTELCONTRIBCOL_PATH="$REPO_DIR/bin/otelcontribcol_linux_$ARCH" | ||
|
||
. $SCRIPT_DIR/../common.sh | ||
|
||
if [[ -z "$VERSION" ]]; then | ||
latest_tag="$( git describe --abbrev=0 --match v[0-9]* )" | ||
VERSION="${latest_tag}-post" | ||
fi | ||
|
||
mkdir -p "$OUTPUT_DIR" | ||
|
||
fpm -s dir -t deb -n $PKG_NAME -v ${VERSION#v} -f -p "$OUTPUT_DIR" \ | ||
--vendor "$PKG_VENDOR" \ | ||
--maintainer "$PKG_MAINTAINER" \ | ||
--description "$PKG_DESCRIPTION" \ | ||
--license "$PKG_LICENSE" \ | ||
--url "$PKG_URL" \ | ||
--architecture "$ARCH" \ | ||
--deb-dist "stable" \ | ||
--deb-user "$PKG_USER" \ | ||
--deb-group "$PKG_GROUP" \ | ||
--before-install "$PREINSTALL_PATH" \ | ||
--after-install "$POSTINSTALL_PATH" \ | ||
--pre-uninstall "$PREUNINSTALL_PATH" \ | ||
$SERVICE_PATH=/lib/systemd/system/$SERVICE_NAME.service \ | ||
$OTELCONTRIBCOL_PATH=/usr/bin/otelcontribcol |
14 changes: 14 additions & 0 deletions
14
internal/buildscripts/packaging/fpm/otel-contrib-collector.service
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 @@ | ||
[Unit] | ||
Description=OpenTelemety Contrib Collector | ||
After=network.target | ||
|
||
[Service] | ||
ExecStart=/usr/bin/otelcontribcol --config /etc/otel-contrib-collector/config.yaml | ||
KillMode=mixed | ||
Restart=on-failure | ||
Type=simple | ||
User=otel | ||
Group=otel | ||
|
||
[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,8 @@ | ||
#!/bin/sh | ||
|
||
if command -v systemctl >/dev/null 2>&1; then | ||
systemctl enable otel-contrib-collector.service | ||
if [ -f /etc/otel-contrib-collector/config.yaml ]; then | ||
systemctl start otel-contrib-collector.service | ||
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,3 @@ | ||
#!/bin/sh | ||
|
||
getent passwd otel >/dev/null || useradd --system --user-group --no-create-home --shell /sbin/nologin otel |
Oops, something went wrong.