Compare commits

..

No commits in common. "45c53ec1502cb3d0d819c47bfa7a3fa7d2e4bdee" and "1983508fb17b4b8ca2b27536d64e382fd5cdbf9a" have entirely different histories.

5 changed files with 24 additions and 3 deletions

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ result*
*screenshot.png
output
todo
log/

View file

@ -31,6 +31,7 @@ in
DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3";
# locally: use a fixed relative reference, so we can use our newest files without copying to the store
REPO_DIR = toString ../.;
LOGGING_DIR = "../log";
};
shellHook = ''
ln -sf ${sources.htmx}/dist/htmx.js src/panel/static/htmx.min.js

View file

@ -30,6 +30,7 @@ let
(builtins.toFile "extra-settings.py" cfg.extra-settings)
];
REPO_DIR = import ../../launch/tf-env.nix { inherit lib pkgs; };
LOGGING_DIR = "/var/log/${name}";
SSH_PRIVATE_KEY_FILE = config.age.secrets.panel-ssh-key.path;
};

View file

@ -176,6 +176,9 @@ COMPRESS_PRECOMPILERS = [
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
logging_dir = env["LOGGING_DIR"]
os.makedirs(logging_dir, mode=0o700, exist_ok=True)
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
@ -214,15 +217,24 @@ LOGGING = {
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
"file": {
"level": "INFO",
"class": "logging.FileHandler",
"filename": f"{logging_dir}/info.log",
},
},
"loggers": {
"": {
"handlers": ["console"],
"handlers": ["console", "file"],
"level": "DEBUG" if DEBUG else "INFO",
},
},
}
SECONDS_PER_MINUTE = 60
DEPLOY_TIMEOUT_MINUTES = 25
DEPLOY_TIMEOUT_SECONDS = DEPLOY_TIMEOUT_MINUTES * SECONDS_PER_MINUTE
# Customization via user settings
# This must be at the end, as it must be able to override the above
# TODO(@fricklerhandwerk):

View file

@ -1,6 +1,7 @@
from enum import Enum
import json
from os.path import expanduser
from subprocess import Popen, PIPE, STDOUT
import subprocess
import logging
import os
@ -160,6 +161,11 @@ class DeploymentStatus(ConfigurationForm):
"--auto-approve",
"-lock=false",
]
deployment_result = subprocess.run(cmd, cwd=cwd, env=env)
logging.info(deployment_result)
popen = Popen(cmd, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)
with popen.stdout:
for line in iter(popen.stdout.readline, b''):
logger.info(line.decode('utf-8').strip())
# FIXME catch subprocess.TimeoutExpired
deployment_result = popen.wait(timeout=settings.DEPLOY_TIMEOUT_SECONDS)
logger.info(f"deployment_result: {deployment_result}")
return deployment_result, deployment_params