Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baserow: 1.14.0 -> 1.28.0, baserow-front: init at 1.28.0, nixos/baserow: init, nixos/tests/baserow: init #324777

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,7 @@
./services/web-apps/atlassian/jira.nix
./services/web-apps/audiobookshelf.nix
./services/web-apps/bluemap.nix
./services/web-apps/baserow.nix
./services/web-apps/bookstack.nix
./services/web-apps/c2fmzq-server.nix
./services/web-apps/calibre-web.nix
Expand Down
254 changes: 254 additions & 0 deletions nixos/modules/services/web-apps/baserow.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{ lib, pkgs, config, ... }:
# TODO: OTEL stuff
let
inherit (lib) mkIf mkOption mkEnableOption mkPackageOptionMD mkDefault mdDoc concatStringsSep mapAttrsToList;
cfg = config.services.baserow;
penv = cfg.package.python.buildEnv.override {
extraLibs = [
(cfg.package.python.pkgs.toPythonModule cfg.package)
];
};
ui = cfg.package.ui;
pythonPath = "${penv}/${cfg.package.python.sitePackages}/";
defaultEnvironment = cfg.environment // {
PYTHONPATH = pythonPath;
};
<<<<<<< HEAD
=======
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad merge

templateNuxtProdConfig = pkgs.writeText "nuxt.config.prod.js.in" ''
import base from './nuxt.config.base.js';

