docker-healthchecks/flake.nix

351 lines
10 KiB
Nix
Raw Normal View History

2023-04-15 19:01:10 -05:00
{
description = "Healthchecks";
inputs = {
nixpkgs = {
2024-06-20 09:20:17 -05:00
url = "nixpkgs/nixos-23.11";
# url = "github:natsukium/nixpkgs/pydantic2";
2023-04-15 19:01:10 -05:00
};
};
2023-11-26 09:00:03 -06:00
outputs = {
self,
nixpkgs,
} @ inputs: let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
py = pkgs.python3.override {
packageOverrides = final: prev: {
django = prev.django_4;
2024-06-20 09:20:17 -05:00
# cronsim = let
# version = "2.5";
# pname = "cronsim";
# src = pkgs.fetchPypi {
# inherit pname version;
# hash = "sha256-FTzwIZ3MGgyp5xqDav22B5ZTfYxSHGhsenMTSDdXM78=";
# };
# in
# prev.buildPythonPackage {
# inherit pname version src;
# # nativeCheckInputs = [ prev.pytestCheckHook ];
# pythonImportsCheck = [
# "cronsim"
# ];
# };
2023-04-15 19:01:10 -05:00
};
2023-11-26 09:00:03 -06:00
};
baseImage = {
tag = "latest";
maxLayers = 2;
contents = [
pkgs.bash
pkgs.coreutils-full
];
config = {
User = "5000:5000";
Volumes = {
"/tmp" = {};
2023-04-15 22:30:12 -05:00
};
2023-11-26 09:00:03 -06:00
WorkingDir = "${self.packages.${system}.healthchecks}/app";
Env = [
"LANG=en_US.UTF-8"
"PYTHONPATH=${self.packages.${system}.healthchecks.pythonPath}"
"PYTHONUNBUFFERED=1"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"STATIC_ROOT=${self.packages.${system}.healthchecks.static}"
2023-04-15 22:30:12 -05:00
];
};
2023-11-26 09:00:03 -06:00
};
in {
packages.${system} = {
2024-06-20 09:20:17 -05:00
oncalendar = let
in
py.pkgs.buildPythonApplication {
inherit pname version propagatedBuildInputs;
format = "other";
outputs = ["out" "static" "doc"];
src = pkgs.fetchFromGitHub {
owner = "healthchecks";
repo = pname;
rev = "v${version}";
inherit hash;
};
dontPatch = true;
dontConfigure = true;
dontBuild = true;
doCheck = false;
installPhase = ''
mkdir -p $out/app
cp -r CHANGELOG.md hc manage.py templates $out/app
chmod +x $out/app/manage.py
mkdir -p $doc
cp -r *.md LICENSE $doc
mkdir -p $static
DEBUG=False SECRET_KEY=build-key STATIC_ROOT=$static ${py}/bin/python ./manage.py collectstatic --noinput
DEBUG=False SECRET_KEY=build-key STATIC_ROOT=$static ${py}/bin/python ./manage.py compress
cp -r static-collected/* $static
cp ${localSettings} $out/app/hc/local_settings.py
'';
passthru = {
# PYTHONPATH of all dependencies used by the package
pythonPath = py.pkgs.makePythonPath propagatedBuildInputs;
tests = {
inherit (pkgs.nixosTests) healthchecks;
};
};
meta = with pkgs.lib; {
homepage = "https://github.com/healthchecks/healthchecks";
description = "A cron monitoring tool written in Python & Django ";
license = licenses.bsd3;
};
};
2023-11-26 09:00:03 -06:00
healthchecks = let
pname = "healthchecks";
2024-06-20 09:20:17 -05:00
version = "3.2";
hash = "sha256-TAhr1PeoGp/zqsnJz9C/w7auip4RdRIFSxvo6haOG0Q=";
2023-11-26 09:00:03 -06:00
localSettings = pkgs.writeText "local_settings.py" ''
import os
CSRF_TRUSTED_HOSTS = os.getenv("CSRF_TRUSTED_HOSTS", "").split(",")
STATIC_ROOT = os.getenv("STATIC_ROOT")
STATICFILES_DIRS = [ ]
SECRET_KEY_FILE = os.getenv("SECRET_KEY_FILE")
if SECRET_KEY_FILE:
with open(SECRET_KEY_FILE, "r") as file:
SECRET_KEY = file.readline()
'';
propagatedBuildInputs = with py.pkgs; [
aiosmtpd
apprise
cron-descriptor
cronsim
django
django-compressor
django-stubs-ext
fido2
minio
psycopg2
pycurl
pydantic
pyotp
segno
statsd
whitenoise
];
in
py.pkgs.buildPythonApplication {
inherit pname version propagatedBuildInputs;
format = "other";
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
outputs = ["out" "static" "doc"];
2023-05-01 18:36:48 -05:00
2023-11-26 09:00:03 -06:00
src = pkgs.fetchFromGitHub {
owner = "healthchecks";
repo = pname;
rev = "v${version}";
inherit hash;
};
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
dontPatch = true;
dontConfigure = true;
dontBuild = true;
doCheck = false;
2023-05-01 18:36:48 -05:00
2023-11-26 09:00:03 -06:00
installPhase = ''
mkdir -p $out/app
cp -r CHANGELOG.md hc manage.py templates $out/app
chmod +x $out/app/manage.py
2023-05-01 18:36:48 -05:00
2023-11-26 09:00:03 -06:00
mkdir -p $doc
cp -r *.md LICENSE $doc
2023-05-01 18:36:48 -05:00
2023-11-26 09:00:03 -06:00
mkdir -p $static
DEBUG=False SECRET_KEY=build-key STATIC_ROOT=$static ${py}/bin/python ./manage.py collectstatic --noinput
DEBUG=False SECRET_KEY=build-key STATIC_ROOT=$static ${py}/bin/python ./manage.py compress
cp -r static-collected/* $static
2023-05-23 22:44:40 -05:00
2023-11-26 09:00:03 -06:00
cp ${localSettings} $out/app/hc/local_settings.py
'';
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
passthru = {
# PYTHONPATH of all dependencies used by the package
pythonPath = py.pkgs.makePythonPath propagatedBuildInputs;
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
tests = {
inherit (pkgs.nixosTests) healthchecks;
2023-04-15 22:30:12 -05:00
};
2023-11-26 09:00:03 -06:00
};
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
meta = with pkgs.lib; {
homepage = "https://github.com/healthchecks/healthchecks";
description = "A cron monitoring tool written in Python & Django ";
license = licenses.bsd3;
2023-04-15 19:01:10 -05:00
};
2023-11-26 09:00:03 -06:00
};
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
smtpd = pkgs.dockerTools.buildLayeredImage (
pkgs.lib.attrsets.recursiveUpdate baseImage {
name = "healthchecks-smtpd";
config = {
Cmd = [
"${self.packages.${system}.healthchecks}/app/manage.py"
"smtpd"
"--port"
"2525"
];
ExposedPorts = {
"2525/tcp" = {};
2023-04-16 22:39:23 -05:00
};
2023-11-26 09:00:03 -06:00
};
}
);
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
sendalerts = pkgs.dockerTools.buildLayeredImage (
pkgs.lib.attrsets.recursiveUpdate baseImage {
name = "healthchecks-sendalerts";
config = {
Cmd = [
"${self.packages.${system}.healthchecks}/app/manage.py"
"sendalerts"
];
ExposedPorts = {};
};
}
);
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
sendreports = pkgs.dockerTools.buildLayeredImage (
pkgs.lib.attrsets.recursiveUpdate baseImage {
name = "healthchecks-sendreports";
config = {
Cmd = [
"${self.packages.${system}.healthchecks}/app/manage.py"
"sendreports"
"--loop"
];
ExposedPorts = {};
};
}
);
maintenance = let
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
pkgs.dockerTools.buildLayeredImage (
pkgs.lib.attrsets.recursiveUpdate baseImage {
2023-11-26 09:00:03 -06:00
name = "healthchecks-maintenance";
config = {
Cmd = [
2023-11-26 09:00:03 -06:00
"${script}"
];
2023-11-26 09:00:03 -06:00
ExposedPorts = {};
};
}
);
2023-11-26 09:00:03 -06:00
migrate = pkgs.dockerTools.buildLayeredImage (
pkgs.lib.attrsets.recursiveUpdate baseImage {
name = "healthchecks-migrate";
config = {
Cmd = [
"${self.packages.${system}.healthchecks}/app/manage.py"
"migrate"
];
ExposedPorts = {};
};
}
);
2023-04-15 22:30:12 -05:00
2023-11-26 09:00:03 -06:00
webserver = let
uwsgi = pkgs.uwsgi.override {
plugins = ["python3"];
};
uwsgi-ini = pkgs.writeTextFile {
name = "uwsgi.ini";
text = ''
[uwsgi]
buffer-size = 32768
chdir = ${self.packages.${system}.healthchecks}/app
die-on-term
disable-write-exception
enable-threads
harakiri = 10
http-socket = :8000
master
max-fd = 10000
mime-file = ${pkgs.mailcap}/etc/nginx/mime.types
module = hc.wsgi:application
plugins = python3
post-buffering = 16192
processes = 4
threads = 1
thunder-lock
'';
};
in
pkgs.dockerTools.buildLayeredImage (
2023-04-16 22:39:23 -05:00
pkgs.lib.attrsets.recursiveUpdate baseImage {
2023-11-26 09:00:03 -06:00
name = "healthchecks-webserver";
fakeRootCommands = '' ;
mkdir /tmp
chmod 0777 /tmp
'';
2023-04-16 22:39:23 -05:00
config = {
Cmd = [
2023-11-26 09:00:03 -06:00
"${uwsgi}/bin/uwsgi"
"${uwsgi-ini}"
2023-04-16 22:39:23 -05:00
];
2023-11-26 09:00:03 -06:00
ExposedPorts = {
"8000/tcp" = {};
};
2023-04-16 22:39:23 -05:00
};
}
);
2023-11-26 09:00:03 -06:00
static = pkgs.dockerTools.buildLayeredImage {
name = "healthchecks-static";
tag = "latest";
maxLayers = 2;
config = {
User = "5000:5000";
Cmd = [
"${pkgs.static-web-server}/bin/static-web-server"
"--port=8000"
"--root=${self.packages.${system}.healthchecks.static}"
];
ExposedPorts = {
"8000/tcp" = {};
2023-05-01 18:36:48 -05:00
};
};
2023-05-23 22:44:40 -05:00
};
2023-04-15 19:01:10 -05:00
};
2023-11-26 09:00:03 -06:00
checks.${system} = {
webserver = self.packages.${system}.webserver;
smtpd = self.packages.${system}.smtpd;
sendalerts = self.packages.${system}.sendalerts;
sendreports = self.packages.${system}.sendreports;
maintenance = self.packages.${system}.maintenance;
migrate = self.packages.${system}.migrate;
static = self.packages.${system}.static;
};
};
2023-04-15 19:01:10 -05:00
}