Fix linting, build-test-publish workflow, Docker image
Some checks failed
Build Docker Image / nix-flake-check (push) Failing after 2m26s
Build Docker Image / docker-build (push) Has been skipped
Build Docker Image / arm-docker-build (push) Has been skipped

This commit is contained in:
Gabriel Simmer 2023-11-10 12:19:31 +00:00
parent 012771f2fb
commit 466f00dd0e
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
5 changed files with 302 additions and 181 deletions

View file

@ -0,0 +1,110 @@
name: Build Docker Image
on:
push:
branches:
- master
jobs:
nix-flake-check:
runs-on: debian-latest
steps:
- name: Install prerequisites
run: apt update && apt install -y sudo zstd
- name: "Cache Nix store"
uses: actions/cache@v3.0.8
id: nix-cache
with:
path: /nix
key: "vr-event-tracker-cache-v1"
- name: Install Nix
uses: https://github.com/cachix/install-nix-action@v22
with:
extra_nix_config: "experimental-features = nix-command flakes"
nix_path: nixpkgs=channel:nixos-23.05
- name: Remove access_tokens
run: sed -i '/^access-tokens/d' /etc/nix/nix.conf
- name: Check out repository
uses: actions/checkout@v3.5.3
with:
ref: master
- name: Check codebase
run: nix flake check -L
docker-build:
needs: nix-flake-check
runs-on: debian-latest
steps:
- name: Install prerequisites
run: apt update && apt install -y sudo zstd
- name: "Cache Nix store"
uses: actions/cache@v3.0.8
id: nix-cache
with:
path: /nix
key: "vr-event-tracker-cache-v1"
- name: Install Nix
uses: https://github.com/cachix/install-nix-action@v22
with:
extra_nix_config: "experimental-features = nix-command flakes"
nix_path: nixpkgs=channel:nixos-23.05
- name: Remove access_tokens
run: sed -i '/^access-tokens/d' /etc/nix/nix.conf
- name: Check out repository
uses: actions/checkout@v3.5.3
with:
ref: master
- name: Build image
run: nix build .#docker
- name: Push image with Skopeo
run: |
nix-env -i skopeo -f '<nixpkgs>'
wget https://raw.githubusercontent.com/containers/skopeo/main/default-policy.json && mkdir /etc/containers && mv default-policy.json /etc/containers/policy.json
skopeo login --username arch --password $REGISTRY_TOKEN git.gmem.ca
skopeo copy docker-archive:result docker://git.gmem.ca/arch/vrchat-prometheus-adapter:latest
env:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
arm-docker-build:
needs: nix-flake-check
runs-on: debian-latest-arm
steps:
- name: Install prerequisites
run: apt update && apt install -y sudo zstd
- name: "Cache Nix store"
uses: actions/cache@v3.0.8
id: nix-cache
with:
path: /nix
key: "vr-event-tracker-cache-arm-v1"
- name: Install Nix
uses: https://github.com/cachix/install-nix-action@v22
with:
extra_nix_config: "experimental-features = nix-command flakes"
nix_path: nixpkgs=channel:nixos-23.05
- name: Remove access_tokens
run: sed -i '/^access-tokens/d' /etc/nix/nix.conf
- name: Check out repository
uses: actions/checkout@v3.5.3
with:
ref: master
- name: Build image
run: nix build .#docker
- name: Push image with Skopeo
run: |
nix-env -i skopeo -f '<nixpkgs>'
wget https://raw.githubusercontent.com/containers/skopeo/main/default-policy.json && mkdir /etc/containers && mv default-policy.json /etc/containers/policy.json
skopeo login --username arch --password $REGISTRY_TOKEN git.gmem.ca
skopeo copy docker-archive:result docker://git.gmem.ca/arch/vrchat-prometheus-adapter:arm
env:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}

7
Cargo.lock generated
View file

@ -670,16 +670,9 @@ dependencies = [
"lazy_static",
"memchr",
"parking_lot",
"protobuf",
"thiserror",
]
[[package]]
name = "protobuf"
version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94"
[[package]]
name = "quote"
version = "1.0.33"

View file

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
axum = "0.6.20"
prometheus = "0.13.3"
prometheus = { version = "0.13.3", default-features = false }
tokio = { version = "1.29.1", features = [ "full" ] }
serde = { version = "1.0.189", features = [ "derive" ] }
toml = "0.8.2"

View file

@ -23,7 +23,17 @@
};
};
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }:
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }: {
nixosModules.default = ({ pkgs, ... }: {
imports = [ ./module.nix ];
# defined overlays injected by the nixflake
nixpkgs.overlays = [
(_self: _super: {
vrchat-prometheus-adapter = self.packages.${pkgs.system}.vrchat-prometheus-adapter;
})
];
});
} //
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
@ -74,6 +84,17 @@
my-crate = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
dockerImage = pkgs.dockerTools.buildImage {
name = "vrchat-prometheus-exporter";
config = {
Cmd = [ "${my-crate}/bin/vr-event-tracker" ];
ExposedPorts = {
"6534/tcp" = {};
};
};
};
in
{
checks = {
@ -123,6 +144,7 @@
packages = {
default = my-crate;
docker = dockerImage;
my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
inherit cargoArtifacts;
});
@ -143,9 +165,8 @@
cargo
rustc
rust-analyzer
sqlite
sqlx-cli
cargo-flamegraph
cargo-bloat
];
};
});

View file

@ -28,7 +28,6 @@ static WORLD_FAVORITES: OnceLock<IntCounterVec> = OnceLock::new();
enum WsError {
Reqwest(reqwest::Error),
Url(url::ParseError),
Custom(String),
}
impl From<url::ParseError> for WsError {
@ -49,7 +48,6 @@ impl fmt::Display for WsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
WsError::Reqwest(e) => write!(f, "Reqwest error: {}", e),
WsError::Custom(e) => write!(f, "Error: {}", e),
WsError::Url(_) => todo!(),
}
}
@ -107,10 +105,7 @@ struct VrcGroupInstance {
#[derive(Clone, Debug, Deserialize)]
struct VrcWorldData {
favorites: u64,
version: f64,
visits: u64,
popularity: f64,
heat: f64,
#[serde(rename = "publicOccupants")]
public_occupants: f64,
#[serde(rename = "privateOccupants")]
@ -227,6 +222,7 @@ async fn group_metrics(
name: String,
group: VrcGroup,
) -> Result<(), WsError> {
if !group.id.is_empty() {
let instance_list_url = format!(
"https://api.vrchat.cloud/api/1/groups/{}/instances",
group.id
@ -246,7 +242,7 @@ async fn group_metrics(
let instances: Vec<VrcInstance> = data
.into_iter()
.map(|f| {
let spl: Vec<&str> = f.location.split(":").collect();
let spl: Vec<&str> = f.location.split(':').collect();
VrcInstance {
instance: Some(spl[0].to_owned()),
world: Some(spl[1].to_owned()),
@ -286,6 +282,7 @@ async fn group_metrics(
])
.set(data.user_count.unwrap_or(0 as f64));
}
}
if group.vrcdn.is_some() {
let vrcdn_url = format!("https://api.vrcdn.live/v1/viewers/{}", group.vrcdn.unwrap());