Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-kali-team committed Dec 5, 2023
1 parent 869183e commit 0273ccf
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 33 deletions.
8 changes: 6 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
target
nvd-server/dist
nvd-server/nvd-er.mwb.bak
nvd-server/nvd-er.mwb
nvd-server/nvd-er.mwb
.idea
.github
dev-script
helper/examples
helper/tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Cargo.lock
/.env
/nvd-server/nvd-er.mwb.bak
/nvd-server/dist/
/dist/
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ opt-level = 3


[dependencies]

[[bin]]
name = "nvd-server"
path = "nvd-server/src/main.rs"
31 changes: 24 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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" ]
2 changes: 1 addition & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
@@ -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/"
21 changes: 2 additions & 19 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
memory_mb = 256
4 changes: 3 additions & 1 deletion nvd-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions nvd-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions nvd-yew/Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build]
target = "index.html"
dist = "dist"

[[proxy]]
backend = "http://127.0.0.1:8888/api/"
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.72.0"
channel = "stable"
components = ["rustfmt", "clippy"]

#https://rust-lang.github.io/rustup/overrides.html

0 comments on commit 0273ccf

Please sign in to comment.