update to 3.6 - use nushell
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jeffrey C. Ollie 2024-09-07 12:11:45 -05:00
parent 49d8b0a5c0
commit 8c865ae822
Signed by: jeff
GPG key ID: 6F86035A6D97044E
2 changed files with 88 additions and 14 deletions

View file

@ -4,19 +4,18 @@
inputs = { inputs = {
nixpkgs = { nixpkgs = {
url = "nixpkgs/nixos-24.05"; url = "nixpkgs/nixos-24.05";
# url = "github:natsukium/nixpkgs/pydantic2";
}; };
}; };
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
} @ inputs: let }: let
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
}; };
py = pkgs.python3.override { py = pkgs.python312.override {
packageOverrides = final: prev: { packageOverrides = final: prev: {
django = prev.django_5; django = prev.django_5;
}; };
@ -47,7 +46,8 @@
packages.${system} = { packages.${system} = {
healthchecks = let healthchecks = let
pname = "healthchecks"; pname = "healthchecks";
version = "3.4"; version = "3.6";
hash = "sha256-aKt9L3ZgZ8HffcNNJaR+hAI38raWuLp2q/6+rvkl2pM=";
secrets = [ secrets = [
"DB_PASSWORD" "DB_PASSWORD"
"DISCORD_CLIENT_SECRET" "DISCORD_CLIENT_SECRET"
@ -64,7 +64,6 @@
"TRELLO_APP_KEY" "TRELLO_APP_KEY"
"TWILIO_AUTH" "TWILIO_AUTH"
]; ];
hash = "sha256-hiuw7XfCDy+9fzuQMaeN9+XsENeBI1RNXy8IM1HIFhI=";
localSettings = pkgs.writeText "local_settings.py" '' localSettings = pkgs.writeText "local_settings.py" ''
import os import os
CSRF_TRUSTED_HOSTS = os.getenv("CSRF_TRUSTED_HOSTS", "").split(",") CSRF_TRUSTED_HOSTS = os.getenv("CSRF_TRUSTED_HOSTS", "").split(",")
@ -195,15 +194,27 @@
); );
maintenance = let maintenance = let
script = pkgs.writeShellScript "maintenance" '' script = pkgs.writeTextFile {
CURL_OPTIONS="--fail --silent --show-error --max-time 10 --retry 5 --output /dev/null" name = "maintenance";
${pkgs.curl}/bin/curl $CURL_OPTIONS http://webserver.healthchecks.svc/ping/$MAINTENANCE_CHECK_UUID/start text = pkgs.lib.concatStringsSep "\n" [
${self.packages.${system}.healthchecks}/app/manage.py prunenotifications #!${pkgs.nushell}/bin/nu"
${self.packages.${system}.healthchecks}/app/manage.py pruneusers ""
${self.packages.${system}.healthchecks}/app/manage.py prunetokenbucket "alias manage = ${self.packages.${system}.healthchecks}/app/manage.py"
${self.packages.${system}.healthchecks}/app/manage.py pruneflips ""
${pkgs.curl}/bin/curl $CURL_OPTIONS http://webserver.healthchecks.svc/ping/$MAINTENANCE_CHECK_UUID (builtins.readFile ./maintenance.nu)
''; ];
executable = true;
destination = "/bin/maintenance";
};
# script = pkgs.writeShellScript "maintenance" ''
# CURL_OPTIONS="--fail --silent --show-error --max-time 10 --retry 5 --output /dev/null"
# ${pkgs.curl}/bin/curl $CURL_OPTIONS http://webserver.healthchecks.svc/ping/$MAINTENANCE_CHECK_UUID/start
# ${self.packages.${system}.healthchecks}/app/manage.py prunenotifications
# ${self.packages.${system}.healthchecks}/app/manage.py pruneusers
# ${self.packages.${system}.healthchecks}/app/manage.py prunetokenbucket
# ${self.packages.${system}.healthchecks}/app/manage.py pruneflips
# ${pkgs.curl}/bin/curl $CURL_OPTIONS http://webserver.healthchecks.svc/ping/$MAINTENANCE_CHECK_UUID
# '';
in in
pkgs.dockerTools.buildLayeredImage ( pkgs.dockerTools.buildLayeredImage (
pkgs.lib.attrsets.recursiveUpdate baseImage { pkgs.lib.attrsets.recursiveUpdate baseImage {

63
maintenance.nu Normal file
View file

@ -0,0 +1,63 @@
def healthcheck_start [
url: record
] {
if not ($env | get -i HEALTHCHECK_URL | is-empty ) {
http get --full --max-time 10 ($url | update path $"($in.path)/start" | url join) | ignore
}
}
def healthcheck_log [
url: record
log: string
] {
if not ($url | is-empty ) {
http post --max-time 10 ($url | update path $"($in.path)/log" | url join) $log | ignore
}
}
def healthcheck_fail [
url: record
log: string
] {
if not ($url | is-empty ) {
http post --full --max-time 10 ($url | update path $"($in.path)/fail" | url join) $log | ignore
}
}
def healthcheck_stop [
url: record
] {
if not ($url | is-empty ) {
http get --full --max-time 10 ($url | url join) | ignore
}
}
def main [] {
let rid = (random uuid)
let healthcheck_url = if not ($env | get -i HEALTHCHECK_URL | is-empty) {
$env.HEALTHCHECK_URL | url parse | update params ($in | get params | insert rid $rid)
} else {
{}
}
healthcheck_start $healthcheck_url
let result = (do {manage prunenotifications} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
let result = (do {manage pruneusers} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
let result = (do {manage prunetokenbucket} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
let result = (do {manage pruneflips} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
healthcheck_stop $healthcheck_url
}