Skip to content

Commit fa6a62e

Browse files
Merge pull request #98 from metakgp/backend-rs
[HOLY WAR] Rustified Backend
2 parents 4e290c1 + 729a3e6 commit fa6a62e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1650
-881
lines changed

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ IQPS was originally created by [Shubham Mishra](https://github.com/grapheo12) in
6060
- Make the env file by copying the template: `cp .env.template .env`
6161
- Fill the env variable and set `DB_HOST=localhost` for running locally for development
6262
- Start the DB by running `docker compose -f docker-compose.dev.yaml up -d`
63-
- Start the Go backend by running `go run .`
63+
- Start the Rust backend by running `cargo run .`
6464
3. Set up the frontend by running `pnpm install` and then `pnpm start` in the `frontend/` directory.
6565
4. Profit.
6666

@@ -77,20 +77,38 @@ IQPS was originally created by [Shubham Mishra](https://github.com/grapheo12) in
7777
5. Optionally set up a Systemd service to start the wiki on startup or use this [deployment github workflow](./.github/workflows/deploy.yaml).
7878

7979
### Environment Variables
80-
Environment variables can be set using a `.env` file. Use the `.env.template` files for reference.
80+
Environment variables can be set using a `.env` file. Use the `.env.template` files for reference. See `backend/src/env.rs` for more documentation and types.
8181

8282
#### Backend
83-
- `DB_PATH`: Path to the database file to use.
84-
- `STATIC_FILES_URL`: The base URL for the static files (PDFs).
85-
- `QPS_PATH`: The local path on the server to store question paper PDFs.
86-
- `DB_NAME`: The name for your database.
87-
- `DB_HOST`: `localhost` if using local postgres server or set your **own** database host address.
88-
- `DB_PORT`: `5432` if using local postgres server, or set to your **own** database port.
89-
- `DB_USER`: The access username for database.
90-
- `DB_PASSWORD`: The access password corressponding to the user.
83+
##### Database (Postgres)
84+
- `DB_NAME`: Database name
85+
- `DB_HOST`: Database hostname (eg: `localhost`)
86+
- `DB_PORT`: Database port
87+
- `DB_USER`: Database username
88+
- `DB_PASSWORD`: Database password
89+
90+
##### Authentication
91+
- `GH_CLIENT_ID`: Client ID of the Github OAuth app.
92+
- `GH_CLIENT_SECRET`: Client secret of the Github OAuth app.
93+
- `GH_ORG_NAME`: The name of the Github organization of the admins.
94+
- `GH_ORG_TEAM_SLUG`: The URL slug of the Github org team of the admins.
95+
- `JWT_SECRET`: A secret key/password for JWT signing. It should be a long, random, unguessable string.
96+
97+
##### Configuration
98+
- `MAX_UPLOAD_LIMIT`: Maximum number of files that can be uploaded at once.
99+
- `LOG_LOCATION`: The path to a local logfile.
100+
- `STATIC_FILES_URL`: The URL of the static files server. (eg: `https://static.metakgp.org`)
101+
- `STATIC_FILE_STORAGE_LOCATION`: The path to the local directory from which the static files are served.
102+
- `UPLOADED_QPS_PATH`: A path relative to `STATIC_FILE_STORAGE_LOCATION` where the uploaded question papers will be stored. (eg: `iqps/uploaded`)
103+
- `LIBRARY_QPS_PATH`: A path relative to `STATIC_FILE_STORAGE_LOCATION` where the library question papers are scraped and stored. (eg: `peqp/qp`)
104+
- `SERVER_PORT`: The port on which the server listens.
105+
- `CORS_ALLOWED_ORIGINS`: A comma (,) separated list of origins to be allowed in CORS.
91106

92107
#### Frontend
93-
- `VITE_BACKEND_URL`: The IQPS backend URL. Use `http://localhost:5000` in development.
108+
- `VITE_BACKEND_URL`: The IQPS backend URL. Use `http://localhost:8080` in development.
109+
- `VITE_MAX_UPLOAD_LIMIT` The maximum number of files that can be uploaded at once. (Note: This is only a client-side limit)
110+
- `VITE_GH_OAUTH_CLIENT_ID` The Client ID of the Github OAuth app.
111+
94112

95113
## Contact
96114

backend-go-old/.env.template

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
STATIC_FILES_URL=https://static.metakgp.org
2+
DB_NAME=
3+
DB_HOST=
4+
DB_PORT=
5+
DB_USER=
6+
DB_PASSWORD=
7+
STATIC_FILES_STORAGE_LOCATION=/srv/static
8+
UPLOADED_QPS_PATH=iqps/uploaded # Relative to `STATIC_FILES_STORAGE_LOCATION`. Final upload location will be /srv/static/iqps/uploaded
9+
MAX_UPLOAD_LIMIT=10
10+
GH_CLIENT_ID= # public token of the oauth app
11+
GH_PRIVATE_ID= # Private token of the oauth app
12+
JWT_SECRET= # JWT encryption secret
13+
GH_ORG_NAME= # name of the org
14+
GH_ORG_TEAM_SLUG= #URL friendly team Name
15+
GH_ORG_ADMIN_TOKEN= #GH TOKEN OF AN ORG ADMIN
16+
IQPS_LOG_LOCATION=./log/application.log

backend-go-old/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM golang:1.22.4 AS builder
2+
3+
WORKDIR /src
4+
5+
COPY go.mod go.sum ./
6+
7+
RUN go mod download
8+
9+
COPY . .
10+
11+
RUN CGO_ENABLED=1 GOOS=linux go build -o ./build --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' .
12+
13+
FROM alpine:latest AS app
14+
15+
RUN apk --no-cache add tzdata ca-certificates bash
16+
17+
ENV TZ="Asia/Kolkata"
18+
19+
WORKDIR /app
20+
21+
COPY metaploy/ ./
22+
23+
RUN chmod +x ./postinstall.sh
24+
25+
COPY --from=builder /src/build .
26+
27+
CMD ["./postinstall.sh", "./build"]
File renamed without changes.

backend-rs/docker-compose.dev.yaml renamed to backend-go-old/docker-compose.dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- PGPORT=${DB_PORT}
1010
- PGHOST=${DB_HOST}
1111
healthcheck:
12-
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}", "${POSTGRES_DB}"]
12+
test: ["CMD", "pg_isready", "-U", "postgres"]
1313
interval: 5s
1414
timeout: 3s
1515
retries: 20

backend-go-old/docker-compose.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
iqps-backend:
3+
image: metakgporg/iqps-backend
4+
container_name: iqps-backend
5+
build: .
6+
restart: always
7+
env_file:
8+
- .env
9+
networks:
10+
metaploy-network:
11+
aliases:
12+
- iqps-backend
13+
metaploy-private-network:
14+
volumes:
15+
- ./logs:/var/log/iqps/logs
16+
- ./db:/db
17+
- nginx-config-volume:/etc/nginx/sites-enabled
18+
- odins-vault:/srv/static
19+
20+
networks:
21+
metaploy-network:
22+
external: true
23+
name: metaploy-network
24+
metaploy-private-network:
25+
external: true
26+
name: metaploy-private-network
27+
28+
volumes:
29+
nginx-config-volume:
30+
external: true
31+
name: metaploy-nginx-config-volume
32+
odins-vault:
33+
external: true
34+
name: odins-vault
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)