Skip to content

Commit b09cabd

Browse files
authored
Merge pull request #6 from arunavo4/l9s9sl-ray/migrate-project-to-bun-with-redis-and-sqlite
Switch package management to Bun
2 parents e95f1d9 + f9c77bb commit b09cabd

File tree

13 files changed

+75
-97
lines changed

13 files changed

+75
-97
lines changed

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
# Node.js
77
node_modules
8+
bun.lockb
89
npm-debug.log
910
yarn-debug.log
1011
yarn-error.log
11-
pnpm-debug.log
1212

1313
# Build outputs
1414
dist
@@ -62,4 +62,3 @@ logs
6262
# Cache
6363
.cache
6464
.npm
65-
.pnpm-store

.github/workflows/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ This workflow runs on all branches and pull requests. It:
2424
- On push to any branch (except changes to README.md and docs)
2525
- On pull requests to any branch (except changes to README.md and docs)
2626

27-
**Key features:**
28-
- Uses pnpm for faster dependency installation
27+
- Uses Bun for dependency installation
2928
- Caches dependencies to speed up builds
3029
- Uploads build artifacts for 7 days
3130

.github/workflows/astro-build-test.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,20 @@ jobs:
2121
- name: Checkout repository
2222
uses: actions/checkout@v4
2323

24-
- name: Install pnpm
25-
uses: pnpm/action-setup@v3
24+
- name: Setup Bun
25+
uses: oven-sh/setup-bun@v1
2626
with:
27-
version: 10
28-
run_install: false
29-
30-
- name: Setup Node.js
31-
uses: actions/setup-node@v4
32-
with:
33-
node-version: 'lts/*'
34-
cache: 'pnpm'
27+
bun-version: '1.2.9'
28+
cache: true
3529

3630
- name: Install dependencies
37-
run: pnpm install
31+
run: bun install
3832

3933
- name: Run tests
40-
run: pnpm test
34+
run: bunx vitest run
4135

4236
- name: Build Astro project
43-
run: pnpm build
37+
run: bunx astro build
4438

4539
- name: Upload build artifacts
4640
uses: actions/upload-artifact@v4

.github/workflows/docker-scan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ on:
77
- 'Dockerfile'
88
- '.dockerignore'
99
- 'package.json'
10-
- 'pnpm-lock.yaml'
10+
- 'bun.lockb'
1111
pull_request:
1212
branches: [ main ]
1313
paths:
1414
- 'Dockerfile'
1515
- '.dockerignore'
1616
- 'package.json'
17-
- 'pnpm-lock.yaml'
17+
- 'bun.lockb'
1818
schedule:
1919
- cron: '0 0 * * 0' # Run weekly on Sunday at midnight
2020

README.md

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
```bash
1919
docker compose --profile production up -d
2020
# or
21-
pnpm setup && pnpm dev
21+
bun run setup && bun run dev
2222
```
2323

2424
<p align="center">
@@ -92,7 +92,7 @@ Before running the application in production mode for the first time, you need t
9292

9393
```bash
9494
# Initialize the database for production mode
95-
pnpm setup
95+
bun run setup
9696
```
9797

