ci: switch rust to gha (#2590)
This commit is contained in:
1 parent
d9cebf3c9b
commit
36ea2fbcd3
13 files changed
+1110
-193
No files matched your search
@@ -9,6 +9,11 @@ on:
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
cargo:
|
||||
uses: vexxhost/github-actions/.github/workflows/cargo.yml@d240297ac3f2162871403fea1074360da43d4585 # main
|
||||
with:
|
||||
install-promtool: true
|
||||
|
||||
chart-vendor:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
Generated
+952
-9
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "kube-prometheus-stack"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
k8s-openapi = { version = "0.24.0", features = ["v1_28"] }
|
||||
kcr_monitoring_coreos_com = "1.20250426.145342"
|
||||
once_cell = "1.21.3"
|
||||
rsjsonnet-front = "0.3.0"
|
||||
rsjsonnet-lang = "0.3.0"
|
||||
serde_yaml = "0.9.34"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.19.1"
|
||||
@@ -0,0 +1,82 @@
|
||||
use k8s_openapi::serde_json;
|
||||
use kcr_monitoring_coreos_com::v1::prometheusrules::PrometheusRuleSpec;
|
||||
use once_cell::sync::Lazy;
|
||||
use rsjsonnet_front::Session;
|
||||
use rsjsonnet_lang::arena::Arena;
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
static RULES: Lazy<HashMap<String, PrometheusRuleSpec>> = Lazy::new(|| {
|
||||
let path = Path::new("../../roles/kube_prometheus_stack/files/jsonnet/rules.jsonnet");
|
||||
|
||||
let arena = Arena::new();
|
||||
let mut session = Session::new(&arena);
|
||||
|
||||
let Some(thunk) = session.load_real_file(path) else {
|
||||
panic!("Failed to load jsonnet file");
|
||||
};
|
||||
|
||||
let Some(value) = session.eval_value(&thunk) else {
|
||||
panic!("Failed to evaluate jsonnet file");
|
||||
};
|
||||
|
||||
let Some(json_result) = session.manifest_json(&value, false) else {
|
||||
panic!("Failed to convert jsonnet to JSON");
|
||||
};
|
||||
|
||||
serde_json::from_str(&json_result).unwrap()
|
||||
});
|
||||
|
||||
pub fn load_rules() -> &'static HashMap<String, PrometheusRuleSpec> {
|
||||
&RULES
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::File;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_promtool() {
|
||||
let mut tests: HashMap<String, serde_yaml::Value> = serde_yaml::from_reader(
|
||||
File::open("../../roles/kube_prometheus_stack/files/jsonnet/tests.yml").unwrap(),
|
||||
)
|
||||
.expect("failed to read tests.yml");
|
||||
|
||||
let tempdir = TempDir::new().unwrap();
|
||||
let mut rule_files = Vec::new();
|
||||
|
||||
for (name, rule) in load_rules() {
|
||||
let file_path = tempdir.path().join(format!("{}.yaml", name));
|
||||
|
||||
serde_json::to_writer(File::create(&file_path).unwrap(), rule).unwrap();
|
||||
rule_files.push(file_path);
|
||||
}
|
||||
|
||||
tests.insert(
|
||||
"rule_files".to_string(),
|
||||
serde_yaml::to_value(rule_files).unwrap(),
|
||||
);
|
||||
|
||||
serde_json::to_writer(
|
||||
File::create(tempdir.path().join("tests.yaml")).unwrap(),
|
||||
&tests,
|
||||
)
|
||||
.expect("failed to write tests.yaml");
|
||||
|
||||
// TODO(mnaser): JUnit output?
|
||||
let output = std::process::Command::new("promtool")
|
||||
.arg("test")
|
||||
.arg("rules")
|
||||
.arg(tempdir.path().join("tests.yaml"))
|
||||
.output()
|
||||
.expect("failed to execute promtool");
|
||||
|
||||
if !output.status.success() {
|
||||
panic!(
|
||||
"promtool failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,11 +149,11 @@ impl DockerContainerGuard {
|
||||
})
|
||||
.await?;
|
||||
|
||||
if bytes.len() == 0 {
|
||||
if bytes.is_empty() {
|
||||
return Err(DockerContainerGuardError::FileNotFound(path.into()));
|
||||
}
|
||||
|
||||
for file in tar::Archive::new(&bytes[..]).entries()? {
|
||||
if let Some(file) = (tar::Archive::new(&bytes[..]).entries()?).next() {
|
||||
let mut s = String::new();
|
||||
file?.read_to_string(&mut s).unwrap();
|
||||
return Ok(s);
|
||||
@@ -168,14 +168,14 @@ impl DockerContainerGuard {
|
||||
) -> Result<HashMap<String, PasswdEntry>, DockerContainerGuardError> {
|
||||
let output = self.read_file("/etc/passwd").await?;
|
||||
|
||||
return output
|
||||
output
|
||||
.lines()
|
||||
.map(|line| {
|
||||
PasswdEntry::from_line(line)
|
||||
.map(|entry| (entry.name.clone(), entry))
|
||||
.map_err(DockerContainerGuardError::from)
|
||||
})
|
||||
.collect();
|
||||
.collect()
|
||||
}
|
||||
|
||||
// Get a specific user from the container.
|
||||
@@ -214,7 +214,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_container_exec() -> Result<(), DockerContainerGuardError> {
|
||||
let guard = DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest").await?;
|
||||
let guard =
|
||||
DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest")
|
||||
.await?;
|
||||
|
||||
let output = guard.exec(vec!["echo", "hello from container"]).await?;
|
||||
assert!(output.contains("hello from container"));
|
||||
@@ -224,7 +226,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_container_read_file() -> Result<(), DockerContainerGuardError> {
|
||||
let guard = DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest").await?;
|
||||
let guard =
|
||||
DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest")
|
||||
.await?;
|
||||
|
||||
let file = guard.read_file("/usr/lib/os-release").await?;
|
||||
assert!(file.len() > 0);
|
||||
@@ -234,7 +238,9 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_container_get_user() -> Result<(), DockerContainerGuardError> {
|
||||
let guard = DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest").await?;
|
||||
let guard =
|
||||
DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest")
|
||||
.await?;
|
||||
|
||||
let user = guard.get_user("root").await?;
|
||||
assert_eq!(user.name, "root");
|
||||
|
||||
Generated
+3
-3
@@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1740396192,
|
||||
"narHash": "sha256-ATMHHrg3sG1KgpQA5x8I+zcYpp5Sf17FaFj/fN+8OoQ=",
|
||||
"lastModified": 1746397377,
|
||||
"narHash": "sha256-5oLdRa3vWSRbuqPIFFmQBGGUqaYZBxX+GGtN9f/n4lU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d9b69c3ec2a2e2e971c534065bdd53374bd68b97",
|
||||
"rev": "ed30f8aba41605e3ab46421e3dcb4510ec560ff8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -4,34 +4,44 @@
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem
|
||||
(system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in
|
||||
{
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
bashInteractive
|
||||
docutils
|
||||
earthly
|
||||
gh
|
||||
glibcLocales
|
||||
go
|
||||
just
|
||||
kubernetes-helm
|
||||
nixpkgs-fmt
|
||||
patchutils
|
||||
python311Packages.tox
|
||||
reno
|
||||
renovate
|
||||
uv
|
||||
vale
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in
|
||||
{
|
||||
formatter = pkgs.nixfmt-rfc-style;
|
||||
|
||||
devShell = pkgs.mkShell {
|
||||
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
cargo
|
||||
clippy
|
||||
docutils
|
||||
gh
|
||||
go
|
||||
kubernetes-helm
|
||||
patchutils
|
||||
python311Packages.tox
|
||||
reno
|
||||
renovate
|
||||
rust-analyzer
|
||||
rustc
|
||||
rustfmt
|
||||
uv
|
||||
vale
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
# Copyright (c) 2024 VEXXHOST, Inc.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import rjsonnet
|
||||
import yaml
|
||||
|
||||
|
||||
def import_callback(base, rel):
|
||||
"""
|
||||
:param base: The directory containing the code that did the import.
|
||||
:param rel: The path imported by the code.
|
||||
"""
|
||||
path = os.path.join(base, rel)
|
||||
with open(path, "r") as f:
|
||||
return path, f.read()
|
||||
|
||||
|
||||
def main():
|
||||
compiled_string = rjsonnet.evaluate_file(
|
||||
"roles/kube_prometheus_stack/files/jsonnet/rules.jsonnet",
|
||||
import_callback=import_callback,
|
||||
)
|
||||
compiled = json.loads(compiled_string)
|
||||
|
||||
tempdir = tempfile.mkdtemp()
|
||||
rule_files = []
|
||||
|
||||
try:
|
||||
for rule_file, data in compiled.items():
|
||||
file_name = rule_file + ".yml"
|
||||
path = os.path.join(tempdir, file_name)
|
||||
|
||||
if os.path.exists(path):
|
||||
raise Exception(f"File {path} already exists")
|
||||
with open(path, "w") as f:
|
||||
yaml.dump(data, f)
|
||||
|
||||
rule_files.append(path)
|
||||
|
||||
with open("roles/kube_prometheus_stack/files/jsonnet/tests.yml") as f:
|
||||
tests = yaml.safe_load(f)
|
||||
|
||||
tests["rule_files"] = rule_files
|
||||
|
||||
tests_file = os.path.join(tempdir, "tests.yml")
|
||||
with open(tests_file, "w") as f:
|
||||
yaml.dump(tests, f)
|
||||
|
||||
# TODO(mnaser): Enable JUnit output
|
||||
os.system(f"promtool test rules {tests_file}")
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -100,14 +100,6 @@ allowlist_externals =
|
||||
commands =
|
||||
bash {toxinidir}/build/build-manila-image.sh
|
||||
|
||||
[testenv:promtool-test]
|
||||
skip_install = true
|
||||
deps =
|
||||
PyYAML
|
||||
rjsonnet
|
||||
commands =
|
||||
python3 {toxinidir}/hack/promtool-test.py
|
||||
|
||||
[testenv:helm-unittest]
|
||||
commands =
|
||||
python3 {toxinidir}/hack/helm-unittest.py
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
- job:
|
||||
name: atmosphere-cargo-test
|
||||
run:
|
||||
- zuul.d/playbooks/cargo-test/run.yml
|
||||
dependencies:
|
||||
- name: atmosphere-build-images
|
||||
soft: true
|
||||
|
||||
- job:
|
||||
name: atmosphere-linters
|
||||
parent: tox-linters
|
||||
pre-run: zuul.d/playbooks/linters/pre.yml
|
||||
|
||||
- job:
|
||||
name: atmosphere-tox-promtool-test
|
||||
parent: tox
|
||||
pre-run: zuul.d/playbooks/promtool/pre.yml
|
||||
vars:
|
||||
tox_envlist: promtool-test
|
||||
|
||||
- job:
|
||||
name: atmosphere-tox-helm-unittest
|
||||
parent: tox
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Install Docker
|
||||
ansible.builtin.include_role:
|
||||
name: ensure-docker
|
||||
|
||||
- name: Install Rust
|
||||
ansible.builtin.include_role:
|
||||
name: ensure-rust
|
||||
|
||||
- name: Ensure required packages are installed
|
||||
become: true
|
||||
ansible.builtin.apt:
|
||||
name: ["build-essential", "pkg-config", "libssl-dev"]
|
||||
state: present
|
||||
|
||||
- name: Run "cargo test"
|
||||
ansible.builtin.command: cargo test --workspace
|
||||
args:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
environment:
|
||||
REGISTRY: "{{ (zuul.artifacts | default([]) | length > 0) | ternary('harbor.atmosphere.dev/ci', 'harbor.atmosphere.dev/library') }}"
|
||||
TAG: "{{ (zuul.artifacts | default([]) | length > 0) | ternary(zuul.change, zuul.branch.replace('stable/', '')) }}"
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright (c) 2024 VEXXHOST, Inc.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Install promtool
|
||||
block:
|
||||
- name: Create temporary file to download
|
||||
ansible.builtin.tempfile:
|
||||
state: file
|
||||
suffix: .tar.gz
|
||||
register: promtool_file
|
||||
|
||||
- name: Download Prometheus
|
||||
ansible.builtin.get_url:
|
||||
url: https://github.com/prometheus/prometheus/releases/download/v2.55.0/prometheus-2.55.0.linux-amd64.tar.gz
|
||||
dest: "{{ promtool_file.path }}"
|
||||
checksum: sha256:7a6b6d5ea003e8d59def294392c64e28338da627bf760cf268e788d6a8832a23
|
||||
|
||||
- name: Extract Prometheus into /usr/local/bin
|
||||
become: true
|
||||
ansible.builtin.unarchive:
|
||||
src: "{{ promtool_file.path }}"
|
||||
dest: /usr/local/bin
|
||||
remote_src: true
|
||||
extra_opts:
|
||||
- --strip-components=1
|
||||
include:
|
||||
- prometheus-2.55.0.linux-amd64/promtool
|
||||
always:
|
||||
- name: Remove temporary file
|
||||
ansible.builtin.file:
|
||||
path: "{{ promtool_file.path }}"
|
||||
state: absent
|
||||
@@ -15,9 +15,7 @@
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
- atmosphere-cargo-test
|
||||
- atmosphere-linters
|
||||
- atmosphere-tox-promtool-test
|
||||
- atmosphere-tox-helm-unittest
|
||||
- atmosphere-tox-py3
|
||||
- atmosphere-molecule-aio-keycloak:
|
||||
@@ -36,7 +34,6 @@
|
||||
dependencies: *image_build_jobs
|
||||
gate:
|
||||
jobs:
|
||||
- atmosphere-cargo-test
|
||||
- atmosphere-linters
|
||||
- atmosphere-tox-py3
|
||||
- atmosphere-build-images
|
||||
|
||||
Reference in new issue
Block a user