Skip to content

Commit 1877ad1

Browse files
Merge branch 'CHAOS-224-KHAOS-rewrite' into CHAOS-625-customisable-ratings
2 parents 5411424 + 9b5aa4c commit 1877ad1

55 files changed

Lines changed: 1741 additions & 5274 deletions

Some content is hidden

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

.github/workflows/docker.yml

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,41 @@ jobs:
1010
build-backend:
1111
name: Build (Backend)
1212
runs-on: ubuntu-latest
13-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
13+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/CHAOS-224-KHAOS-rewrite' }}
14+
services:
15+
postgres:
16+
image: postgres:16
17+
env:
18+
POSTGRES_USER: postgres
19+
POSTGRES_PASSWORD: password
20+
POSTGRES_DB: chaos
21+
ports:
22+
- 5432:5432
1423
steps:
1524
- uses: actions/checkout@v4
1625
with:
1726
submodules: true
1827
token: ${{ secrets.GH_TOKEN }}
28+
- name: Setup cargo cache
29+
uses: actions/cache@v3
30+
with:
31+
path: |
32+
~/.cargo/bin/
33+
~/.cargo/registry/index/
34+
~/.cargo/registry/cache/
35+
~/.cargo/git/db/
36+
backend/server/target/
37+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+
restore-keys: ${{ runner.os }}-cargo-
39+
- name: Setup temporary DB
40+
working-directory: backend
41+
run: |
42+
which sqlx || cargo install sqlx-cli --no-default-features --features native-tls,postgres
43+
echo "DATABASE_URL=postgres://postgres:password@localhost:5432/chaos" >> .env
44+
sqlx migrate run
45+
- name: Generate SQLx files
46+
working-directory: backend/server
47+
run: cargo sqlx prepare
1948
- name: Set up Docker Buildx
2049
id: buildx
2150
uses: docker/setup-buildx-action@master
@@ -40,33 +69,27 @@ jobs:
4069
context: backend
4170
builder: ${{ steps.buildx.outputs.name }}
4271
file: backend/Dockerfile
43-
push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
72+
push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/CHAOS-224-KHAOS-rewrite' }}
4473
tags: |
4574
ghcr.io/devsoc-unsw/chaos-backend:${{ github.sha }}
46-
ghcr.io/devsoc-unsw/chaos-backend:latest
75+
ghcr.io/devsoc-unsw/chaos-backend:staging-latest
4776
labels: ${{ steps.meta.outputs.labels }}
4877
cache-from: type=local,src=/tmp/.buildx-cache
49-
# Note the mode=max here
50-
# More: https://github.com/moby/buildkit#--export-cache-options
51-
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue
5278
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
5379
- name: Move cache
5480
run: |
5581
rm -rf /tmp/.buildx-cache
5682
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
57-
build-client:
58-
name: Build (Client)
83+
build-frontend:
84+
name: Build (Frontend)
5985
runs-on: ubuntu-latest
86+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/CHAOS-224-KHAOS-rewrite' }}
6087
permissions:
6188
contents: read
6289
packages: write
6390
steps:
6491
- name: Checkout repository
6592
uses: actions/checkout@v4
66-
- name: Set up QEMU
67-
uses: docker/setup-qemu-action@v2
68-
with:
69-
platforms: arm64
7093
- name: Set up Docker Buildx
7194
uses: docker/setup-buildx-action@v2
7295
- name: Log into registry ${{ env.REGISTRY }}
@@ -78,26 +101,23 @@ jobs:
78101
- name: Build and push Docker image
79102
uses: docker/build-push-action@v4
80103
with:
81-
context: frontend
82-
push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
104+
context: frontend-nextjs
105+
push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/CHAOS-224-KHAOS-rewrite' }}
83106
platforms: linux/amd64
84-
file: frontend/Dockerfile
85-
build-args: |
86-
VITE_API_BASE_URL=${{ secrets.API_BASE_URL }}
87-
VITE_OAUTH_CALLBACK_URL=${{ secrets.OAUTH_CALLBACK_URL }}
107+
file: frontend-nextjs/Dockerfile
88108
tags: |
89109
ghcr.io/devsoc-unsw/chaos-frontend:${{ github.sha }}
90-
ghcr.io/devsoc-unsw/chaos-frontend:latest
110+
ghcr.io/devsoc-unsw/chaos-frontend:staging-latest
91111
labels: ${{ steps.meta.outputs.labels }}
92112
deploy:
93113
name: Deploy (CD)
94114
runs-on: ubuntu-latest
95-
needs: [build-client, build-backend]
96-
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
115+
needs: [build-frontend, build-backend]
116+
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/CHAOS-224-KHAOS-rewrite' }}
97117
concurrency: staging
98118
environment:
99119
name: staging
100-
url: https://chaos.staging.csesoc.unsw.edu.au
120+
url: https://chaosstaging.devsoc.app
101121
steps:
102122
- name: Checkout repository
103123
uses: actions/checkout@v4

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
echo "ROLE_NAME_MAX_CHARS=20" >> backend/.env
5151
echo "ROLE_DESCRIPTION_MAX_CHARS=50" >> backend/.env
5252
echo "ROLE_POSITIONS_AVAILABLE_MAX=20" >> backend/.env
53+
echo "CHAOS_SUPER_USER_EMAIL=me@example.com" >> backend/.env
5354
# selecting a toolchain either by action or manual `rustup` calls should happen
5455
# before the plugin, as it uses the current rustc version as its cache key
5556
- uses: actions-rs/toolchain@v1

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
**/.idea/
44
**/.next/
55
**/target/
6-
**/.env.*
6+
**/.env.*

