Containerize application

This commit is contained in:
Marsn3 2025-02-09 04:57:05 +01:00
parent a12ff2fa95
commit 19b69dc548
4 changed files with 85 additions and 15 deletions

View file

@ -1,10 +1,8 @@
import discord import discord
import os import os
import requests import requests
from dotenv import load_dotenv
from enum import Enum from enum import Enum
load_dotenv()
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
PB_TOKEN = os.getenv("PB_TOKEN") PB_TOKEN = os.getenv("PB_TOKEN")
@ -108,7 +106,7 @@ async def on_voice_state_update(
if channel and event: if channel and event:
data = Data(member, channel, event) data = Data(member, channel, event)
r = requests.post( r = requests.post(
"https://api.m3.fyi/api/collections/vc_stats/records", f"https://{PB_URL}/api/collections/{PB_COLLECTION}/records",
json=data.__dict__, json=data.__dict__,
headers={"Authorization": PB_TOKEN, "content-type": "application/json"}, headers={"Authorization": PB_TOKEN, "content-type": "application/json"},
) )

View file

@ -31,6 +31,23 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": { "gitignore": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -51,6 +68,40 @@
"type": "github" "type": "github"
} }
}, },
"mk-shell-bin": {
"locked": {
"lastModified": 1677004959,
"owner": "rrbutani",
"repo": "nix-mk-shell-bin",
"rev": "ff5d8bd4d68a347be5042e2f16caee391cd75887",
"type": "github"
},
"original": {
"owner": "rrbutani",
"repo": "nix-mk-shell-bin",
"type": "github"
}
},
"nix2container": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1730479402,
"owner": "nlewo",
"repo": "nix2container",
"rev": "5fb215a1564baa74ce04ad7f903d94ad6617e17a",
"type": "github"
},
"original": {
"owner": "nlewo",
"repo": "nix2container",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1733477122, "lastModified": 1733477122,
@ -90,9 +141,25 @@
"root": { "root": {
"inputs": { "inputs": {
"devenv": "devenv", "devenv": "devenv",
"mk-shell-bin": "mk-shell-bin",
"nix2container": "nix2container",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks" "pre-commit-hooks": "pre-commit-hooks"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -1,8 +1,18 @@
{ pkgs, lib, config, inputs, ... }: { pkgs, lib, config, inputs, ... }:
{ {
packages = [pkgs.openssl pkgs.cacert];
dotenv.enable = true;
# https://devenv.sh/languages/ # https://devenv.sh/languages/
languages.python.enable = true; languages.python.enable = true;
languages.python.venv.enable = true; languages.python.venv.enable = true;
languages.python.uv.enable = true; languages.python.uv.enable = true;
languages.python.uv.sync.enable = true;
processes.bot.exec = "uv run bot.py";
containers."bot".name = "vc-stats-bot";
containers."bot".startupCommand = config.processes.bot.exec;
containers."bot".registry = "docker://git.m3.fyi/metrik/";
containers."bot".enableLayerDeduplication = true;
#containers."processes".copyToRoot = null;
} }

View file

@ -1,15 +1,10 @@
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs: inputs:
nix2container:
url: github:nlewo/nix2container
inputs:
nixpkgs:
follows: nixpkgs
nixpkgs: nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling url: github:cachix/devenv-nixpkgs/rolling
mk-shell-bin:
# If you're using non-OSS software, you can set allowUnfree to true. url: github:rrbutani/nix-mk-shell-bin
# allowUnfree: true
# If you're willing to use a package that's vulnerable
# permittedInsecurePackages:
# - "openssl-1.1.1w"
# If you have more than one devenv you can merge them
#imports:
# - ./backend