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

ci: simplify dev/CI and prepare for image building #140

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
3 changes: 0 additions & 3 deletions .circleci/README.md

This file was deleted.

124 changes: 85 additions & 39 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,96 @@
version: 2.1
jobs:
build:
working_directory: ~/repo

executors:
go-executor:
docker:
- image: cimg/go:1.21

commands:
setup_build_tools:
description: "Ensure the build tools are installed"
steps:
- checkout
- restore_cache:
keys:
- builder-config-{{ checksum "builder-config.yaml" }}
- run:
name: install dependencies
environment:
OTC_BUILDER_VERSION: 0.98.0
PYTHON_VERSION: 3.9
name: Ensure the right yq is installed
command: |
sudo apt-get update -qq
sudo apt-get install -y python2 libbz2-dev libreadline-dev libssl-dev openssl
curl https://pyenv.run | bash
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
export PYENV_ROOT=/home/circleci/.pyenv
export PATH=/home/circleci/.pyenv/shims:/home/circleci/.pyenv/bin:/home/circleci/.poetry/bin:$PATH
pyenv install $PYTHON_VERSION
pyenv global $PYTHON_VERSION
pip3 install yq
export GOARCH=$(go env GOARCH)
export GOOS=$(go env GOOS)
mkdir -p /home/circleci/bin
curl -sLo /home/circleci/bin/ocb "https://github.com/open-telemetry/opentelemetry-collector/releases/download/cmd%2Fbuilder%2Fv${OTC_BUILDER_VERSION}/ocb_${OTC_BUILDER_VERSION}_${GOOS}_${GOARCH}"
chmod u+x /home/circleci/bin/ocb
python --version
pip3 --version
ocb version
if ! bin/yq --version; then
sudo apt-get update -qq
sudo apt-get install -y python3-pip
pip install yq
fi
bin/yq --version
- run:
name: Run tests
command: |
export PYENV_ROOT=/home/circleci/.pyenv
export PATH=/home/circleci/.pyenv/shims:/home/circleci/.pyenv/bin:/home/circleci/.poetry/bin:$PATH
make test
name: Install build tools
command: make tools_exist

setup_remote_and_local_docker:
description: "Setup Docker and fiddle permissions when running local CI"
steps:
- setup_remote_docker
- run:
name: Create artifacts
name: Maybe fiddle local Docker permissions
command: |
mkdir -p /tmp/images;
cp build/otelcol_hny_$(go env GOOS)_$(go env GOARCH) /tmp/images;
ls -ls /var/run/docker*.sock
if [[ ${CIRCLE_SHELL_ENV} =~ "localbuild" ]]; then
sudo chgrp circleci /var/run/docker*.sock
fi
ls -ls /var/run/docker*.sock

jobs:
build:
executor: go-executor
steps:
- checkout
- setup_remote_and_local_docker
- setup_build_tools
- run:
name: Build for target test platform
command: make build
- run:
name: Test
command: make test
- run:
name: Cross-compile binaries and build local Docker image
command: make all
- save_cache:
key: builder-config-{{ checksum "builder-config.yaml" }}
paths: build
key: go_build_cache-{{ .Environment.CIRCLE_SHA1 }}
paths:
- /home/circleci/.cache/go-build
- store_artifacts:
path: /tmp/images
path: dist
publish_image:
executor: go-executor
steps:
- checkout
- restore_cache:
keys:
- go_build_cache-{{ .Environment.CIRCLE_SHA1 }}
- setup_remote_docker
- attach_workspace:
at: .
- run:
name: Publish Docker images
command: |
make release

filters_always: &filters_always
filters:
tags:
only: /.*/

filters_publish: &filters_publish
filters:
tags:
only: /^v[0-9].*/
branches:
ignore: /.*/

workflows:
version: 2
build:
jobs:
- build:
<<: *filters_always
- publish_image:
<<: *filters_publish
requires:
- build
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/.circleci/config-processed.yml
/artifacts/*
/bin/goreleaser*
/bin/ko*
/bin/ocb*
/build/*
/test/tmp-*
/cmd/otelcol_hny
/dist/*

# GoLand IDEA
Expand Down
95 changes: 95 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Documentation for this config can be found at https://goreleaser.com

# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

builds:
- id: otelcol_hny
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
dir: ./cmd/otelcol_hny
binary: otelcol_hny_{{ .Os }}_{{ .Arch }}
no_unique_dist_dir: true

snapshot:
version_template: "{{ .Env.VERSION }}"

kos:
- id: otelcol_hny
repository: ghcr.io/honeycombio/otelcol_hny
tags:
- "{{ .Version }}"
- "{{ if not .IsSnapshot }}{{ .Major }}.{{ .Minor }}{{ end }}"
- "{{ if not .IsSnapshot }}{{ .Major }}{{ end }}"
- "{{ if not .IsSnapshot }}latest{{ else }}dev{{ end }}"
base_import_paths: true
labels:
org.opencontainers.image.source: https://github.com/honeycombio/opentelemetry-collector-configs
org.opencontainers.image.licenses: Apache-2.0
org.opencontainers.image.revision: "{{ .FullCommit }}"

archives:
- id: otelcol_hny
format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
otelcol_hny_
{{- .Env.VERSION }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
files:
- src: artifacts/honeycomb-metrics-config.yaml
dst: honeycomb-metrics-config.yaml

nfpms:
- package_name: otelcol_hny
builds:
- otelcol_hny
vendor: Honeycomb.io
maintainer: Honeycomb Engineering <support@honeycomb.io>
license: Apache-2.0
formats:
- deb
- rpm
contents:
- src: packaging/fpm/otel-hny-collector.service
dst: /etc/systemd/system/otelcol_hny.service
- src: packaging/fpm/otel-hny-collector.conf
dst: /etc/otelcol_hny/otelcol_hny.conf
- src: artifacts/honeycomb-metrics-config.yaml
dst: /etc/otelcol_hny/config.yaml
scripts:
preinstall: packaging/fpm/preinstall.sh
postinstall: packaging/fpm/postinstall.sh
preremove: packaging/fpm/preuninstall.sh

release:
draft: true
extra_files:
- glob: ./artifacts/honeycomb-metrics-config.yaml

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
6 changes: 6 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defaultPlatforms:
- linux/arm64
- linux/amd64
builds:
- id: otelcol_hny
dir: cmd/otelcol_hny
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang 1.21.13
goreleaser 2.3.2
Loading
Loading