Skip to content
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

Initial deb and rpm packaging #1278

Merged
merged 2 commits into from
Jul 8, 2020
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
53 changes: 53 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ workflows:
- coverage
- windows-test
- windows-msi
- deb-package
- rpm-package
filters:
branches:
ignore: /.*/
Expand All @@ -144,6 +146,22 @@ workflows:
filters:
tags:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/
- build-package:
name: deb-package
package_type: deb
requires:
- cross-compile
filters:
tags:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/
- build-package:
name: rpm-package
package_type: rpm
requires:
- cross-compile
filters:
tags:
only: /^v([0-9])+.([0-9])+.([0-9])+.*/

jobs:
setup-and-lint:
Expand Down Expand Up @@ -317,3 +335,38 @@ jobs:
- persist_to_workspace:
root: ~/
paths: project/bin

build-package:
executor: golang
parameters:
package_type:
type: enum
enum: ["deb", "rpm"]
steps:
- checkout
- attach_to_workspace
- run:
name: Install fpm and dependencies
command: |
sudo apt-get update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should an upgrade happen here as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upgrade upgrades other deps, update just refreshes the repositories.

sudo apt-get install -y ruby ruby-dev rubygems build-essential rpm
sudo gem install --no-document fpm -v 1.11.0
- run:
name: Build << parameters.package_type >> amd64 package
command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "amd64" "./bin/"
- run:
name: Build << parameters.package_type >> arm64 package
command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "arm64" "./bin/"
- run:
name: Test << parameters.package_type >> package installation
command: |
if [[ "<< parameters.package_type >>" = "deb" ]]; then
sudo dpkg -i bin/otel-collector*amd64.deb
else
sudo rpm -ivh bin/otel-collector*x86_64.rpm
fi
test -f /usr/bin/otelcol || (echo "/usr/bin/otelcol not found!" && exit 1)
test -f /etc/otel-collector/config.yaml || (echo "/etc/otel-collector/config.yaml not found" && exit 1)
- persist_to_workspace:
root: ~/
paths: project/bin
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ binaries-linux_arm64:
binaries-windows_amd64:
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) binaries

.PHONY: deb-rpm-package
%-package: ARCH ?= amd64
%-package:
$(MAKE) binaries-linux_$(ARCH)
docker build -t otelcol-fpm internal/buildscripts/packaging/fpm
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcol-fpm

# Definitions for ProtoBuf generation.

# The source directory for OTLP ProtoBufs.
Expand Down
16 changes: 16 additions & 0 deletions internal/buildscripts/packaging/fpm/Dockerfile
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/bin/"

CMD ./internal/buildscripts/packaging/fpm/$PACKAGE/build.sh "$VERSION" "$ARCH" "$OUTPUT_DIR"
10 changes: 10 additions & 0 deletions internal/buildscripts/packaging/fpm/deb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Build otel-collector deb package

Build the otel-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
`bin/otel-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`.
28 changes: 28 additions & 0 deletions internal/buildscripts/packaging/fpm/deb/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/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/bin/"}"
OTELCOL_PATH="$REPO_DIR/bin/otelcol_linux_amd64"
CONFIG_PATH="$REPO_DIR/examples/otel-local-config.yaml"

if [[ -z "$VERSION" ]]; then
latest_tag="$( git describe --abbrev=0 --match v[0-9]* )"
VERSION="${latest_tag}-post"
fi

fpm -s dir -t deb -n otel-collector -v ${VERSION#v} -f -p "$OUTPUT_DIR" \
--vendor "OpenTelemetry Community" \
--maintainer "OpenTelemetry Community <[email protected]>" \
--description "OpenTelemetry Collector" \
--license "Apache 2.0" \
--url "https://github.com/open-telemetry/opentelemetry-collector" \
--architecture "$ARCH" \
--config-files /etc/otel-collector/config.yaml \
--deb-dist "stable" \
$OTELCOL_PATH=/usr/bin/otelcol \
$CONFIG_PATH=/etc/otel-collector/config.yaml
10 changes: 10 additions & 0 deletions internal/buildscripts/packaging/fpm/rpm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Build otel-collector rpm package

Build the otel-collector rpm package with [fpm](https://github.com/jordansissel/fpm).

To build the rpm package, run `make rpm-package` from the repo root directory. The rpm package will be written to
`bin/otel-collector-<version>.<arch>.rpm`.

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 rpm-package`.
28 changes: 28 additions & 0 deletions internal/buildscripts/packaging/fpm/rpm/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/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/bin/"}"
OTELCOL_PATH="$REPO_DIR/bin/otelcol_linux_amd64"
CONFIG_PATH="$REPO_DIR/examples/otel-local-config.yaml"

if [[ -z "$VERSION" ]]; then
latest_tag="$( git describe --abbrev=0 --match v[0-9]* )"
VERSION="${latest_tag}~post"
fi

fpm -s dir -t rpm -n otel-collector -v ${VERSION#v} -f -p "$OUTPUT_DIR" \
--vendor "OpenTelemetry Community" \
--maintainer "OpenTelemetry Community <[email protected]>" \
--description "OpenTelemetry Collector" \
--license "Apache 2.0" \
--rpm-summary "OpenTelemetry Collector" \
--url "https://github.com/open-telemetry/opentelemetry-collector" \
--architecture "$ARCH" \
--config-files /etc/otel-collector/config.yaml \
$OTELCOL_PATH=/usr/bin/otelcol \
$CONFIG_PATH=/etc/otel-collector/config.yaml