Skip to content

Commit cc962cd

Browse files
authored
Merge pull request #33 from codam-coding-college/rework
New intra synchronisation design. Synchronises with API filters. Updated website interface. Added login screen. Now uses SQLite (with prisma) instead of JSON databases.
2 parents dcd7939 + d1995c1 commit cc962cd

32 files changed

+6346
-9062
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
/node_modules/
55
/token*.json
66
/env/.env
7-
/database*/
7+
database/*.db
88
/test.ts
99
/sessions/
1010
*.swp
11+
/prisma/*.db

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"semi": false,
2+
"semi": true,
33
"singleQuote": true,
44
"bracketSameLine": true,
55
"printWidth": 180,

Dockerfile

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
FROM node:18-alpine
22

3-
WORKDIR /app
3+
# Install build dependencies and fix distutils in one layer
4+
RUN apk add --no-cache python3 make g++ py3-setuptools py3-pip && \
5+
ln -sf /usr/lib/python3.12/site-packages/setuptools/_distutils /usr/lib/python3.12/distutils || echo "distutils workaround attempted"
46

5-
HEALTHCHECK --interval=5s --timeout=10s --start-period=5s --retries=1 CMD wget -q -O - http://localhost:8080/robots.txt
6-
EXPOSE 8080
7+
WORKDIR /app
8+
RUN mkdir -p /app/database
79

8-
ENV NODE_ENV=production
10+
# Copy package files first for better caching
911
COPY package.json package-lock.json ./
10-
RUN npm ci --omit=dev
12+
13+
# Install all dependencies and build in fewer layers
14+
RUN npm ci --ignore-scripts && \
15+
npm install --save-dev @types/oauth @types/passport-oauth2 @types/connect-sqlite3 && \
16+
npm rebuild
17+
18+
# Copy source files
1119
COPY . .
12-
RUN npm run build
1320

14-
RUN rm -rf src
15-
COPY views ./build/views
21+
# Build application and clean up in one layer
22+
RUN npx prisma generate && \
23+
npx prisma migrate deploy && \
24+
npx prisma db push && \
25+
npm run build && \
26+
npm prune --omit=dev && \
27+
rm -rf src
28+
29+
# Move views to built location
30+
RUN mv views build/
31+
32+
# Runtime configuration
33+
ENV NODE_ENV=production
34+
EXPOSE 8080
35+
HEALTHCHECK --interval=5s --timeout=10s --start-period=5s --retries=1 CMD wget -q -O - http://localhost:8080/robots.txt
1636

1737
ENTRYPOINT [ "npm", "start" ]

README.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ This website is meant to help students to find peers that are working on the sam
99

1010
Also see `./src/env.ts` for more configuration
1111

12-
## Changing listed projects
13-
- The projects shown on the front page are listed in `./env/projectIDs.json`. Should the curriculum change, you can edit that file. Remember to restart the server and wait for the server to pull all the data from the intra api.
14-
- A list of all the projects and their corresponding ID in the 42 network (as of march 2022) can be found in `./env/allProjectIDs.json`
15-
1612
## Updating the secrets / API tokens
1713
```shell
1814
cd find-peers
@@ -25,26 +21,13 @@ docker compose up -d
2521
docker logs --tail 10000 -f find-peers
2622
```
2723

28-
## Monitoring
29-
At the (unauthenticated) route `/status/pull` you can see a summary of the pull status of every campus
30-
It contains the key `hoursAgo` for every campus, which is the amount of hours since the last successful pull (syncing the 42 DB of the users' completed projects) of that campus
31-
This value should not be higher than 2 * the pull timeout (currently 24 hours)
32-
3324
## Configuration files
3425
| File path | Description | Managed by server |
3526
|----------------------------------------------|---------------------------------------------------------------------------------------|-------------------|
36-
| `./env/projectIDs.json` | List of all the projects and their corresponding ID to be displayed on the front page | no |
37-
| `./env/allProjectIDs.json` | List of all projects in the 42 network (as of march 2022) | no |
3827
| `./env/.env-example` | Example file for api tokens, rename to `.env` to activate | no |
39-
| `./env/campusIDs.json` | List of all campuses and their corresponding ID that are fetched from the 42 API | no |
40-
| `./database/` | All database files, mount this when running in a docker container | yes |
41-
| `./database/sessions/` | All session files currently active | yes |
42-
| `./database/users.json` | Userdata associated with session | yes |
43-
| `./database/<campus_name>/lastpull.txt` | Unix timestamp when the project users of that campus were last successfully updated | yes |
44-
| `./database/<campus_name>/projectUsers.json` | Status of users for each project | yes |
4528

4629
## Running
47-
The 'database' of this project is a folder called 'database' at the root of the project.
30+
The database of this project is in a folder called 'database' at the root of the project.
4831

4932
### Docker and Docker-compose
5033
This is in production
@@ -61,5 +44,9 @@ docker logs --tail 10000 -f find-peers
6144
- Install Nodejs >= 18.x
6245
- Install dependencies\
6346
`npm install`
47+
- Generate prisma client
48+
`npx prisma generate`
49+
- Push schema directly
50+
`npx prisma db`
6451
- Start development server\
6552
`npm run dev`

docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ services:
2525
environment:
2626
- PORT=8080
2727
ports:
28-
- 80:8080
29-
# - 8080:8080
28+
- 8080:8080
29+
# - 80:8080
3030

3131
watchtower:
3232
container_name: watchtower

env/.env-example

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,3 @@ USERAUTH_CALLBACK_URL=https://example.com/auth/42/callback
2121

2222
SYNC_UID=
2323
SYNC_SECRET=
24-
25-
# Rate limiter, you can find this number on in the line "Your application has a secondly rate limit set at " on the application page
26-
SYNC_MAX_REQUESTS_PER_SECOND=
27-
28-
# DataDog API key, used for logging metrics
29-
DD_API_KEY=

0 commit comments

Comments
 (0)