From 19b69dc54817db5fbf58d4e64074611aa5a1e3cd Mon Sep 17 00:00:00 2001 From: Marsn3 Date: Sun, 9 Feb 2025 04:57:05 +0100 Subject: [PATCH] Containerize application --- src/bot/bot.py | 4 +-- src/bot/devenv.lock | 67 +++++++++++++++++++++++++++++++++++++++++++++ src/bot/devenv.nix | 10 +++++++ src/bot/devenv.yaml | 19 +++++-------- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/src/bot/bot.py b/src/bot/bot.py index 91cbee6..c026cef 100644 --- a/src/bot/bot.py +++ b/src/bot/bot.py @@ -1,10 +1,8 @@ import discord import os import requests -from dotenv import load_dotenv from enum import Enum -load_dotenv() DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") PB_TOKEN = os.getenv("PB_TOKEN") @@ -108,7 +106,7 @@ async def on_voice_state_update( if channel and event: data = Data(member, channel, event) r = requests.post( - "https://api.m3.fyi/api/collections/vc_stats/records", + f"https://{PB_URL}/api/collections/{PB_COLLECTION}/records", json=data.__dict__, headers={"Authorization": PB_TOKEN, "content-type": "application/json"}, ) diff --git a/src/bot/devenv.lock b/src/bot/devenv.lock index 96842bf..aa6ba70 100644 --- a/src/bot/devenv.lock +++ b/src/bot/devenv.lock @@ -31,6 +31,23 @@ "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": { "inputs": { "nixpkgs": [ @@ -51,6 +68,40 @@ "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": { "locked": { "lastModified": 1733477122, @@ -90,9 +141,25 @@ "root": { "inputs": { "devenv": "devenv", + "mk-shell-bin": "mk-shell-bin", + "nix2container": "nix2container", "nixpkgs": "nixpkgs", "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", diff --git a/src/bot/devenv.nix b/src/bot/devenv.nix index 5fd7ae6..243dd9e 100644 --- a/src/bot/devenv.nix +++ b/src/bot/devenv.nix @@ -1,8 +1,18 @@ { pkgs, lib, config, inputs, ... }: { + packages = [pkgs.openssl pkgs.cacert]; + dotenv.enable = true; # https://devenv.sh/languages/ languages.python.enable = true; languages.python.venv.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; } diff --git a/src/bot/devenv.yaml b/src/bot/devenv.yaml index 116a2ad..225fdb4 100644 --- a/src/bot/devenv.yaml +++ b/src/bot/devenv.yaml @@ -1,15 +1,10 @@ -# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json inputs: + nix2container: + url: github:nlewo/nix2container + inputs: + nixpkgs: + follows: nixpkgs nixpkgs: url: github:cachix/devenv-nixpkgs/rolling - -# If you're using non-OSS software, you can set allowUnfree to true. -# 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 + mk-shell-bin: + url: github:rrbutani/nix-mk-shell-bin