Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 263e98b

Browse files
Merge pull request #139 from The-CS-Nerds/dev
Add dev to testing
2 parents 25e447a + 0ead47b commit 263e98b

29 files changed

Lines changed: 415 additions & 1101 deletions

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.py linguist-language=Python
2+
*.sh linguist-language=Shell
3+
*.sql linguist-language=SQL
4+
*.Dockerfile linguist-language=Dockerfile
5+
*.yaml linguist-language=YAML
6+
*.md linguist-language=Markdown

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
** @the-cs-nerds/library-devs

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ logs/**
33
config/*.yaml
44
!config/example*
55
secrets/
6-
*/__pycache__/**
6+
*/__pycache__/**
7+
Python-3.13.5/**
8+
Python-3.13.5.tgz
9+
Python3.13-Portable-Image/**

Python3.13-Portable-Image

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 56bc8b072030ad24e0d8d1d506cb9e72187fd3fe

compose.yaml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
# Docker Compose configuration
18-
1918
services:
2019
frontend:
21-
entrypoint: ["docker-entrypoint.sh"] # Frontend webapp
20+
2221
container_name: frontend
2322
#image: library-system/frontend
2423
build:
@@ -28,14 +27,14 @@ services:
2827
- "443:443" # HTTPS traffic for serving webapp
2928
networks:
3029
- backend
31-
- casdoor
30+
- logto
3231
restart: unless-stopped
3332
depends_on:
3433
backend:
3534
condition: service_started
3635
command: ["python","/src/__main__.py"]
3736
backend: # Backend
38-
entrypoint: ["docker-entrypoint.sh"]
37+
3938
container_name: backend
4039
#image: library-system/backend
4140
build:
@@ -44,53 +43,63 @@ services:
4443
networks:
4544
- backend
4645
- db
47-
- casdoor
4846
restart: unless-stopped
4947
environment:
5048
DB_HOST: db
5149
DB_PORT: 5432
5250
command: ["python","/src/__main__.py"]
53-
secrets:
54-
- db_pass
5551
depends_on:
5652
db:
5753
condition: service_healthy
54+
ports:
55+
- "8000:8000"
5856
db: # Database
57+
# entrypoint: ['docker-entrypoint.sh']
5958
image: postgres:17.5-alpine3.21 # Using alpine Postgres image
59+
container_name: db
6060
networks:
6161
- db
6262
restart: unless-stopped
6363
volumes:
6464
- pgdata:/var/lib/postgresql/data
6565
- db-init:/docker-entrypoint-initdb.d:ro # Init scripts for postgres
6666
environment:
67-
POSTGRES_USER: library
68-
POSTGRES_PASSWORD_FILE: /run/secrets/db_pass
67+
POSTGRES_USER: library
68+
POSTGRES_PASSWORD: ${DB_PASS}
6969
POSTGRES_DB: library
7070

71-
secrets:
72-
- db_pass
73-
- casbin_login_pass
74-
7571
healthcheck:
7672
test: ["CMD", "pg_isready", "-U", "library"]
7773
interval: 10s
7874
retries: 5
79-
casdoor:
80-
image: casbin/casdoor:v1.960.0
75+
76+
logto:
77+
depends_on:
78+
db:
79+
condition: service_healthy
80+
image: svhd/logto:${TAG-latest}
81+
entrypoint: ["sh", "-c", "npm run cli db seed -- --swe && npm start"]
82+
ports:
83+
- 3001:3001
84+
- 3002:3002
85+
environment:
86+
- TRUST_PROXY_HEADER=1
87+
- DB_URL=postgres://library:$DB_PASS@db:5432/library
88+
- NODE_ENV=test
89+
- PORT=3001
90+
- ADMIN_PORT=3002
91+
- ADMIN_ENDPOINT=http://localhost:3002
8192
networks:
82-
- casdoor
93+
- db
94+
- logto
8395
restart: unless-stopped
84-
depends_on:
85-
backend:
86-
condition: service_started
8796

88-
networks:
89-
backend:
97+
networks: # Frontend and DB MUST NEVER be on the same network.
98+
backend: # For all containers that must communicate with backend. MUST include backend.
9099
driver: bridge
91-
db:
100+
db: # For all containers that must communicate with the database. MUST include db. CANNOT include frontend.
92101
driver: bridge
93-
casdoor:
102+
logto:
94103
driver: bridge
95104

96105
volumes:
@@ -99,6 +108,6 @@ volumes:
99108

100109
secrets:
101110
casbin_login_pass:
102-
file: ./secrets/casbin_login_pass.txt
111+
environment: CASBIN_LOGIN_PASS
103112
db_pass:
104-
file: ./secrets/db_pass.txt
113+
environment: DB_PASS

conf/app.conf

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

db-init/0_roles.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
-- Create casbin role
2020
CREATE ROLE casbin NOLOGIN;
21-
CREATE ROLE casbin_login LOGIN PASSWORD 'SUBSTITUTE_PASSWORD';
21+
CREATE ROLE casbin_login LOGIN PASSWORD :casbin_login_pass;
2222
GRANT casbin TO casbin_login;
2323

2424
-- Create server admin, write and read roles
2525
CREATE ROLE server_admin LOGIN PASSWORD 'SUBSTITUTE_PASSWORD';
2626
CREATE ROLE server_write LOGIN PASSWORD 'SUBSTITUTE_PASSWORD';
27-
CREATE ROLE server_read LOGIN PASSWORD 'SUBSTITUTE_PASSWORD';
27+
CREATE ROLE server_read LOGIN PASSWORD 'SUBSTITUTE_PASSWORD';
28+
29+
CREATE ROLE zitadel LOGIN PASSWORD 'zitadel';

db-init/1_tables.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# along with this program. If not, see <https://www.gnu.org/licenses/>. */
1717

