Merge pull request 'merge dev to master for infra pr' (#20) from dev into master
Reviewed-on: #20
This commit was merged in pull request #20.
This commit is contained in:
@@ -11,15 +11,16 @@ config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
#if config.config_file_name is not None:
|
||||
# fileConfig(config.config_file_name, disable_existing_loggers=False)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
from app.model.models import Base
|
||||
target_metadata = Base.metadata
|
||||
from app.model import models
|
||||
|
||||
target_metadata = models.Base.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
|
||||
@@ -8,4 +8,4 @@ SECRET_KEY="8b14d0b447bff7efa24d5019cc59a999786e31f6f865173bbd642bf18de5ad85"
|
||||
#Key for oauth
|
||||
#THESE ARE TESTING KEYS - DO NOT USE IN PROD
|
||||
|
||||
SQLALCHEMY_DATABASE_URL="sqlite:///./gatekeeper.db"
|
||||
SQLALCHEMY_DATABASE_PATH="./gatekeeper.db"
|
||||
|
||||
@@ -5,19 +5,21 @@ from sqlmodel import Session, SQLModel, create_engine
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = getenv("SQLALCHEMY_DATABASE_URL", "sqlite:///./gatekeeper.db")
|
||||
SQLALCHEMY_DATABASE_PATH = getenv("SQLALCHEMY_DATABASE_PATH", "./gatekeeper.db")
|
||||
SQLALCHEMY_DATABASE_URL = "sqlite:///" + SQLALCHEMY_DATABASE_PATH
|
||||
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||
|
||||
|
||||
def create_db_and_tables():
|
||||
if not path.exists(SQLALCHEMY_DATABASE_URL):
|
||||
if not path.exists(SQLALCHEMY_DATABASE_PATH):
|
||||
SQLModel.metadata.create_all(engine)
|
||||
from alembic.config import Config
|
||||
|
||||
from alembic import command
|
||||
|
||||
alembic_cfg = Config("./alembic.ini")
|
||||
alembic_cfg.attributes["sqlalchemy.url"] = SQLALCHEMY_DATABASE_URL
|
||||
command.stamp(alembic_cfg, "head")
|
||||
logger.info("Database created and tables initialized.")
|
||||
else:
|
||||
|
||||
@@ -11,7 +11,7 @@ def verify_settings():
|
||||
"MIFARE_ACL_WRITE_BASE_KEY",
|
||||
]
|
||||
important_envs = ["SECRET_KEY"]
|
||||
other_envs = ["SQLALCHEMY_DATABASE_URL"]
|
||||
other_envs = ["SQLALCHEMY_DATABASE_PATH"]
|
||||
for setting in card_envs:
|
||||
if (setting not in os.environ or setting == "") and not os.getenv(
|
||||
"DISABLE_CARDS"
|
||||
@@ -26,4 +26,4 @@ def verify_settings():
|
||||
)
|
||||
for setting in other_envs:
|
||||
if setting not in os.environ:
|
||||
logger.critical(f"Env var {setting} not set. Continuing with defaults.")
|
||||
logger.warning(f"Env var {setting} not set. Continuing with defaults.")
|
||||
|
||||
@@ -123,6 +123,7 @@
|
||||
'');
|
||||
};
|
||||
});
|
||||
nixosModules = { gatekeeper = import ./module.nix; };
|
||||
nixosModules.gatekeeper = { config, pkgs, lib, ... }@args:
|
||||
import ./module.nix (args // { self = self; system = pkgs.system; });
|
||||
};
|
||||
}
|
||||
|
||||
24
module.nix
24
module.nix
@@ -8,33 +8,41 @@ in
|
||||
enable = lib.mkEnableOption "Enable the gatekeeper api service.";
|
||||
dotenv = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = null;
|
||||
description = "The path to a .env file with the keys";
|
||||
};
|
||||
db = {
|
||||
db = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = null;
|
||||
description = "Where to save the database.";
|
||||
};
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
users.extraGroups.gatekeeper = {};
|
||||
users.extraUsers.gatekeeper = {
|
||||
users.groups.gatekeeper = {};
|
||||
users.users.gatekeeper = {
|
||||
description = "gatekeeper user";
|
||||
group = "gatekeeper";
|
||||
isSystemUser = true;
|
||||
};
|
||||
environment.systemPackages = [self.packages.${system}.default];
|
||||
services.pcscd = {
|
||||
enable = true;
|
||||
plugins = [ pkgs.acsccid ];
|
||||
};
|
||||
networking.firewall.allowedTCPPorts = [ 8000 ];
|
||||
systemd.services.gatekeeper = {
|
||||
description = "Runs the gatekeeper api";
|
||||
script = ''
|
||||
export LD_LIBRARY_PATH="${lib.getLib pkgs.legacyPackages.${system}.pcsclite}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||
exec ${self.packages.${system}.default}/bin/fastapi run ${self}/app/main.py
|
||||
export LD_LIBRARY_PATH="${lib.getLib pkgs.pcsclite}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||
exec ${self.packages.${system}.default}/bin/uvicorn --host 0.0.0.0 --port 8000 --app-dir ${self} app.main:app
|
||||
'';
|
||||
after = [ "network.target" ];
|
||||
wantedBy = ["multi-user.target"];
|
||||
|
||||
serviceConfig = {
|
||||
User = "gatekeeper";
|
||||
Restart = "on-failure";
|
||||
RestartSec = "20";
|
||||
StateDirectory = "gatekeeper";
|
||||
WorkingDirectory = "/var/lib/gatekeeper";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user