From 0273ccf933f7706b0439b693716291c1c79a5bad Mon Sep 17 00:00:00 2001 From: cn-kali-team Date: Tue, 5 Dec 2023 14:12:01 +0800 Subject: [PATCH] docker --- .dockerignore | 8 ++++++-- .gitignore | 1 + Cargo.toml | 4 ++++ Dockerfile | 31 ++++++++++++++++++++++++------- Trunk.toml | 2 +- fly.toml | 21 ++------------------- nvd-server/Cargo.toml | 4 +++- nvd-server/src/main.rs | 4 ++-- nvd-yew/Trunk.toml | 6 ++++++ rust-toolchain.toml | 2 +- 10 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 nvd-yew/Trunk.toml diff --git a/.dockerignore b/.dockerignore index 4484b8b..0799507 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,8 @@ target -nvd-server/dist nvd-server/nvd-er.mwb.bak -nvd-server/nvd-er.mwb \ No newline at end of file +nvd-server/nvd-er.mwb +.idea +.github +dev-script +helper/examples +helper/tests \ No newline at end of file diff --git a/.gitignore b/.gitignore index 13b4ed1..1770e07 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ Cargo.lock /.env /nvd-server/nvd-er.mwb.bak /nvd-server/dist/ +/dist/ diff --git a/Cargo.toml b/Cargo.toml index b1f4e20..9257d07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,7 @@ opt-level = 3 [dependencies] + +[[bin]] +name = "nvd-server" +path = "nvd-server/src/main.rs" diff --git a/Dockerfile b/Dockerfile index bface7c..4fcfa51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,33 @@ FROM rust:slim-buster AS builder WORKDIR /prod #为了命中docker构建缓存,先拷贝这几个文件进去 -COPY nvd-server/Cargo.toml Cargo.toml COPY .cargo .cargo -RUN cargo fetch - -COPY nvd-server/src src +RUN rustup target add wasm32-unknown-unknown +RUN cargo install --locked trunk +RUN cargo install --locked wasm-bindgen-cli RUN apt-get update -RUN apt-get install -y --no-install-recommends xz-utils liblz4-tool libssl-dev default-libmysqlclient-dev pkg-config +RUN apt-get install -y --no-install-recommends gcc-multilib xz-utils liblz4-tool libc6-dev libssl-dev default-libmysqlclient-dev pkg-config musl-tools patchelf build-essential zlib1g-dev ca-certificates +COPY Cargo.toml Cargo.toml +COPY Trunk.toml Trunk.toml +COPY cpe cpe +COPY cve cve +COPY cvss cvss +COPY cwe cwe +COPY nvd-yew nvd-yew +COPY nvd-api nvd-api +COPY nvd-server nvd-server +COPY helper helper RUN cargo build --release +RUN trunk build --release # Use any runner as you want # But beware that some images have old glibc which makes rust unhappy -FROM fedora:34 AS runner -COPY --from=builder /prod/target/release/rust-demo-server /bin \ No newline at end of file +FROM debian:latest AS runner +WORKDIR /prod +ENV TZ=Asia/Shanghai +RUN apt-get update +RUN apt-get install -y --no-install-recommends libssl-dev default-libmysqlclient-dev ca-certificates +COPY --from=builder /prod/target/release/nvd-server /prod +COPY --from=builder /prod/dist /prod/dist +EXPOSE 8888 +CMD [ "/prod/nvd-server" ] \ No newline at end of file diff --git a/Trunk.toml b/Trunk.toml index bc0ba98..3b7ff08 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -1,6 +1,6 @@ [build] target = "nvd-yew/index.html" -dist = "nvd-server/dist" +dist = "dist" [[proxy]] backend = "http://127.0.0.1:8888/api/" \ No newline at end of file diff --git a/fly.toml b/fly.toml index 84c4684..a6be4a1 100644 --- a/fly.toml +++ b/fly.toml @@ -7,7 +7,7 @@ app = "nvd-rs" primary_region = "nrt" [http_service] - internal_port = 8080 + internal_port = 8888 force_https = true auto_stop_machines = true auto_start_machines = true @@ -17,21 +17,4 @@ primary_region = "nrt" [[vm]] cpu_kind = "shared" cpus = 1 - memory_mb = 1024 - -[[services.ports]] -handlers = ["http"] -port = 80 - -[[services.ports]] -handlers = ["tls", "http"] -port = 443 - -[[services.http_checks]] -path = "/health" -method = "get" -timeout = "2000" -interval = "10000" -protocol = "http" -grace_period = "5s" -tls_skip_verify = false \ No newline at end of file + memory_mb = 256 \ No newline at end of file diff --git a/nvd-server/Cargo.toml b/nvd-server/Cargo.toml index 543f5e3..ab4916b 100644 --- a/nvd-server/Cargo.toml +++ b/nvd-server/Cargo.toml @@ -6,7 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = { version = "4.4.0" } +actix-web = { version = "4.4.0", features = ["openssl"] } +openssl-sys = "0.9" +openssl = { version = "0.10", features = ["vendored"] } actix-files = "0.6.2" actix-cors = "0.6.4" diesel = { version = "2.1.4", features = ["r2d2", "mysql", "chrono", "uuid", "serde_json"] } diff --git a/nvd-server/src/main.rs b/nvd-server/src/main.rs index 6f5c083..8f0aad6 100644 --- a/nvd-server/src/main.rs +++ b/nvd-server/src/main.rs @@ -19,12 +19,12 @@ async fn main() -> std::io::Result<()> { .app_data(web::Data::new(connection_pool.clone())) .service(web::scope("/api").configure(api_route)) .service( - actix_files::Files::new("/", "nvd-server/dist") + actix_files::Files::new("/", "dist") .show_files_listing() .index_file("index.html"), ) }) - .bind(("127.0.0.1", 8888))? + .bind(("0.0.0.0", 8888))? .run() .await } diff --git a/nvd-yew/Trunk.toml b/nvd-yew/Trunk.toml new file mode 100644 index 0000000..aba4a1e --- /dev/null +++ b/nvd-yew/Trunk.toml @@ -0,0 +1,6 @@ +[build] +target = "index.html" +dist = "dist" + +[[proxy]] +backend = "http://127.0.0.1:8888/api/" \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5a209d8..7cba774 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.72.0" +channel = "stable" components = ["rustfmt", "clippy"] #https://rust-lang.github.io/rustup/overrides.html \ No newline at end of file