Skip to content

Commit 3e75bd2

Browse files
authored
feat: selfhostable support (#41)
1 parent 65129e7 commit 3e75bd2

File tree

8 files changed

+481
-2
lines changed

8 files changed

+481
-2
lines changed

.dockerignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Dependencies
2+
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Next.js build output
8+
.next
9+
out
10+
build
11+
12+
# Testing
13+
coverage
14+
.nyc_output
15+
16+
# Environment variables
17+
.env
18+
.env*.local
19+
20+
# IDEs and editors
21+
.vscode
22+
.idea
23+
*.swp
24+
*.swo
25+
*~
26+
27+
# OS files
28+
.DS_Store
29+
Thumbs.db
30+
31+
# Git
32+
.git
33+
.gitignore
34+
.gitattributes
35+
36+
# Documentation
37+
*.md
38+
!README.md
39+
40+
# Database
41+
*.db
42+
*.sqlite
43+
44+
# User assets (will be created at runtime)
45+
public/userassets/banners/*
46+
public/userassets/avatars/*
47+
48+
# Misc
49+
*.pem
50+
.vercel
51+
.github

.env.production.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Production Environment Configuration
2+
# Copy this file to .env and update with your values
3+
4+
# Database Configuration
5+
# For Docker deployment, use the path below
6+
DATABASE_URL="file:/app/data/database.db"
7+
8+
# Authentication
9+
# IMPORTANT: Generate a secure random key for production!
10+
# You can generate one with: openssl rand -base64 32
11+
JWT_SECRET="CHANGE-THIS-TO-A-SECURE-RANDOM-STRING"
12+
13+
# Analytics (Optional)
14+
# Leave empty to disable PostHog analytics
15+
NEXT_PUBLIC_POSTHOG_KEY=""
16+
NEXT_PUBLIC_POSTHOG_HOST=""
17+
18+
# Node Environment
19+
NODE_ENV="production"

.github/workflows/docker-build.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches: [ main ]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to Docker Hub (optional)
27+
if: github.event_name != 'pull_request'
28+
uses: docker/login-action@v3
29+
with:
30+
username: ${{ secrets.DOCKER_USERNAME }}
31+
password: ${{ secrets.DOCKER_PASSWORD }}
32+
continue-on-error: true
33+
34+
- name: Extract metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: |
39+
sysregister/app
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=raw,value=latest,enable={{is_default_branch}}
46+
47+
- name: Build Docker image
48+
uses: docker/build-push-action@v5
49+
with:
50+
context: .
51+
push: false
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Multi-stage build for optimal image size
2+
FROM node:20-alpine AS base
3+
4+
# Install dependencies only when needed
5+
FROM base AS deps
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
# Install dependencies based on the preferred package manager
10+
COPY package.json package-lock.json* ./
11+
RUN npm ci
12+
13+
# Rebuild the source code only when needed
14+
FROM base AS builder
15+
WORKDIR /app
16+
COPY --from=deps /app/node_modules ./node_modules
17+
COPY . .
18+
19+
# Generate Prisma Client
20+
RUN npx prisma generate
21+
22+
# Build the application
23+
RUN npm run build
24+
25+
# Production image, copy all the files and run next
26+
FROM base AS runner
27+
WORKDIR /app
28+
29+
ENV NODE_ENV=production
30+
31+
RUN addgroup --system --gid 1001 nodejs
32+
RUN adduser --system --uid 1001 nextjs
33+
34+
# Copy necessary files
35+
COPY --from=builder /app/public ./public
36+
COPY --from=builder /app/.next/standalone ./
37+
COPY --from=builder /app/.next/static ./.next/static
38+
COPY --from=builder /app/prisma ./prisma
39+
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
40+
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
41+
42+
# Create directories for user assets
43+
RUN mkdir -p /app/public/userassets/banners /app/public/userassets/avatars
44+
RUN chown -R nextjs:nodejs /app/public/userassets
45+
46+
USER nextjs
47+
48+
EXPOSE 3000
49+
50+
ENV PORT=3000
51+
ENV HOSTNAME="0.0.0.0"
52+
53+
CMD ["node", "server.js"]

README.md

Lines changed: 201 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,209 @@
22

33
⭐ Star us on GitHub — your support keeps us motivated!
44

5-
SysRegister offered an improved web UI for the ClasseViva school register and adds a few quality-of-life features.
5+
SysRegister offers an improved web UI for the ClasseViva school register and adds a few quality-of-life features.
66

77
---
88

99
### SysRegister has been forced to shut down.
10-
#### Recently, ClasseViva has decided to ban our servers, as a result, SysRegister can no longer access the necessary data to function, for this reason I've decided to not continue with the project.
10+
#### Recently, ClasseViva has decided to ban our servers, as a result, SysRegister can no longer access the necessary data to function. However, you can now **self-host your own instance** to continue using SysRegister!
11+
12+
---
13+
14+
## 🚀 Self-Hosting Guide
15+
16+
Self-hosting allows you to run your own instance of SysRegister, avoiding centralized server bans. You can deploy it using Docker for the easiest setup.
17+
18+
### Prerequisites
19+
20+
- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed
21+
- Basic knowledge of terminal/command line
22+
23+
### Quick Start with Docker Compose
24+
25+
#### Option 1: Automated Setup (Recommended)
26+
27+
Run the quick start script:
28+
```bash
29+
git clone https://github.com/gablilli/sysregister-reborn.git
30+
cd sysregister-reborn
31+
./start.sh
32+
```
33+
34+
This script will:
35+
- Create the `.env` file with a random JWT secret
36+
- Create necessary data directories
37+
- Build and start the Docker containers
38+
- Display helpful information
39+
40+
#### Option 2: Manual Setup
41+
42+
1. **Clone the repository**
43+
```bash
44+
git clone https://github.com/gablilli/sysregister-reborn.git
45+
cd sysregister-reborn
46+
```
47+
48+
2. **Create environment file**
49+
```bash
50+
cp .env.example .env
51+
```
52+
53+
3. **Edit the `.env` file** with your configuration:
54+
```env
55+
# Database (SQLite - default configuration)
56+
DATABASE_URL="file:/app/data/database.db"
57+
58+
# Authentication - IMPORTANT: Generate a secure random key!
59+
JWT_SECRET="your-super-secret-jwt-key-change-this"
60+
61+
# PostHog Analytics (Optional - leave empty to disable)
62+
NEXT_PUBLIC_POSTHOG_KEY=""
63+
NEXT_PUBLIC_POSTHOG_HOST=""
64+
```
65+
66+
4. **Start the application**
67+
```bash
68+
docker-compose up -d
69+
```
70+
71+
5. **Access SysRegister**
72+
73+
Open your browser and navigate to `http://localhost:3000`
74+
75+
### Configuration Options
76+
77+
#### Environment Variables
78+
79+
| Variable | Description | Required | Default |
80+
|----------|-------------|----------|---------|
81+
| `DATABASE_URL` | Database connection string | Yes | `file:/app/data/database.db` |
82+
| `JWT_SECRET` | Secret key for JWT authentication | Yes | - |
83+
| `NEXT_PUBLIC_POSTHOG_KEY` | PostHog analytics key | No | - |
84+
| `NEXT_PUBLIC_POSTHOG_HOST` | PostHog analytics host | No | - |
85+
86+
#### Ports
87+
88+
The application runs on port `3000` by default. You can change this in `docker-compose.yml`:
89+
90+
```yaml
91+
ports:
92+
- "8080:3000" # Access on port 8080 instead
93+
```
94+
95+
### Data Persistence
96+
97+
The following directories are persisted using Docker volumes:
98+
99+
- `./data` - SQLite database
100+
- `./userassets` - User uploaded content (avatars, banners)
101+
102+
These directories will be created automatically on first run.
103+
104+
### Managing the Application
105+
106+
**View logs:**
107+
```bash
108+
docker-compose logs -f
109+
```
110+
111+
**Stop the application:**
112+
```bash
113+
docker-compose down
114+
```
115+
116+
**Restart the application:**
117+
```bash
118+
docker-compose restart
119+
```
120+
121+
**Update to latest version:**
122+
```bash
123+
git pull
124+
docker-compose down
125+
docker-compose build --no-cache
126+
docker-compose up -d
127+
```
128+
129+
### Manual Docker Build (Advanced)
130+
131+
If you prefer to build and run manually:
132+
133+
```bash
134+
# Build the image
135+
docker build -t sysregister .
136+
137+
# Run the container
138+
docker run -d \
139+
-p 3000:3000 \
140+
-e DATABASE_URL="file:/app/data/database.db" \
141+
-e JWT_SECRET="your-secret-key" \
142+
-v $(pwd)/data:/app/data \
143+
-v $(pwd)/userassets:/app/public/userassets \
144+
--name sysregister \
145+
sysregister
146+
```
147+
148+
### Local Development (Without Docker)
149+
150+
1. **Install dependencies**
151+
```bash
152+
npm install
153+
```
154+
155+
2. **Set up environment**
156+
```bash
157+
cp .env.example .env
158+
# Edit .env with your configuration
159+
```
160+
161+
3. **Generate Prisma client**
162+
```bash
163+
npx prisma generate
164+
```
165+
166+
4. **Run database migrations**
167+
```bash
168+
npx prisma migrate deploy
169+
```
170+
171+
5. **Start development server**
172+
```bash
173+
npm run dev
174+
```
175+
176+
6. **Build for production**
177+
```bash
178+
npm run build
179+
npm start
180+
```
181+
182+
### Troubleshooting
183+
184+
**Issue: Database locked errors**
185+
- Ensure only one instance is running
186+
- Check that the `./data` directory has proper permissions
187+
188+
**Issue: Cannot connect to ClasseViva**
189+
- This is expected if you're running behind a banned IP
190+
- Consider using a VPN or proxy
191+
192+
**Issue: User assets not persisting**
193+
- Verify the `./userassets` volume is properly mounted
194+
- Check directory permissions
195+
196+
### Security Recommendations
197+
198+
- **Always change the default `JWT_SECRET`** to a strong, random value
199+
- Use HTTPS in production (consider using a reverse proxy like Nginx or Caddy)
200+
- Keep your instance updated with the latest security patches
201+
- Regularly backup the `./data` directory
202+
203+
### Contributing
204+
205+
Contributions are welcome! Please feel free to submit a Pull Request.
206+
207+
### License
208+
209+
See LICENSE file for details.
11210

0 commit comments

Comments
 (0)