91 lines
2.7 KiB
Markdown
91 lines
2.7 KiB
Markdown
# sbrs — sing-box rules sync
|
|
|
|
A containerized Rust utility to synchronize and self-host remote rule sets for `sing-box`.
|
|
|
|
## Core Workflow
|
|
|
|
1. **Reads** a source JSON configuration (`config/template.json`) containing remote URLs (e.g., from GitHub).
|
|
2. **Downloads** all rule files specified in the source config to a local directory (for example, `./rules`).
|
|
3. **Cleans up** stale rule files from the local directory that are no longer present in the source config.
|
|
4. **Generates** a new, client-facing configuration (`config/default.json`) where all remote URLs are rewritten to point to a self-hosted domain.
|
|
|
|
The original `template.json` is never modified by this application.
|
|
|
|
Upon container start, the utility performs an initial synchronization immediately and then sets up a cron job for subsequent, scheduled runs.
|
|
|
|
## Prerequisites
|
|
|
|
- Docker
|
|
- Docker Compose
|
|
|
|
## Usage via Docker
|
|
|
|
**1. Example of possible directory structure**
|
|
|
|
Create the following directory structure in your project root before the first run:
|
|
|
|
```
|
|
.
|
|
├── config/
|
|
│ └── template.json # Your input config with original URLs
|
|
├── rules/ # Empty directory for downloaded rule files
|
|
├── docker/
|
|
│ ├── Dockerfile
|
|
│ └── entrypoint.sh
|
|
└── docker-compose.yml
|
|
```
|
|
*Note: `config/default.json` will be generated by the application on the first run.*
|
|
|
|
**2. Configuration**
|
|
|
|
Edit `docker-compose.yml` to set the required environment variables:
|
|
|
|
- `PUID`/`PGID`: Set to your host user's ID (`id -u`) and group ID (`id -g`) to prevent volume permission issues.
|
|
- `DOMAIN`: The public domain that will serve the rule files (e.g., `rules.mydomain.com`).
|
|
- `RULE_PATH`: The path on the domain where the files are located (e.g., `/` or `/files`).
|
|
- `TZ`: The timezone for container logs (e.g., `Etc/UTC`).
|
|
- `CRON_SCHEDULE`: The schedule for the sync task.
|
|
|
|
**3. Run the Service**
|
|
|
|
```bash
|
|
# Build the image and start the service in detached mode
|
|
docker-compose up --build -d
|
|
```
|
|
|
|
The service will run the sync task immediately upon starting and then again on the schedule defined by `CRON_SCHEDULE`.
|
|
|
|
### Common Commands
|
|
|
|
```bash
|
|
# View live logs
|
|
docker-compose logs -f
|
|
|
|
# Trigger a manual sync immediately (without restarting)
|
|
docker-compose exec sbrs entrypoint.sh manual
|
|
|
|
# Stop and remove the container
|
|
docker-compose down
|
|
```
|
|
|
|
## Local Development
|
|
|
|
Requires the [Rust toolchain](https://rustup.rs/).
|
|
|
|
**1. Build**
|
|
```bash
|
|
cargo build --release
|
|
```
|
|
|
|
**2. Run**
|
|
|
|
All arguments are required.
|
|
|
|
```bash
|
|
./target/release/sbrs \
|
|
--input-config ./config/template.json \
|
|
--rules-dir ./rules \
|
|
--output-config ./config/default.json \
|
|
--domain my.server.com \
|
|
--rule-path rules
|
|
``` |