Skip to content

Commit

Permalink
feat: goss checks and 0.43.4 (#98)
Browse files Browse the repository at this point in the history
* feat: goss checks and 0.43.4

* update README

* update rock-update
  • Loading branch information
lucabello authored Dec 11, 2024
1 parent 3ef0c2f commit d3c1eae
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/rock-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Update rock
on:
workflow_dispatch: {}
schedule:
- cron: '0 0,4,8,12,16,20 * * *'
- cron: '0 0 * * *'

jobs:
build:
Expand All @@ -12,3 +12,4 @@ jobs:
rock-name: grafana-agent
source-repo: grafana/agent
check-go: true
secrets: inherit
17 changes: 17 additions & 0 deletions 0.43.4/agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server:
log_level: info

metrics:
global:
scrape_interval: 1m
configs:
- name: test
host_filter: false
scrape_configs:
- job_name: local_scrape
static_configs:
- targets: ['127.0.0.1:12345']
labels:
cluster: 'localhost'
remote_write:
- url: http://localhost:9009/api/prom/push
54 changes: 54 additions & 0 deletions 0.43.4/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: grafana-agent
summary: Grafana Agent in a ROCK.
description: "Grafana Agent is a single binary collector for metrics and logging, useful for per-node metrics or proxying from edge endpoints."
version: "0.43.4"
base: [email protected]
build-base: [email protected]
license: Apache-2.0
platforms:
amd64:
arm64:
services:
agent:
command: /usr/bin/grafana-agent --config.file=/etc/agent/agent.yaml --metrics.wal-directory=/etc/agent/data
override: replace
startup: enabled
parts:
grafana-agent:
plugin: go
source: https://github.com/grafana/agent
source-type: git
source-tag: "v0.43.4"
build-snaps:
- go/1.22/stable
build-environment:
- USE_CONTAINER: 0
- RELEASE_BUILD: 1
stage-packages:
- ca-certificates
override-build: |
make agent
install -D -m755 build/grafana-agent ${CRAFT_PART_INSTALL}/opt/agent/bin/grafana-agent
ln -sv /bin/grafana-agent ${CRAFT_PART_INSTALL}/opt/agent/bin/agent
organize:
opt/agent/bin/grafana-agent: usr/bin/grafana-agent
opt/agent/bin/agent: usr/bin/agent
default-config:
plugin: dump
source: .
organize:
agent.yaml: etc/agent/agent.yaml
stage:
- etc/agent/agent.yaml
ca-certs:
plugin: nil
overlay-packages: [ca-certificates]
deb-security-manifest:
plugin: nil
after:
- grafana-agent
- ca-certs
override-prime: |
set -x
mkdir -p $CRAFT_PRIME/usr/share/rocks/
(echo "# os-release" && cat /etc/os-release && echo "# dpkg-query" && dpkg-query --admindir=$CRAFT_PRIME/var/lib/dpkg/ -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) > $CRAFT_PRIME/usr/share/rocks/dpkg.query
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
[Rocks](https://canonical-rockcraft.readthedocs-hosted.com/en/latest/) for [Grafana Agent](https://grafana.com/oss/agent/).
This repository holds all the necessary files to build rocks for the upstream versions we support. The Grafana Agent rock is used by the [grafana-agent-k8s-operator](https://github.com/canonical/grafana-agent-k8s-operator) charm.

The rocks on this repository are built with [OCI Factory](https://github.com/canonical/oci-factory/), which also takes care of periodically rebuilding the images.
The rocks on this repository are built with [OCI Factory](https://github.com/canonical/oci-factory/), which also takes care of periodically rebuilding the images. New versions of the rock are tested using `kgoss`, which is part of [`goss`](https://github.com/goss-org/goss).

**How do I interact with this repo?** This repo uses [`just`](https://github.com/casey/just) to easily run some commands:
```
∮ just
Available recipes:
clean version # `rockcraft clean` for a specific version
pack version # Pack a rock of a specific version
run version=latest_version # Run a rock and open a shell into it with `kgoss`
test version=latest_version # Test the rock with `kgoss`
```

Automation takes care of:

* validating PRs, by simply trying to build the rock;
* pulling upstream releases, creating a PR with the necessary files to be manually reviewed;
* on PRs, validate the added (or modified) rocks by running `kgoss`;
* releasing to GHCR at [ghcr.io/canonical/grafana-agent:dev](https://ghcr.io/canonical/grafana-agent:dev), when merging to main, for development purposes.

13 changes: 13 additions & 0 deletions goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
process:
grafana-agent:
running: true
http:
instances:
status: 200
url: http://localhost:12345/agent/api/v1/metrics/instances
ready:
status: 200
url: http://localhost:12345/-/ready
healthy:
status: 200
url: http://localhost:12345/-/healthy
35 changes: 35 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
set quiet # Recipes are silent by default
set export # Just variables are exported to environment variables

kgoss := `which kgoss` # `kgoss` is required

rock_name := `echo ${PWD##*/} | sed 's/-rock//'`
latest_version := `find . -maxdepth 1 -type d | sort -V | tail -n1 | sed 's@./@@'`

[private]
default:
just --list

# Push an OCI image to a local registry
[private]
push-to-registry version:
echo "Pushing $rock_name $version to local registry"
rockcraft.skopeo --insecure-policy copy --dest-tls-verify=false \
"oci-archive:${version}/${rock_name}_${version}_amd64.rock" \
"docker://localhost:32000/${rock_name}-dev:${version}"

# Pack a rock of a specific version
pack version:
cd "$version" && rockcraft pack

# `rockcraft clean` for a specific version
clean version:
cd "$version" && rockcraft clean

# Run a rock and open a shell into it with `kgoss`
run version=latest_version: (push-to-registry version)
kgoss edit -i localhost:32000/${rock_name}-dev:${version}

# Test the rock with `kgoss`
test version=latest_version: (push-to-registry version)
GOSS_OPTS="--retry-timeout 60s" kgoss run -i localhost:32000/${rock_name}-dev:${version}

0 comments on commit d3c1eae

Please sign in to comment.