export default base(
@baseModules@,
@premiumModules@,
@enterpriseModules@
)
'';
environmentAsFile = pkgs.writeText "baserow-environment" (concatStringsSep "\n"
(mapAttrsToList (key: value: "${key}=\"${toString value}\"") cfg.environment));
# TODO: handle env file and secrets.
baserowManageScript = pkgs.writeShellScriptBin "baserow-manage" ''
set -a
export PYTHONPATH=${cfg.package.pythonPath}
source ${cfg.secretFile}
source ${environmentAsFile}
sudo=exec
if [[ "$USER" != baserow ]]; then
sudo='exec /run/wrappers/bin/sudo -u baserow --preserve-env'
fi
$sudo ${cfg.package}/bin/baserow "$@"
'';
in
{
options.services.baserow = {
enable = mkEnableOption (mdDoc "baserow, you need to provide your own reverse proxy server");
package = mkPackageOptionMD pkgs "baserow" {};

listenAddress = mkOption {
type = lib.types.str;
default = "[::1]";
description = lib.mdDoc ''
Address the server will listen on.
'';
};

port = mkOption {
type = lib.types.port;
default = 8000;
description = lib.mdDoc ''
Port the server will listen on.
'';
};

environment = mkOption {
type = lib.types.submodule {
freeformType = with lib.types; attrsOf (oneOf [ int str path ]);
};
default = {};
description = "Environment variables passed to Baserow, use this to configure the service.";
};
secretFile = mkOption {
default = null;
type = lib.types.nullOr lib.types.path;
description = "Secrets that should not end up in the Nix store.";
};
};

config = mkIf cfg.enable {
services.baserow.environment = {
DATABASE_URL = mkDefault "postgresql:///baserow";
REDIS_URL = mkDefault "redis+socket://${config.services.redis.servers.baserow.unixSocket}";
REDIS_BEAT_URL = mkDefault "unix://${config.services.redis.servers.baserow.unixSocket}";
DJANGO_REDIS_URL = mkDefault "unix://${config.services.redis.servers.baserow.unixSocket}";
DJANGO_CHANNEL_REDIS_URL = mkDefault "unix://${config.services.redis.servers.baserow.unixSocket}";
DJANGO_SETTINGS_MODULE = mkDefault "baserow.config.settings.base";
BASEROW_TRIGGER_SYNC_TEMPLATES_AFTER_MIGRATION = mkDefault "false";
NUXT_TELEMETRY_DISABLED = mkDefault "1";
};

services.redis.servers.baserow.enable = true;
services.postgresql = {
enable = true;
ensureDatabases = [ "baserow" ];
ensureUsers = [
{
name = "baserow";
ensurePermissions."DATABASE baserow" = "ALL PRIVILEGES";
}
];
};

environment.systemPackages = [ baserowManageScript ];
systemd.targets.baserow = {
description = "Target for all Baserow services";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" "redis-baserow.service" ];
};

systemd.services =
let
defaultServiceConfig = {
WorkingDirectory = "/var/lib/baserow";
User = "baserow";
Group = "baserow";
StateDirectory = "baserow";
StateDirectoryMode = "0750";
Restart = "on-failure";

EnvironmentFile = mkIf (cfg.secretFile != null) [ cfg.secretFile ];
};
in
{
baserow-prepare = {
description = "Baserow migrations & misc service";
wantedBy = [ "baserow.target" ];
after = [ "postgresql.service" ];

environment = defaultEnvironment;
path = [ baserowManageScript ];

serviceConfig = defaultServiceConfig // {
Type = "oneshot";
ExecStart = ''
${baserowManageScript}/bin/baserow-manage migrate
${baserowManageScript}/bin/baserow-manage sync_templates
'';
};
};
baserow-nuxt = {
description = "Baserow Nuxt service (frontend)";
wantedBy = [ "baserow.target" ];
requires = [ "baserow-prepare.service" ];
after = [ "baserow-prepare.service" ];

environment = defaultEnvironment // {
NODE_MODULES = "${ui}/node_modules";
NODE_OPTIONS = "--openssl-legacy-provider";
};

preStart = ''
ln -sf ${ui}/.nuxt /var/lib/baserow/.nuxt
'';

serviceConfig = defaultServiceConfig // {
WorkingDirectory = "/var/lib/baserow";
# https://github.com/nuxt/nuxt/issues/20714
ExecStart = ''
${ui}/node_modules/.bin/nuxt start
=======
NODE_OPTIONS = "--openssl-legacy-provider --dns-result-order=verbatim";
};

preStart = ''
ln -sf ${ui}/web-frontend/.nuxt /var/lib/baserow/frontend/
ln -sf ${ui}/premium /var/lib/baserow/
ln -sf ${ui}/enterprise /var/lib/baserow/
ln -sf ${ui}/web-frontend/modules /var/lib/baserow/frontend/
mkdir -p /var/lib/baserow/frontend/config
${pkgs.xorg.lndir}/bin/lndir -ignorelinks ${ui}/web-frontend/config /var/lib/baserow/frontend/config
ln -sf ${(pkgs.substituteAll {
src = templateNuxtProdConfig;
baseImport = "${ui}/web-frontend/config/nuxt.config.base.js";
baseModules = "${ui}/web-frontend";
premiumModules = "${ui}/premium/web-frontend";
enterpriseModules = "${ui}/enterprise/web-frontend";
})} /var/lib/baserow/frontend/config/nuxt.config.prod.js
'';

serviceConfig = defaultServiceConfig // {
WorkingDirectory = "/var/lib/baserow/frontend";
StateDirectory = [ "baserow" "baserow/frontend" ];
# https://github.com/nuxt/nuxt/issues/20714
ExecStart = ''
${ui}/web-frontend/node_modules/.bin/nuxt start --config-file config/nuxt.config.local.js
>>>>>>> e3b5d8d20811 (nixos module)
'';
};
};
baserow-wsgi = {
description = "Baserow WSGI service (backend)";
wantedBy = [ "baserow.target" ];
requires = [ "baserow-prepare.service" ];
after = [ "baserow-prepare.service" ];

environment = defaultEnvironment;

# On worker temp dir: https://github.com/bram2w/baserow/blob/master/backend/docker/docker-entrypoint.sh#L205C12-L206
serviceConfig = defaultServiceConfig // {
RuntimeDirectory = "baserow";
ExecStart = ''
${cfg.package.python.pkgs.gunicorn}/bin/gunicorn \
-k uvicorn.workers.UvicornWorker \
baserow.config.asgi:application \
--worker-tmp-dir=/run/baserow \
--log-file=- \
--access-logfile=- \
--capture-output \
--bind ${cfg.listenAddress}:${toString cfg.port} \
'';
};
};
baserow-celery-worker = {
description = "Baserow Celery workers service";
wantedBy = [ "baserow.target" ];
requires = [ "baserow-wsgi.service" ];
after = [ "baserow-wsgi.service" ];

environment = defaultEnvironment;

serviceConfig = defaultServiceConfig // {
ExecStart = ''
${cfg.package.python.pkgs.celery}/bin/celery -A baserow worker \
-l INFO \
-Q celery,export \
-n "default-worker@%h"
'';
};
};
# baserow-celery-exportworker = {};
baserow-celery-beat = {
description = "Baserow scheduler service";
wantedBy = [ "baserow.target" ];
requires = [ "baserow-celery-worker.service" ];
after = [ "baserow-celery-worker.service" ];

environment = defaultEnvironment;

serviceConfig = defaultServiceConfig // {
ExecStart = ''
${cfg.package.python.pkgs.celery}/bin/celery -A baserow beat \
-l INFO \
-S redbeat.RedBeatScheduler
'';
};
};
};