backend/.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Build artifacts
2+
target/
3+
**/target/
4+
server/target/
5+
6+
# Git
7+
.git/
8+
.gitignore
9+
10+
# Environment files
11+
.env
12+
.env.*
13+
14+
# Logs and temp files
15+
*.log
16+
*.tmp
17+
flycheck*/
18+
19+
# IDE files
20+
.vscode/
21+
.idea/
22+
*.swp
23+
.DS_Store
24+
25+
# Documentation
26+
*.md
27+
README*
28+
api.json
29+
api.yaml
30+
31+
# Development tools (not needed in production image)
32+
database-seeding/
33+
setup-*.sh
34+
setup-*.yml

backend/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ target
33
prisma-cli/prisma/migrations
44
/.idea
55
**/.DS_Store
6-
.env.*
6+
.env.*
7+
**/.sqlx

backend/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# build project w/ cargo chef to speed up build times(idk saw it on yt)
2+
FROM rust:latest AS chef
3+
4+
RUN apt-get update && apt-get install -y \
5+
libssl-dev \
6+
pkg-config \
7+
&& rm -rf /var/lib/apt/lists/*
8+
RUN cargo install cargo-chef
9+
WORKDIR /backend
10+
11+
FROM chef AS planner
12+
COPY server/ ./server/
13+
WORKDIR /backend/server
14+
RUN cargo chef prepare --recipe-path recipe.json
15+
16+
FROM chef AS builder
17+
WORKDIR /backend/server
18+
COPY --from=planner /backend/server/recipe.json ./recipe.json
19+
20+
RUN cargo chef cook --release --recipe-path recipe.json
21+
22+
COPY server/ ./
23+
24+
# Build the server binary
25+
WORKDIR /backend/server
26+
27+
ENV SQLX_OFFLINE=true
28+
29+
RUN cargo build --release
30+
31+
FROM debian:trixie-slim
32+
33+
RUN apt-get update && apt-get install -y \
34+
ca-certificates \
35+
libssl3 \
36+
libc6 \
37+
netcat-openbsd \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
RUN groupadd --system --gid 1001 chaos
41+
RUN useradd --system --uid 1001 --gid chaos rust
42+
43+
COPY --from=builder --chown=chaos:rust /backend/server/target/release/server /backend/server
44+
45+
USER rust
46+
47+
ENTRYPOINT ["/backend/server"]
48+
EXPOSE 8000

backend/migrations/20240406023149_create_users.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@ CREATE TABLE users (
1414
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
1515
);
1616

17-
-- Seed initial superuser
18-
INSERT INTO users (id, email, name, role)
19-
VALUES (10000, 'chaosdirectors@devsoc.app', 'Super Admin', 'SuperUser');
20-
2117
CREATE UNIQUE INDEX IDX_users_email_lower on users((lower(email)));

backend/migrations/20240406024211_create_organisations.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ CREATE TABLE organisation_members (
1919
FOREIGN KEY(organisation_id)
2020
REFERENCES organisations(id)
2121
ON DELETE CASCADE
22-
ON UPDATE CASCADE
22+
ON UPDATE CASCADE,
23+
CONSTRAINT FK_organisation_members_user
24+
FOREIGN KEY(user_id)
25+
REFERENCES users(id)
26+
ON DELETE CASCADE
27+
ON UPDATE CASCADE,
28+
UNIQUE(organisation_id, user_id)
2329
);
2430

2531

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE organisation_invites (
2+
id BIGINT PRIMARY KEY,
3+
organisation_id BIGINT NOT NULL REFERENCES organisations(id) ON DELETE CASCADE,
4+
code TEXT NOT NULL UNIQUE,
5+
email TEXT NOT NULL,
6+
expires_at TIMESTAMPTZ NOT NULL,
7+
used_at TIMESTAMPTZ,
8+
used_by BIGINT REFERENCES users(id) ON DELETE SET NULL,
9+
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
10+
invited_by_user_id BIGINT REFERENCES users(id) ON DELETE SET NULL
11+
);
12+
13+
CREATE INDEX IDX_organisation_invites_code ON organisation_invites(code);
14+
CREATE INDEX IDX_organisation_invites_organisation_id ON organisation_invites(organisation_id);
15+
CREATE INDEX IDX_organisation_invites_email ON organisation_invites(email);

backend/package-lock.json

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

0 commit comments

Comments
 (0)