feat: add docker-compose and server init support migrate

This commit is contained in:
fan-tastic-z
2025-08-28 11:16:13 +08:00
parent bd4dc285ba
commit ca55dae11d
4 changed files with 53 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ expiration = 604800 # 7 days
[database]
host = "127.0.0.1"
port = 5432
username = "app"
username = "postgres"
password = "YSm*wF60c72CLJD!"
database_name = "vulnfeed"

41
docker-compose.yml Normal file
View File

@@ -0,0 +1,41 @@
version: "3.1"
services:
postgres:
image: postgres:14.0
restart: always
cap_drop:
- NET_RAW
logging:
driver: "json-file"
options:
max-size: "200M"
stop_grace_period: 30s
environment:
POSTGRES_PASSWORD: YSm*wF60c72CLJD!
POSTGRES_USERNAME: postgres
POSTGRES_DB: vulnfeed
TZ: Asia/Shanghai
volumes:
- "./data/:/var/lib/postgresql/data/"
ports:
- "127.0.0.1:5432:5432"
privileged: true
vulnfeed:
image: vulnfeed:latest
restart: always
depends_on:
- postgres
volumes:
- "./config/config.toml:/app/config.toml"
privileged: true
command: ["./vulnfeed", "server", "--config-file", "config.toml"]
ports:
- "9000:9000"
networks:
vulnfeed-net:
name: vulnfeed-net
ipam:
driver: default

View File

@@ -1,5 +1,5 @@
-- Add migration script here
CREATE TABLE vuln_information (
CREATE TABLE IF NOT EXISTS vuln_information (
id BIGSERIAL PRIMARY KEY,
key TEXT NOT NULL UNIQUE,
title TEXT NOT NULL DEFAULT '',
@@ -18,7 +18,7 @@ CREATE TABLE vuln_information (
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE sync_task (
CREATE TABLE IF NOT EXISTS sync_task (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL DEFAULT '',
interval_minutes INTEGER NOT NULL DEFAULT 15,
@@ -28,7 +28,7 @@ CREATE TABLE sync_task (
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE sync_task_record (
CREATE TABLE IF NOT EXISTS sync_task_record (
id BIGSERIAL PRIMARY KEY,
task_id TEXT NOT NULL DEFAULT '',
started_at TIMESTAMPTZ,
@@ -39,10 +39,10 @@ CREATE TABLE sync_task_record (
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE admin_user (
CREATE TABLE IF NOT EXISTS admin_user (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
password TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
);

View File

@@ -73,6 +73,12 @@ async fn run_server(server_rt: &Runtime, config: Config) -> Result<(), Error> {
let jwt = JWT::new(&config.auth.jwt.secret);
let db = Pg::new(&config).await.change_context_lazy(make_error)?;
sqlx::migrate!("./migrations")
.run(&db.pool)
.await
.change_context_lazy(make_error)?;
let (sender, receiver) = mea::mpsc::unbounded::<CreateVulnInformation>();
plugins::init(sender).change_context_lazy(make_error)?;