Rust multistage build (#550)

* fix get request not accepted

* use mutli-stage docker build to minimize final image

Co-authored-by: Minghe <h.minghe@gmail.com>
This commit is contained in:
FrontMage
2020-06-17 14:16:31 +08:00
committed by GitHub
parent 046226b580
commit ba43561f40
2 changed files with 28 additions and 5 deletions

View File

@@ -1,7 +1,12 @@
FROM liuchong/rustup
WORKDIR /usr/src/myapp
FROM clux/muslrust:nightly AS builder
WORKDIR /build
COPY . .
RUN cp ./config ~/.cargo/ && rustup default nightly && cargo build
RUN ln -s /usr/bin/g++ /usr/bin/musl-g++ && cargo build --release
FROM scratch
WORKDIR /usr/src/myapp
COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/rust /usr/src/myapp/
COPY ./Rocket.toml /usr/src/myapp/
EXPOSE 3000
CMD ["cargo", "run"]
ENV ROCKET_ENV=prod
CMD ["/usr/src/myapp/rust"]

View File

@@ -1,5 +1,23 @@
[development]
address = "localhost"
port = 3000
workers = 8
keep_alive = 5
log = "normal"
limits = { forms = 32768 }
[staging]
address = "0.0.0.0"
port = 3000
workers = 8
keep_alive = 5
log = "normal"
limits = { forms = 32768 }
[production]
address = "0.0.0.0"
port = 3000
workers = 8
keep_alive = 5
log = "critical"
limits = { forms = 32768 }