Skip to content

Commit 9dbfccb

Browse files
committed
Add pallas as staging server
1 parent 83c1cbc commit 9dbfccb

File tree

4 files changed

+163
-0
lines changed

4 files changed

+163
-0
lines changed

nix/hosts/pallas/configuration.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
flake,
3+
inputs,
4+
pkgs,
5+
perSystem,
6+
...
7+
}:
8+
{
9+
imports = [
10+
inputs.staging.nixosModules.hardware-proxmox-lxc
11+
inputs.staging.nixosModules.server-j3ff
12+
inputs.srvos.nixosModules.mixins-nginx
13+
flake.nixosModules.strykeforce-website
14+
./postgresql.nix
15+
./strykeforce-sync.nix
16+
./strykeforce-website.nix
17+
];
18+
19+
networking.hostName = "pallas";
20+
nixpkgs.hostPlatform = "x86_64-linux";
21+
22+
system.stateVersion = "21.11";
23+
}

nix/hosts/pallas/postgresql.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ config, pkgs, ... }:
2+
let
3+
backupDir = "/mnt/backup/postgres";
4+
in
5+
{
6+
services.postgresql = {
7+
enable = true;
8+
package = pkgs.postgresql_15;
9+
settings = {
10+
unix_socket_directories = "/run/postgresql";
11+
};
12+
};
13+
14+
services.postgresqlBackup = {
15+
enable = true;
16+
databases = [ "strykeforce" ];
17+
pgdumpOptions = "--clean";
18+
};
19+
20+
age.secrets.pgadmin_passwd = pkgs.lib.mkIf config.services.pgadmin.enable {
21+
file = ../../secrets/pgadmin_passwd.age;
22+
owner = "pgadmin";
23+
group = "pgadmin";
24+
};
25+
26+
services.pgadmin = {
27+
enable = false;
28+
initialEmail = "[email protected]";
29+
initialPasswordFile = "${config.age.secrets.pgadmin_passwd.path}";
30+
};
31+
32+
services.nginx = {
33+
enable = true;
34+
recommendedProxySettings = true;
35+
recommendedOptimisation = true;
36+
37+
virtualHosts."pgadmin.j3ff.io" = {
38+
39+
locations = {
40+
"/" = {
41+
proxyPass = "http://127.0.0.1:5050";
42+
};
43+
44+
};
45+
};
46+
};
47+
48+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{ config, pkgs, ... }:
2+
{
3+
age.secrets.aws_credentials = {
4+
file = ../../secrets/aws_secret.age;
5+
path = "/root/.aws/credentials";
6+
};
7+
8+
systemd.services.copy-aws-config =
9+
let
10+
aws-config = (pkgs.formats.ini { }).generate "aws-config-root" {
11+
default = {
12+
region = "us-east-2";
13+
output = "json";
14+
};
15+
};
16+
in
17+
{
18+
serviceConfig = {
19+
Type = "oneshot";
20+
ExecStart = "${pkgs.coreutils}/bin/ln -sf ${aws-config} /root/.aws/config";
21+
};
22+
wantedBy = [ "multi-user.target" ];
23+
};
24+
25+
environment.systemPackages =
26+
let
27+
sync-script = pkgs.writeShellApplication {
28+
name = "strykeforce-sync";
29+
runtimeInputs = with pkgs; [
30+
awscli2
31+
gzip
32+
postgresql_15
33+
rclone
34+
];
35+
36+
text = ''
37+
if [ "$EUID" -ne 0 ]
38+
then echo "Please run as root"
39+
exit
40+
fi
41+
systemctl stop strykeforce-website.service
42+
43+
STRYKEFORCE_DIR=/var/lib/strykeforce
44+
SQL_FILE=$(mktemp -t XXXXXXXXXX.sql.gz)
45+
46+
aws s3 cp s3://www.strykeforce.org/sql/strykeforce.sql.gz "$SQL_FILE"
47+
rclone -v sync s3://www.strykeforce.org/media/ $STRYKEFORCE_DIR/media
48+
chown -R strykeforce:strykeforce $STRYKEFORCE_DIR/media
49+
50+
51+
sudo -u postgres -H -- psql -tAc 'DROP DATABASE IF EXISTS "strykeforce"'
52+
sudo -u postgres -H -- psql -tAc 'CREATE DATABASE "strykeforce"'
53+
sudo -u postgres -H -- psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='strykeforce'" | grep -q 1 || psql -tAc 'CREATE USER "strykeforce"'
54+
sudo -u postgres -H -- psql -tAc 'GRANT ALL PRIVILEGES ON DATABASE strykeforce TO "strykeforce"'
55+
56+
zcat "$SQL_FILE" | sudo -u postgres -H -- psql -d strykeforce
57+
systemctl start strykeforce-website.service
58+
systemctl start redis.service
59+
'';
60+
};
61+
in
62+
[ sync-script ];
63+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ config, pkgs, ... }:
2+
{
3+
age.secrets.stryker_website_secrets = {
4+
file = ../../secrets/strykeforce_website_secrets.age;
5+
};
6+
strykeforce.services.website = {
7+
enable = true;
8+
ssl = false;
9+
settingsModule = "website.settings.production";
10+
secrets = [ config.age.secrets.stryker_website_secrets.path ];
11+
allowedHosts = "*";
12+
};
13+
14+
services.nginx.virtualHosts."strykeforce.j3ff.io" = {
15+
locations = {
16+
"/" = {
17+
proxyPass = "http://127.0.0.1:8000";
18+
};
19+
20+
"/media/" = {
21+
alias = "/var/lib/strykeforce/media/";
22+
extraConfig = ''
23+
expires max;
24+
add_header Cache-Control public;
25+
'';
26+
};
27+
};
28+
};
29+
}

0 commit comments

Comments
 (0)