1818
CREATE TABLE IF NOT EXISTS books ( -- Needs to be updated in future
19-
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
19+
id UUID PRIMARY KEY,
2020
isbn TEXT UNIQUE NOT NULL,
2121
title TEXT NOT NULL,
2222
author TEXT NOT NULL,
@@ -25,11 +25,19 @@ CREATE TABLE IF NOT EXISTS books ( -- Needs to be updated in future
2525
);
2626

2727
CREATE TABLE IF NOT EXISTS loans ( -- Needs to be updated in future
28-
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
28+
id UUID PRIMARY KEY,
2929
isbn TEXT NOT NULL REFERENCES books(isbn) ON UPDATE CASCADE,
3030
student_id CHAR(4) NOT NULL REFERENCES users(student_id) ON UPDATE CASCADE,
3131
borrowed_at TIMESTAMPTZ DEFAULT now(),
3232
due_at DATE NOT NULL,
3333
returned_at TIMESTAMPTZ
3434
);
3535

36+
CREATE TABLE IF NOT EXISTS users (
37+
id UUID PRIMARY KEY,
38+
forename TEXT NOT NULL,
39+
surname TEXT NOT NULL,
40+
student_id INTEGER NOT NULL
41+
email TEXT NOT NULL UNIQUE,
42+
role TEXT NOT NULL,
43+
);

dbKeyGen.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@
1616

1717
from secrets import token_urlsafe
1818
import os
19+
from argparse import ArgumentParser
1920

20-
os.makedirs("secrets", exist_ok=True)
21+
parser = ArgumentParser()
22+
parser.add_argument("--keys",action='extend',nargs='+')
23+
parser.add_argument("--print",action='store_true')
24+
if parser.parse_args().print:
25+
os.makedirs("secrets", exist_ok=True)
26+
if 'db' in parser.parse_args().keys:
27+
if parser.parse_args().print:
28+
print(token_urlsafe(512))
29+
else:
30+
with open("secrets/db_pass.txt", "w") as f:
31+
f.write(token_urlsafe(512))
32+
os.remove("secrets/db_pass.txt")
2133

22-
with open("secrets/db_pass.txt", "w") as f:
23-
f.write(token_urlsafe(512))
24-
25-
with open("secrets/casbin_login_pass.txt", "w") as f:
26-
f.write(token_urlsafe(512))
34+
if 'auth' in parser.parse_args().keys:
35+
if parser.parse_args().print:
36+
print(token_urlsafe(512))
37+
else:
38+
with open("secrets/casbin_login_pass.txt", "w") as f:
39+
f.write(token_urlsafe(512))
40+
os.remove("secrets/casbin_login_pass.txt")

docker-entrypoint.sh

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

0 commit comments

Comments
 (0)