9898
This will create the necessary tables. On first launch, you'll be guided through creating your admin account with a secure password.
@@ -110,7 +110,7 @@ Gitea Mirror provides multi-architecture Docker images that work on both ARM64 (
110110
docker compose --profile production up -d
111111

112112
# For development mode (requires configuration)
113-
# Ensure you have run pnpm setup first
113+
# Ensure you have run bun run setup first
114114
docker compose -f docker-compose.dev.yml up -d
115115
```
116116

@@ -206,40 +206,40 @@ git clone https://github.com/arunavo4/gitea-mirror.git
206206
cd gitea-mirror
207207

208208
# Quick setup (installs dependencies and initializes the database)
209-
pnpm setup
209+
bun run setup
210210

211211
# Development Mode Options
212212

213213
# Run in development mode
214-
pnpm dev
214+
bun run dev
215215

216216
# Run in development mode with clean database (removes existing DB first)
217-
pnpm dev:clean
217+
bun run dev:clean
218218

219219
# Production Mode Options
220220

221221
# Build the application
222-
pnpm build
222+
bun run build
223223

224224
# Preview the production build
225-
pnpm preview
225+
bun run preview
226226

227227
# Start the production server (default)
228-
pnpm start
228+
bun run start
229229

230230
# Start the production server with a clean setup
231-
pnpm start:fresh
231+
bun run start:fresh
232232

233233
# Database Management
234234

235235
# Initialize the database
236-
pnpm init-db
236+
bun run init-db
237237

238238
# Reset users for testing first-time signup
239-
pnpm reset-users
239+
bun run reset-users
240240

241241
# Check database status
242-
pnpm check-db
242+
bun run check-db
243243
```
244244

245245
### Configuration
@@ -262,10 +262,10 @@ Key configuration options include:
262262

263263
```bash
264264
# Install dependencies
265-
pnpm setup
265+
bun run setup
266266

267267
# Start the development server
268-
pnpm dev
268+
bun run dev
269269
```
270270

271271

@@ -467,33 +467,19 @@ Try the following steps:
467467
> For better Redis connection handling, you can modify the `src/lib/redis.ts` file to include retry logic and better error handling:
468468
469469
```typescript
470-
import Redis from "ioredis";
470+
import { RedisClient } from "bun";
471471
472472
// Connect to Redis using REDIS_URL environment variable or default to redis://redis:6379
473-
const redisUrl = process.env.REDIS_URL ?? 'redis://redis:6379';
473+
const redisUrl = process.env.REDIS_URL ?? "redis://redis:6379";
474474
475475
console.log(`Connecting to Redis at: ${redisUrl}`);
476476
477-
// Configure Redis client with connection options
478-
const redisOptions = {
479-
retryStrategy: (times) => {
480-
// Retry with exponential backoff up to 30 seconds
481-
const delay = Math.min(times * 100, 3000);
482-
console.log(`Redis connection attempt ${times} failed. Retrying in ${delay}ms...`);
483-
return delay;
484-
},
485-
maxRetriesPerRequest: 5,
486-
enableReadyCheck: true,
487-
connectTimeout: 10000,
488-
};
489-
490-
export const redis = new Redis(redisUrl, redisOptions);
491-
export const redisPublisher = new Redis(redisUrl, redisOptions);
492-
export const redisSubscriber = new Redis(redisUrl, redisOptions);
477+
const redis = new RedisClient(redisUrl, { autoReconnect: true });
493478
494-
// Log connection events
495-
redis.on('connect', () => console.log('Redis client connected'));
496-
redis.on('error', (err) => console.error('Redis client error:', err));
479+
redis.onconnect = () => console.log("Redis client connected");
480+
redis.onclose = err => {
481+
if (err) console.error("Redis client error:", err);
482+
};
497483
```
498484
499485

docker-entrypoint.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ set -e
55
# Ensure data directory exists
66
mkdir -p /app/data
77

8-
# If pnpm is available, run setup (for dev images), else run node init directly
9-
if command -v pnpm >/dev/null 2>&1; then
10-
echo "Running pnpm setup (if needed)..."
11-
pnpm setup || true
8+
# If bun is available, run setup (for dev images)
9+
if command -v bun >/dev/null 2>&1; then
10+
echo "Running bun setup (if needed)..."
11+
bun run setup || true
1212
fi
1313

1414
# Initialize the database if it doesn't exist
1515
if [ ! -f "/app/data/gitea-mirror.db" ]; then
1616
echo "Initializing database..."
1717
if [ -f "dist/scripts/init-db.js" ]; then
18-
node dist/scripts/init-db.js
18+
bun dist/scripts/init-db.js
1919
elif [ -f "dist/scripts/manage-db.js" ]; then
20-
node dist/scripts/manage-db.js init
20+
bun dist/scripts/manage-db.js init
2121
else
2222
echo "Warning: Could not find database initialization scripts in dist/scripts."
2323
echo "Creating and initializing database manually..."
@@ -119,9 +119,9 @@ EOF
119119
else
120120
echo "Database already exists, checking for issues..."
121121
if [ -f "dist/scripts/fix-db-issues.js" ]; then
122-
node dist/scripts/fix-db-issues.js
122+
bun dist/scripts/fix-db-issues.js
123123
elif [ -f "dist/scripts/manage-db.js" ]; then
124-
node dist/scripts/manage-db.js fix
124+
bun dist/scripts/manage-db.js fix
125125
fi
126126

127127
# Since the application is not used by anyone yet, we've removed the schema updates and migrations
@@ -130,4 +130,4 @@ fi
130130

131131
# Start the application
132132
echo "Starting Gitea Mirror..."
133-
exec node ./dist/server/entry.mjs
133+
exec bun ./dist/server/entry.mjs

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"bun": ">=1.2.9"
77
},
88
"scripts": {
9-
"setup": "pnpm install && pnpm manage-db init",
9+
"setup": "bun install && bun run manage-db init",
1010
"dev": "bunx astro dev",
11-
"dev:clean": "pnpm cleanup-db && pnpm manage-db init && bunx astro dev",
11+
"dev:clean": "bun run cleanup-db && bun run manage-db init && bunx astro dev",
1212
"build": "bunx astro build",
1313
"cleanup-db": "rm -f gitea-mirror.db data/gitea-mirror.db",
1414
"manage-db": "bun scripts/manage-db.ts",
@@ -18,7 +18,7 @@
1818
"reset-users": "bun scripts/manage-db.ts reset-users",
1919
"preview": "bunx astro preview",
2020
"start": "bun dist/server/entry.mjs",
21-
"start:fresh": "pnpm cleanup-db && pnpm manage-db init && bun dist/server/entry.mjs",
21+
"start:fresh": "bun run cleanup-db && bun run manage-db init && bun dist/server/entry.mjs",
2222
"test": "bunx vitest run",
2323
"test:watch": "bunx vitest",
2424
"astro": "bunx astro"
@@ -79,5 +79,5 @@
7979
"tsx": "^4.19.3",
8080
"vitest": "^3.1.1"
8181
},
82-
"packageManager": "pnpm@10.10.0"
82+
"packageManager": "bun@1.2.9"
8383
}

