Skip to content

Commit

Permalink
feat: add new versions and goss checks (#72)
Browse files Browse the repository at this point in the history
* feat: add new versions and goss checks

* feat: add new versions and justfile

* trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* add multiple rock versions and build on 24.04

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* chore: trigger ci

* use workflow from main

* update readme

* update rock-update
  • Loading branch information
lucabello authored Dec 12, 2024
1 parent 81d7bdf commit 92f3834
Show file tree
Hide file tree
Showing 6 changed files with 208 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 @@ -20,3 +20,4 @@ jobs:
## grafana-ui dependency
source_tag=$(yq .parts.grafana.source-tag $rockcraft_yaml)
tag="\$source_tag" yq -i '.parts.grafana-ui.source-tag = strenv(tag)' $rockcraft_yaml
secrets: inherit
72 changes: 72 additions & 0 deletions 11.3.2/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: grafana
summary: Grafana in a ROCK.
description: "The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more."
version: "11.3.2"
base: ubuntu@24.04
license: AGPL-3.0
services:
grafana:
command: /bin/grafana-server --config /etc/grafana/grafana-config.ini
override: replace
startup: enabled
platforms:
amd64:
parts:
grafana:
plugin: go
source: https://github.com/grafana/grafana.git
source-tag: v11.3.2
source-depth: 1
build-snaps:
- go/1.23/stable
override-build: |
set -x
make build-go
find bin -type f -executable | while read f; do install -D -m 755 $f ${CRAFT_PART_INSTALL}/usr/$(echo $f | sed -e 's%linux-amd64/%%'); done
cp -rpv conf ${CRAFT_PART_INSTALL}/conf
mkdir -p ${CRAFT_PART_INSTALL}/etc/grafana
touch ${CRAFT_PART_INSTALL}/etc/grafana/grafana-config.ini
stage:
- bin/*
- usr/bin/grafana*
- conf/
- etc/grafana
grafana-ui:
after: [grafana]
plugin: nil
source-type: git
source: https://github.com/grafana/grafana.git
source-tag: v11.3.2
build-snaps:
- node/18/stable
build-environment:
- NODE_OPTIONS: "--max-old-space-size=8192"
override-build: |
# We have to limit node's max memory usage otherwise we'll run
# into OOM issues even with a 10GB RAM VM.
npm install --location=global --prefix $CRAFT_PART_BUILD yarn
[[ -v http_proxy ]] && yarn config set httpProxy ${http_proxy}
[[ -v https_proxy ]] && yarn config set httpsProxy ${https_proxy}
yarn config
YARN_ENABLE_PROGRESS_BARS=false yarn install --immutable
echo "Building frontend"
make build-js
mkdir -p ${CRAFT_PART_INSTALL}/{public,tools}
cp -rpv public/* ${CRAFT_PART_INSTALL}/public/
stage:
- public/
- tools/
ca-certs:
plugin: nil
overlay-packages:
- ca-certificates
deb-security-manifest:
plugin: nil
after:
- grafana
- grafana-ui
- 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
72 changes: 72 additions & 0 deletions 11.4.0/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: grafana
summary: Grafana in a ROCK.
description: "The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more."
version: "11.4.0"
base: ubuntu@24.04
license: AGPL-3.0
services:
grafana:
command: /bin/grafana-server --config /etc/grafana/grafana-config.ini
override: replace
startup: enabled
platforms:
amd64:
parts:
grafana:
plugin: go
source: https://github.com/grafana/grafana.git
source-tag: v11.4.0
source-depth: 1
build-snaps:
- go/1.23/stable
override-build: |
set -x
make build-go
find bin -type f -executable | while read f; do install -D -m 755 $f ${CRAFT_PART_INSTALL}/usr/$(echo $f | sed -e 's%linux-amd64/%%'); done
cp -rpv conf ${CRAFT_PART_INSTALL}/conf
mkdir -p ${CRAFT_PART_INSTALL}/etc/grafana
touch ${CRAFT_PART_INSTALL}/etc/grafana/grafana-config.ini
stage:
- bin/*
- usr/bin/grafana*
- conf/
- etc/grafana
grafana-ui:
after: [grafana]
plugin: nil
source-type: git
source: https://github.com/grafana/grafana.git
source-tag: v11.4.0
build-snaps:
- node/18/stable
build-environment:
- NODE_OPTIONS: "--max-old-space-size=8192"
override-build: |
# We have to limit node's max memory usage otherwise we'll run
# into OOM issues even with a 10GB RAM VM.
npm install --location=global --prefix $CRAFT_PART_BUILD yarn
[[ -v http_proxy ]] && yarn config set httpProxy ${http_proxy}
[[ -v https_proxy ]] && yarn config set httpsProxy ${https_proxy}
yarn config
YARN_ENABLE_PROGRESS_BARS=false yarn install --immutable
echo "Building frontend"
make build-js
mkdir -p ${CRAFT_PART_INSTALL}/{public,tools}
cp -rpv public/* ${CRAFT_PART_INSTALL}/public/
stage:
- public/
- tools/
ca-certs:
plugin: nil
overlay-packages:
- ca-certificates
deb-security-manifest:
plugin: nil
after:
- grafana
- grafana-ui
- 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,10 +7,21 @@
[Rocks](https://canonical-rockcraft.readthedocs-hosted.com/en/latest/) for [Grafana](https://grafana.com/).
This repository holds all the necessary files to build rocks for the upstream versions we support. The Grafana rock is used by the [grafana-k8s-operator](https://github.com/canonical/grafana-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:dev](https://ghcr.io/canonical/grafana:dev), when merging to main, for development purposes.

15 changes: 15 additions & 0 deletions goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
process:
grafana:
running: true
package:
ca-certificates:
installed: true
http:
metrics:
status: 200
url: http://localhost:3000/metrics
timeout: 1000
health:
status: 200
url: http://localhost:3000/api/health
timeout: 1000
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 92f3834

Please sign in to comment.