Skip to content

Commit 3591926

Browse files
Merge branch 'main' into issue202exportSVG
2 parents dc3c211 + 6d20f93 commit 3591926

File tree

25 files changed

+676
-105
lines changed

25 files changed

+676
-105
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ jobs:
3636
rustup toolchain install stable
3737
rustup target add wasm32-unknown-unknown
3838
39-
- name: Build
39+
- name: Build for Prod
40+
if: github.event_name == 'release'
4041
run: |
4142
pnpm install
4243
pnpm --filter ./packages/frontend run build
4344
45+
- name: Build for Staging
46+
if: github.event_name == 'push' || github.event_name == 'pull_request'
47+
run: |
48+
pnpm install
49+
pnpm --filter ./packages/frontend run build --mode staging
50+
4451
- name: Upload
4552
uses: actions/upload-artifact@v4
4653
with:

dev-docs/trees/dev-000A.tree

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,59 @@
4444
\p{However, this will not update the version of catcolab that is running on the server. There is currently a somewhat manual process to do this, because Owen believes that it is important for people to understand the steps of the manual process so that they can debug things when they go wrong.}
4545

4646
\p{On backend-next.catcolab.org, there is a git clone of the catcolab repository in \code{/var/lib/catcolab}. There is a daemon (managed via systemd) that runs \code{node dist/index.js} in \code{/var/lib/catcolab/packages/backend}. In order to upgrade the version of catcolab that is running on the server, one should:}
47-
4847
\ol{
49-
\li{Log in via \code{ssh} into backend-next.catcolab.org (if you don't have an account with administrator access, ask Owen)}
50-
\li{Use \code{su} to become the user \code{catcolab}.}
48+
\li{Log in via \code{ssh root@backend-next.catcolab.org}. If you don't have access, ask Shaowei.}
49+
\li{Use \code{su - catcolab} to become the user \code{catcolab}.}
5150
\li{\code{cd} into \code{/var/lib/catcolab/packages/backend}.}
5251
\li{Use \code{git} to checkout the desired version of catcolab.}
5352
\li{Run \code{npm run build} to produce a new \code{dist/index.js} file.}
54-
\li{Run as user root \code{systemctl stop catcolab}; this will temporarily stop the backend.}
53+
\li{Run as user root \code{systemctl stop catcolab}; this will temporarily stop the backend. It is helpful to do this in another terminal window.}
5554
\li{Run as user catcolab in \code{/var/lib/catcolab/packages/backend} \code{npm run migrate}. This will update the database with new any migrations that have been added since the last time the database was migrated.}
5655
\li{Run as user root \code{systemctl start catcolab}; this will start back up the backend.}
5756
\li{(If there are no new migrations, the previous three commands can simply be accomplished via \code{systemctl restart catcolab})}
58-
\li{You can check the status of the catcolab daemon with \code{systemctl status catcolab}, or look at the log messages with \code{journalctl -u catcolab}.}
57+
\li{You can check the status of the catcolab daemon with \code{systemctl status catcolab}, or look at the log messages with \code{journalctl -eu catcolab}.}
58+
}
59+
60+
\p{To give a new user access to the servers:}
61+
\ol{
62+
\li{Update the public keys in \code{infrastructure/hosts/catcolab/default.nix}.}
63+
\li{Get someone with server access to run \code{nix develop; deploy .#catcolab}.}
64+
}
65+
66+
\p{To give a new user access to the secrets:}
67+
\ol{
68+
\li{Update the public keys in \code{infrastructure/secrets/secrets.nix}.}
69+
\li{Get someone with secret access to run \code{nix develop; agenix -r}.}
70+
}
71+
72+
\p{If you are creating an AWS instance and setting up a CatColab backend, e.g. \code{backend-next}, for the first time:}
73+
\ol{
74+
\li{Use the \code{nixos/24.05.3348.7e5afd404b62-x86_64-linux} community AMI.}
75+
\li{Add 50GB of storage to the instance.}
76+
\li{Open ports 80, 443 for HTTP, HTTPS in addition to port 22 for SSH.}
77+
\li{Add a public key of the machine to \code{infrastructure/secrets/secrets.nix}. You can get the public keys by running \code{ssh-keyscan <machine-ip-address>}.}
78+
\li{In the \code{namecheap} domain name hosting service, point \code{backend-next.catcolab.org} to the instance's IP address.}
79+
\li{Log in via \code{ssh root@backend-next.catcolab.org}. If you don't have access, ask Shaowei.}
80+
\li{Use \code{git} to clone the catcolab repo in \code{/var/lib}. Rename the directory with \code{mv CatColab catcolab} and change ownership with \code{chown -R catcolab:catcolab catcolab}.}
81+
\li{Use \code{su - catcolab} to become the user \code{catcolab}.}
82+
\li{\code{cd} into \code{/var/lib/catcolab/packages/backend}.}
83+
\li{Use \code{git} to checkout the desired version of catcolab.}
84+
\li{Run \code{pnpm install} to install dependencies.}
5985
}
86+
87+
\p{Setting up the Postgres database:}
88+
\ol{
89+
\li{\code{su - postgres}}
90+
\li{\code{createuser catcolab}}
91+
\li{\code{createdb catcolab}}
92+
\li{\code{psql}}
93+
\ul{
94+
\li{\code{alter user catcolab with encrypted password '<password>';}}
95+
\li{\code{grant all privileges on database catcolab to catcolab;}}
96+
\li{\code{﹨c catcolab postgres}}
97+
\li{\code{grant all on schema public to catcolab;}}
98+
\li{\code{exit}}
99+
}
100+
}
101+
60102
}

infrastructure/flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
sshUser = "root";
4040
};
4141
};
42+
catcolab-next = {
43+
hostname = "ec2-18-191-165-64.us-east-2.compute.amazonaws.com";
44+
profiles.system = mkSystemProfile "catcolab-next" // {
45+
sshUser = "root";
46+
};
47+
};
4248
};
4349

4450
devShells.${system}.default = import ./shell { inherit self pkgs inputs; };
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{ inputs, pkgs, config, ... }:
2+
3+
let
4+
port = "8000";
5+
startScript = pkgs.writeShellScript "catcolab.sh" ''
6+
rm -f instrument.mjs
7+
cp ${config.age.secrets."instrument.mjs".path} .
8+
${pkgs.nodejs}/bin/node dist/index.js
9+
'';
10+
in {
11+
age.secrets.DATABASE_URL = {
12+
file = "${inputs.self}/secrets/DATABASE_URL.age";
13+
mode = "400";
14+
owner = "catcolab";
15+
};
16+
17+
age.secrets."instrument.mjs" = {
18+
file = "${inputs.self}/secrets/instrument.mjs.age";
19+
mode = "400";
20+
owner = "catcolab";
21+
};
22+
23+
services.postgresql.enable = true;
24+
25+
services.nginx.enable = true;
26+
services.nginx.virtualHosts."backend-next.catcolab.org" = {
27+
forceSSL = true;
28+
enableACME = true;
29+
locations."/" = {
30+
extraConfig = ''
31+
if ($request_method = OPTIONS) {
32+
return 204;
33+
}
34+
proxy_hide_header 'Access-Control-Allow-Origin';
35+
add_header 'Access-Control-Allow-Origin' '*' always;
36+
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT, OPTIONS' always;
37+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
38+
proxy_pass http://localhost:${port};
39+
error_log syslog:server=unix:/dev/log;
40+
access_log syslog:server=unix:/dev/log;
41+
proxy_http_version 1.1;
42+
proxy_set_header Upgrade $http_upgrade;
43+
proxy_set_header Connection "upgrade";
44+
'';
45+
};
46+
};
47+
48+
systemd.services.catcolab = {
49+
enable = true;
50+
wantedBy = ["multi-user.target"];
51+
52+
environment = {
53+
PORT = port;
54+
DATABASE_URL_PATH = config.age.secrets.DATABASE_URL.path;
55+
NODE_OPTIONS = "--import ./instrument.mjs";
56+
};
57+
58+
serviceConfig = {
59+
User = "catcolab";
60+
ExecStart = startScript;
61+
Type="simple";
62+
WorkingDirectory = "/var/lib/catcolab/packages/backend/";
63+
Restart = "on-failure";
64+
};
65+
};
66+
67+
users.users.catcolab = {
68+
isNormalUser = true;
69+
group = "catcolab";
70+
};
71+
72+
environment.systemPackages = with pkgs; [
73+
rustup
74+
nodejs
75+
nodejs.pkgs.pnpm
76+
git
77+
stdenv.cc
78+
];
79+
80+
environment.variables.DATABASE_URL_PATH = config.age.secrets.DATABASE_URL.path;
81+
82+
users.groups.catcolab = {};
83+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{ inputs, ... }:
2+
3+
let
4+
owen = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF2sBTuqGoEXRWpBRqTBwZZPDdLGGJ0GQcuX5dfIZKb4 o@red-special";
5+
epatters = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAKXx6wMJSeYKCHNmbyR803RQ72uto9uYsHhAPPWNl2D evan@epatters.org";
6+
shaowei = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOV/7Vnjn7PwOC9VWyRAvsh5lUieIBHgdf4RRLkL8ZPa shaowei@gmail.com";
7+
in
8+
{
9+
imports = [
10+
./backend.nix
11+
"${inputs.nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
12+
];
13+
14+
networking.hostName = "catcolab-next";
15+
16+
security.sudo.wheelNeedsPassword = false;
17+
18+
users.mutableUsers = false;
19+
20+
users.users.o = {
21+
isNormalUser = true;
22+
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
23+
openssh.authorizedKeys.keys = [ owen ];
24+
};
25+
26+
users.users.epatters = {
27+
isNormalUser = true;
28+
extraGroups = [ "wheel" ];
29+
openssh.authorizedKeys.keys = [ epatters ];
30+
};
31+
32+
users.users.shaowei = {
33+
isNormalUser = true;
34+
extraGroups = [ "wheel" ];
35+
openssh.authorizedKeys.keys = [ shaowei ];
36+
};
37+
38+
users.users.root.openssh.authorizedKeys.keys = [ owen epatters shaowei ];
39+
40+
time.timeZone = "America/New_York";
41+
42+
# Enable the OpenSSH daemon.
43+
services.openssh.enable = true;
44+
45+
system.stateVersion = "24.05";
46+
47+
security.acme.acceptTerms = true;
48+
security.acme.defaults.email = "owen@topos.institute";
49+
50+
nix.extraOptions = ''
51+
experimental-features = nix-command flakes
52+
'';
53+
54+
networking.firewall.allowedTCPPorts = [ 80 443 ];
55+
}

infrastructure/hosts/catcolab/catcolab.nix renamed to infrastructure/hosts/catcolab/backend.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ in {
2121
};
2222

2323
services.postgresql.enable = true;
24-
services.nginx.enable = true;
2524

25+
services.nginx.enable = true;
2626
services.nginx.virtualHosts."backend.catcolab.org" = {
2727
forceSSL = true;
2828
enableACME = true;
@@ -31,6 +31,7 @@ in {
3131
if ($request_method = OPTIONS) {
3232
return 204;
3333
}
34+
proxy_hide_header 'Access-Control-Allow-Origin';
3435
add_header 'Access-Control-Allow-Origin' '*' always;
3536
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT, OPTIONS' always;
3637
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
@@ -71,6 +72,7 @@ in {
7172
environment.systemPackages = with pkgs; [
7273
rustup
7374
nodejs
75+
nodejs.pkgs.pnpm
7476
git
7577
stdenv.cc
7678
];

infrastructure/hosts/catcolab/default.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{ inputs, ... }:
22

33
let
4-
owen = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF2sBTuqGoEXRWpBRqTBwZZPDdLGGJ0GQcuX5dfIZKb4 o@red-special";
4+
owen = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF2sBTuqGoEXRWpBRqTBwZZPDdLGGJ0GQcuX5dfIZKb4 o@red-special";
55
epatters = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAKXx6wMJSeYKCHNmbyR803RQ72uto9uYsHhAPPWNl2D evan@epatters.org";
6-
shaowei = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOV/7Vnjn7PwOC9VWyRAvsh5lUieIBHgdf4RRLkL8ZPa shaowei@gmail.com";
6+
shaowei = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOV/7Vnjn7PwOC9VWyRAvsh5lUieIBHgdf4RRLkL8ZPa shaowei@gmail.com";
77
in
88
{
99
imports = [
10-
./catcolab.nix
10+
./backend.nix
1111
"${inputs.nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
1212
];
1313

110 Bytes
Binary file not shown.
110 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)