scripts/README-docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The script uses environment variables from the `.env` file in the project root:
4343
3. Using with docker-compose:
4444
```bash
4545
# Ensure dependencies are installed and database is initialized
46-
pnpm setup
46+
bun run setup
4747

4848
# First build the image
4949
./scripts/build-docker.sh --load

scripts/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@ This is a consolidated database management tool that handles all database-relate
1919
You can execute the database management tool using your package manager with various commands:
2020

2121
```bash
22-
# Checks database status (default action if no command is specified, equivalent to 'pnpm check-db')
23-
pnpm manage-db
22+
# Checks database status (default action if no command is specified, equivalent to 'bun run check-db')
23+
bun run manage-db
2424

2525
# Check database status
26-
pnpm check-db
26+
bun run check-db
2727

2828
# Initialize the database (only if it doesn't exist)
29-
pnpm init-db
29+
bun run init-db
3030

3131
# Fix database location issues
32-
pnpm fix-db
32+
bun run fix-db
3333

3434
# Automatic check, fix, and initialize if needed
35-
pnpm db-auto
35+
bun run db-auto
3636

3737
# Reset all users (for testing signup flow)
38-
pnpm reset-users
38+
bun run reset-users
3939

4040
# Update the database schema to the latest version
41-
pnpm update-schema
41+
bun run update-schema
4242

4343
# Remove database files completely
44-
pnpm cleanup-db
44+
bun run cleanup-db
4545

4646
# Complete setup (install dependencies and initialize database)
47-
pnpm setup
47+
bun run setup
4848

4949
# Start development server with a fresh database
50-
pnpm dev:clean
50+
bun run dev:clean
5151

5252
# Start production server with a fresh database
53-
pnpm start:fresh
53+
bun run start:fresh
5454
```
5555

5656
## Database File Location

scripts/docker-diagnostics.sh

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ echo -e "${BLUE} Recommendations ${NC}"
105105
echo -e "${BLUE}=====================================================${NC}"
106106

107107
echo -e "\n${YELLOW}For local development:${NC}"
108-
echo -e "1. ${GREEN}pnpm setup${NC} (initialize database and install dependencies)"
108+
echo -e "1. ${GREEN}bun run setup${NC} (initialize database and install dependencies)"
109109
echo -e "2. ${GREEN}./scripts/build-docker.sh --load${NC} (build and load into Docker)"
110110
echo -e "3. ${GREEN}docker-compose -f docker-compose.dev.yml up -d${NC} (start the development container)"
111111

112112
echo -e "\n${YELLOW}For production deployment (using Docker Compose):${NC}"
113-
echo -e "1. ${GREEN}pnpm setup${NC} (if not already done, to ensure database schema is ready)"
113+
echo -e "1. ${GREEN}bun run setup${NC} (if not already done, to ensure database schema is ready)"
114114
echo -e "2. ${GREEN}docker-compose --profile production up -d${NC} (start the production container)"
115115

116116
echo -e "\n${YELLOW}For CI/CD builds:${NC}"

0 commit comments

Comments
 (0)