users.users.baserow = {
isSystemUser = true;
group = "baserow";
};
users.groups.baserow = {};
users.groups."${config.services.redis.servers.baserow.user}".members = [ "baserow" ];
};
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ in {
avahi-with-resolved = handleTest ./avahi.nix { networkd = true; };
ayatana-indicators = runTest ./ayatana-indicators.nix;
babeld = handleTest ./babeld.nix {};
baserow = handleTest ./web-apps/baserow.nix {};
bazarr = handleTest ./bazarr.nix {};
bcachefs = handleTestOn ["x86_64-linux" "aarch64-linux"] ./bcachefs.nix {};
beanstalkd = handleTest ./beanstalkd.nix {};
Expand Down
82 changes: 82 additions & 0 deletions nixos/tests/web-apps/baserow.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import ../make-test-python.nix ({ lib, pkgs, ... }: {
name = "baserow";

meta = with lib.maintainers; {
maintainers = [ raitobezarius julienmalka ];
};

nodes.machine = { ... }: {
services.baserow = {
enable = true;
environment = {
# Needed for the frontend.
PUBLIC_BACKEND_URL = "http://localhost/api/";
BASEROW_DISABLE_PUBLIC_URL_CHECK = "1";
PRIVATE_BACKEND_URL = "http://[::1]:8000";
BASEROW_PUBLIC_URL = "http://localhost";
BASEROW_BACKEND_DEBUG = "on";
BASEROW_BACKEND_LOG_LEVEL = "DEBUG";
# Ensure we are allowed to do those requests.
BASEROW_EXTRA_ALLOWED_HOSTS = "localhost,[::1],127.0.0.1";
};
# Do not do this in production.
secretFile = pkgs.writeText "secret" ''
SECRET_KEY=aaaaaaaaaaaaaaaaaaaaaaaa
'';
};

services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts."localhost" = {
locations."~ ^/(api|ws)/" = {
proxyPass = "http://[::1]:8000";
proxyWebsockets = true;
};
locations."/media/" = {
extraConfig = ''
if ($arg_dl) {
add_header Content-disposition "attachment; filename=$arg_dl";
}
alias /var/lib/baserow/media;
'';
};
locations."/" = {
proxyPass = "http://[::1]:3000";
};
};
};
};

testScript = { nodes }: ''
machine.start()
machine.wait_for_unit("baserow.target")
machine.wait_for_open_port(8000)

print(machine.succeed(
"curl -H 'Host: localhost' -sSfL http://[::1]:8000/api/settings/"
))
# [::1] is not an allowed host.
machine.fail(
"curl -sSfL http://[::1]:8000/api/settings/"
)
machine.wait_for_unit("nginx.service")
machine.wait_for_open_port(80)

# Backend
print(machine.succeed(
"curl -sSfL http://localhost/api/_health/"
))

# Frontend
machine.wait_for_unit("baserow-nuxt.service")
machine.wait_for_open_port(3000)
# Test connection to backend through frontend
print(machine.succeed(
"curl -sSfL http://localhost/login/"
))
print(machine.succeed(
"curl -sSfL http://localhost/_health/"
))
'';
})
26 changes: 26 additions & 0 deletions pkgs/by-name/ba/baserow/0001-backend-package-HTML-templates.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From d30489f46fec68ee2ddd369963fe22ed37999d81 Mon Sep 17 00:00:00 2001
From: Raito Bezarius <[email protected]>
Date: Mon, 8 May 2023 07:44:16 +0200
Subject: [PATCH] backend: package HTML templates

---
setup.py | 3 +++
1 file changed, 3 insertions(+)

diff --git a/setup.py b/setup.py
index 0309d164..bee79602 100644
--- a/setup.py
+++ b/setup.py
@@ -30,6 +30,9 @@ setup(
"technical expertise. Build a table and define custom fields "
"like text, number, file and many more.",
platforms=["linux"],
+ package_data={
+ 'baserow.core': ['templates/*.html', 'templates/*.eta', 'templates/**/*.eta', 'templates/**/*.html']
+ },
package_dir={"": "src"},
packages=find_packages("src"),
include_package_data=True,
--
2.40.1

Loading
Loading