diff --git a/Dockerfile b/Dockerfile index b3e7c47..71aea7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,11 @@ COPY --from=deps /app/node_modules ./node_modules COPY . . RUN pnpm build +# Compile TypeScript scripts to JavaScript +RUN mkdir -p dist/scripts && \ + for script in scripts/*.ts; do \ + node_modules/.bin/tsc --outDir dist/scripts --module commonjs --target es2020 --esModuleInterop $script || true; \ + done # ----------------------------------- FROM deps AS pruner @@ -55,14 +60,14 @@ COPY --from=builder /app/data ./data ENV NODE_ENV=production ENV HOST=0.0.0.0 ENV PORT=4321 -ENV DATABASE_URL=sqlite://data/gitea-mirror.db +ENV DATABASE_URL=file:data/gitea-mirror.db # Make entrypoint executable RUN chmod +x /app/docker-entrypoint.sh ENTRYPOINT ["/app/docker-entrypoint.sh"] -RUN apk add --no-cache wget && \ +RUN apk add --no-cache wget sqlite && \ mkdir -p /app/data && \ addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 gitea-mirror && \ diff --git a/README.md b/README.md index ab28a5a..5912817 100644 --- a/README.md +++ b/README.md @@ -71,18 +71,6 @@ This will create the necessary tables. On first launch, you'll be guided through Gitea Mirror provides multi-architecture Docker images that work on both ARM64 (e.g., Apple Silicon, Raspberry Pi) and x86_64 (Intel/AMD) platforms. -##### Using Pre-built Images from GitHub Container Registry - -```bash -# Pull the latest multi-architecture image -docker pull ghcr.io/arunavo4/gitea-mirror:latest - -# Run the application -docker run -d \\ - -p 4321:4321 \\ - ghcr.io/arunavo4/gitea-mirror:latest -``` - ##### Using Docker Compose (Recommended) ```bash @@ -94,6 +82,25 @@ docker-compose --profile production up -d docker-compose -f docker-compose.dev.yml up -d ``` +> **Important**: Docker Compose is the recommended method for running Gitea Mirror as it automatically sets up the required Redis sidecar service that the application depends on. + +##### Using Pre-built Images from GitHub Container Registry + +If you want to run the container directly without Docker Compose, you'll need to set up a Redis instance separately: + +```bash +# First, start a Redis container +docker run -d --name gitea-mirror-redis redis:alpine + +# Pull the latest multi-architecture image +docker pull ghcr.io/arunavo4/gitea-mirror:latest + +# Run the application with a link to the Redis container +docker run -d -p 4321:4321 --link gitea-mirror-redis:redis \ + -e REDIS_URL=redis://redis:6379 \ + ghcr.io/arunavo4/gitea-mirror:latest +``` + ##### Building Docker Images Manually The project includes a build script to create and manage multi-architecture Docker images: @@ -145,10 +152,11 @@ docker volume create gitea-mirror-data The Docker container can be configured with the following environment variables: -- `DATABASE_URL`: SQLite database URL (default: `sqlite://data/gitea-mirror.db`) +- `DATABASE_URL`: SQLite database URL (default: `file:data/gitea-mirror.db`) - `HOST`: Host to bind to (default: `0.0.0.0`) - `PORT`: Port to listen on (default: `4321`) - `JWT_SECRET`: Secret key for JWT token generation (important for security) +- `REDIS_URL`: URL for Redis connection (required, default: none) #### Manual Installation @@ -227,8 +235,14 @@ Gitea Mirror follows a modular architecture with clear separation of concerns. S │ │ │ │ │ │ │ │ │ │ Frontend │◄───►│ Backend │◄───►│ Database │ │ │ │ (Astro) │ │ (Node.js) │ │ (SQLite) │ │ -│ │ │ │ │ │ │ │ -│ └─────────────┘ └──────┬──────┘ └─────────────────┘ │ +│ │ │ │ │ │ │ │ │ +│ └─────────────┘ └──────┼──────┘ └─────────────────┘ │ +│ │ │ +│ ┌──────┴──────┐ │ +│ │ │ │ +│ │ Redis │ │ +│ │ │ │ +│ └──────┬──────┘ │ │ │ │ └─────────────────────────────┼───────────────────────────────────┘ │ @@ -246,6 +260,8 @@ Gitea Mirror follows a modular architecture with clear separation of concerns. S └─────────────────────────────────────────┘ ``` +> **Note**: Redis is a required component for Gitea Mirror as it's used for job queuing and caching. + ## Development ### Local Development Setup @@ -344,6 +360,7 @@ GITEA_USERNAME=your-local-gitea-username - **Frontend**: Astro, React, Shadcn UI, Tailwind CSS v4 - **Backend**: Node.js - **Database**: SQLite (default) or PostgreSQL +- **Caching/Queue**: Redis - **API Integration**: GitHub API (Octokit), Gitea API ## Contributing diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c0a52f6..df02f7f 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -14,29 +14,126 @@ fi # Initialize the database if it doesn't exist if [ ! -f "/app/data/gitea-mirror.db" ]; then echo "Initializing database..." - if [ -f "scripts/init-db.ts" ]; then - node -r tsx/cjs scripts/init-db.ts - elif [ -f "scripts/manage-db.ts" ]; then - node -r tsx/cjs scripts/manage-db.ts init + if [ -f "dist/scripts/init-db.js" ]; then + node dist/scripts/init-db.js + elif [ -f "dist/scripts/manage-db.js" ]; then + node dist/scripts/manage-db.js init + else + echo "Warning: Could not find database initialization scripts in dist/scripts." + echo "Creating and initializing database manually..." + + # Create the database file + touch /app/data/gitea-mirror.db + + # Initialize the database with required tables + sqlite3 /app/data/gitea-mirror.db <