Skip to content

Commit

Permalink
Add basic build and CI (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling authored Mar 11, 2022
1 parent faec544 commit c0766b8
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 12 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Continuous Integration

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
name: Build
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Verify
run: make ci
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GO ?= go

OTELCOL_BUILDER_VERSION ?= 0.46.0
OTELCOL_BUILDER_DIR ?= ${HOME}/bin
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb

DISTRIBUTIONS ?= "sidecar,tracing"

ci: check build
check:

build: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -b ${OTELCOL_BUILDER} -g ${GO}

generate: generate-sources

generate-sources: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -s true -b ${OTELCOL_BUILDER} -g ${GO}

.PHONY: ocb
ocb:
ifeq (, $(shell command -v ocb 2>/dev/null))
@{ \
[ ! -x '$(OTELCOL_BUILDER)' ] || exit 0; \
set -e ;\
os=$$(uname | tr A-Z a-z) ;\
machine=$$(uname -m) ;\
[ "$${machine}" != x86 ] || machine=386 ;\
[ "$${machine}" != x86_64 ] || machine=amd64 ;\
echo "Installing ocb ($${os}/$${machine}) at $(OTELCOL_BUILDER_DIR)";\
mkdir -p $(OTELCOL_BUILDER_DIR) ;\
curl -sLo $(OTELCOL_BUILDER) "https://github.com/open-telemetry/opentelemetry-collector/releases/download/v$(OTELCOL_BUILDER_VERSION)/ocb_$(OTELCOL_BUILDER_VERSION)_$${os}_$${machine}" ;\
chmod +x $(OTELCOL_BUILDER) ;\
}
else
OTELCOL_BUILDER=$(shell command -v ocb)
endif

.PHONY: go
go:
@{ \
if ! command -v '$(GO)' >/dev/null 2>/dev/null; then \
echo >&2 '$(GO) command not found. Please install golang. https://go.dev/doc/install'; \
exit 1; \
fi \
}
9 changes: 4 additions & 5 deletions distributions/sidecar/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ dist:
module: github.com/grafana/opentelemetry-collector-components/distributions/sidecar
name: otelcol
description: OpenTelemetry Collector Sidecar by Grafana Labs
version: 0.39.0
version: 0.46.0
output_path: ./_build
otelcol_version: 0.39.0
include_core: false
otelcol_version: 0.46.0

receivers:
- import: go.opentelemetry.io/collector/receiver/otlpreceiver
gomod: go.opentelemetry.io/collector v0.39.0
gomod: go.opentelemetry.io/collector v0.46.0
exporters:
- import: go.opentelemetry.io/collector/exporter/otlpexporter
gomod: go.opentelemetry.io/collector v0.39.0
gomod: go.opentelemetry.io/collector v0.46.0
13 changes: 6 additions & 7 deletions distributions/tracing/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ dist:
module: github.com/grafana/opentelemetry-collector-components/distributions/sidecar
name: otelcol
description: OpenTelemetry Collector for Tracing by Grafana Labs
version: 0.39.0
version: 0.46.0
output_path: ./_build
otelcol_version: 0.39.0
include_core: false
otelcol_version: 0.46.0

receivers:
- import: go.opentelemetry.io/collector/receiver/otlpreceiver
gomod: go.opentelemetry.io/collector v0.39.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.39.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.39.0
gomod: go.opentelemetry.io/collector v0.46.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.46.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.46.0
exporters:
- import: go.opentelemetry.io/collector/exporter/otlpexporter
gomod: go.opentelemetry.io/collector v0.39.0
gomod: go.opentelemetry.io/collector v0.46.0
56 changes: 56 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

REPO_DIR="$( cd "$(dirname $( dirname "${BASH_SOURCE[0]}" ))" &> /dev/null && pwd )"
BUILDER=''
GO=''

# default values
skipcompilation=false

while getopts d:s:b:g: flag
do
case "${flag}" in
d) distributions=${OPTARG};;
s) skipcompilation=${OPTARG};;
b) BUILDER=${OPTARG};;
g) GO=${OPTARG};;
esac
done

[[ -n "$BUILDER" ]] || BUILDER='ocb'
[[ -n "$GO" ]] || GO='go'

if [[ -z $distributions ]]; then
echo "List of distributions to build not provided. Use '-d' to specify the names of the distributions to build. Ex.:"
echo "$0 -d tracing"
exit 1
fi

if [[ "$skipcompilation" = true ]]; then
echo "Skipping the compilation, we'll only generate the sources."
fi

echo "Distributions to build: $distributions";

for distribution in $(echo "$distributions" | tr "," "\n")
do
pushd "${REPO_DIR}/distributions/${distribution}" > /dev/null
mkdir -p _build

echo "Building: $distribution"
echo "Using Builder: $(command -v "$BUILDER")"
echo "Using Go: $(command -v "$GO")"

if "$BUILDER" --skip-compilation=${skipcompilation} --go "$GO" --config manifest.yaml > _build/build.log 2>&1; then
echo "✅ SUCCESS: distribution '${distribution}' built."
else
echo "❌ ERROR: failed to build the distribution '${distribution}'."
echo "🪵 Build logs for '${distribution}'"
echo "----------------------"
cat _build/build.log
echo "----------------------"
exit 1
fi

popd > /dev/null
done

0 comments on commit c0766b8

Please sign in to comment.