Fix linting, build-test-publish workflow, Docker image
This commit is contained in:
parent
012771f2fb
commit
466f00dd0e
110
.forgejo/workflows/build-test.yml
Normal file
110
.forgejo/workflows/build-test.yml
Normal 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
7
Cargo.lock
generated
|
@ -670,16 +670,9 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"memchr",
|
"memchr",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"protobuf",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "protobuf"
|
|
||||||
version = "2.28.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.33"
|
version = "1.0.33"
|
||||||
|
|
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = "0.6.20"
|
axum = "0.6.20"
|
||||||
prometheus = "0.13.3"
|
prometheus = { version = "0.13.3", default-features = false }
|
||||||
tokio = { version = "1.29.1", features = [ "full" ] }
|
tokio = { version = "1.29.1", features = [ "full" ] }
|
||||||
serde = { version = "1.0.189", features = [ "derive" ] }
|
serde = { version = "1.0.189", features = [ "derive" ] }
|
||||||
toml = "0.8.2"
|
toml = "0.8.2"
|
||||||
|
|
27
flake.nix
27
flake.nix
|
@ -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:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
|
@ -74,6 +84,17 @@
|
||||||
my-crate = craneLib.buildPackage (commonArgs // {
|
my-crate = craneLib.buildPackage (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
inherit cargoArtifacts;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dockerImage = pkgs.dockerTools.buildImage {
|
||||||
|
name = "vrchat-prometheus-exporter";
|
||||||
|
config = {
|
||||||
|
Cmd = [ "${my-crate}/bin/vr-event-tracker" ];
|
||||||
|
ExposedPorts = {
|
||||||
|
"6534/tcp" = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
checks = {
|
checks = {
|
||||||
|
@ -123,6 +144,7 @@
|
||||||
|
|
||||||
packages = {
|
packages = {
|
||||||
default = my-crate;
|
default = my-crate;
|
||||||
|
docker = dockerImage;
|
||||||
my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
|
my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
|
||||||
inherit cargoArtifacts;
|
inherit cargoArtifacts;
|
||||||
});
|
});
|
||||||
|
@ -143,9 +165,8 @@
|
||||||
cargo
|
cargo
|
||||||
rustc
|
rustc
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
sqlite
|
|
||||||
sqlx-cli
|
|
||||||
cargo-flamegraph
|
cargo-flamegraph
|
||||||
|
cargo-bloat
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,7 +28,6 @@ static WORLD_FAVORITES: OnceLock<IntCounterVec> = OnceLock::new();
|
||||||
enum WsError {
|
enum WsError {
|
||||||
Reqwest(reqwest::Error),
|
Reqwest(reqwest::Error),
|
||||||
Url(url::ParseError),
|
Url(url::ParseError),
|
||||||
Custom(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<url::ParseError> for WsError {
|
impl From<url::ParseError> for WsError {
|
||||||
|
@ -49,7 +48,6 @@ impl fmt::Display for WsError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
WsError::Reqwest(e) => write!(f, "Reqwest error: {}", e),
|
WsError::Reqwest(e) => write!(f, "Reqwest error: {}", e),
|
||||||
WsError::Custom(e) => write!(f, "Error: {}", e),
|
|
||||||
WsError::Url(_) => todo!(),
|
WsError::Url(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,10 +105,7 @@ struct VrcGroupInstance {
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
struct VrcWorldData {
|
struct VrcWorldData {
|
||||||
favorites: u64,
|
favorites: u64,
|
||||||
version: f64,
|
|
||||||
visits: u64,
|
visits: u64,
|
||||||
popularity: f64,
|
|
||||||
heat: f64,
|
|
||||||
#[serde(rename = "publicOccupants")]
|
#[serde(rename = "publicOccupants")]
|
||||||
public_occupants: f64,
|
public_occupants: f64,
|
||||||
#[serde(rename = "privateOccupants")]
|
#[serde(rename = "privateOccupants")]
|
||||||
|
@ -227,6 +222,7 @@ async fn group_metrics(
|
||||||
name: String,
|
name: String,
|
||||||
group: VrcGroup,
|
group: VrcGroup,
|
||||||
) -> Result<(), WsError> {
|
) -> Result<(), WsError> {
|
||||||
|
if !group.id.is_empty() {
|
||||||
let instance_list_url = format!(
|
let instance_list_url = format!(
|
||||||
"https://api.vrchat.cloud/api/1/groups/{}/instances",
|
"https://api.vrchat.cloud/api/1/groups/{}/instances",
|
||||||
group.id
|
group.id
|
||||||
|
@ -246,7 +242,7 @@ async fn group_metrics(
|
||||||
let instances: Vec<VrcInstance> = data
|
let instances: Vec<VrcInstance> = data
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
let spl: Vec<&str> = f.location.split(":").collect();
|
let spl: Vec<&str> = f.location.split(':').collect();
|
||||||
VrcInstance {
|
VrcInstance {
|
||||||
instance: Some(spl[0].to_owned()),
|
instance: Some(spl[0].to_owned()),
|
||||||
world: Some(spl[1].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));
|
.set(data.user_count.unwrap_or(0 as f64));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if group.vrcdn.is_some() {
|
if group.vrcdn.is_some() {
|
||||||
let vrcdn_url = format!("https://api.vrcdn.live/v1/viewers/{}", group.vrcdn.unwrap());
|
let vrcdn_url = format!("https://api.vrcdn.live/v1/viewers/{}", group.vrcdn.unwrap());
|
||||||
|
|
Loading…
Reference in a new issue