Skip to content

Commit

Permalink
feat: add working docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Net-Mist committed Jan 11, 2024
1 parent 630eda6 commit 53f4157
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
17 changes: 13 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
target
old
.cargo
tarpaulin-report.html
millennium.log*
.cargo
.env
.git
.github
.gitignore
deny.toml
examples
old
Readme.md
rustfmt.toml
target
tarpaulin-report.html
tests
Dockerfile
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
FROM rust:1.75.0-buster as builder

RUN rustup target add x86_64-unknown-linux-musl
RUN apt update && apt install -y clang

WORKDIR /app
COPY . /app/

COPY Cargo.lock /app/
COPY Cargo.toml /app/
COPY src /app/src/
COPY front /app/front/
COPY .sqlx /app/.sqlx
RUN cargo build --release

FROM scratch
USER 1000
FROM ubuntu:24.04
WORKDIR /app
COPY --from=builder /app/target/release/millennium_falcon .
ENTRYPOINT [ "./millennium_falcon" ]
6 changes: 5 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Solution of the [developer-test](https://github.com/lioncowlionant/developer-tes

With a recent version of rust (tested with 1.75.0), you can build the project with `cargo build --release`. Then you can run the cli with `./target/release/give-me-the-odds examples/millennium-falcon.json examples/example2/empire.json` and the webserver with `./target/release/millennium_falcon examples/millennium-falcon.json`.

Note that when starting, the webserver will create a file `millennium.log.{date}` containing the log of the server. stdio will be pretty silent if everything goes well. The server will be listening on `127.0.0.1:8000`.
Note that when starting, the webserver will create a folder `logs` containing a file `millennium.log.{date}` with the log of the server. stdio will be pretty silent if everything goes well. The server will be listening on `127.0.0.1:8000`.

It is also possible to start the server with docker by running `docker build -t millennium-falcon .` then `docker run -it --rm -v ./logs:/app/logs -v ./examples:/app/examples -p 0.0.0.0:8000:8000 millennium-falcon examples/millennium-falcon.json`

and the cli by running `docker build -t give-me-the-odds -f cli.Dockerfile .` then `docker run -it --rm -v ./examples:/app/examples give-me-the-odds examples/millennium-falcon.json examples/example1/empire.json`

## Architecture

Expand Down
13 changes: 13 additions & 0 deletions cli.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1.75.0-buster as builder
WORKDIR /app
COPY Cargo.lock /app/
COPY Cargo.toml /app/
COPY src /app/src/
COPY front /app/front/
COPY .sqlx /app/.sqlx
RUN cargo build --release

FROM ubuntu:24.04
WORKDIR /app
COPY --from=builder /app/target/release/give-me-the-odds .
ENTRYPOINT [ "./give-me-the-odds" ]
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub async fn setup_webserver(address: &str) -> Result<Server> {

#[actix_web::main]
async fn main() -> std::io::Result<()> {
let file_appender = tracing_appender::rolling::daily(".", "millennium.log");
let file_appender = tracing_appender::rolling::daily("logs", "millennium.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
tracing_subscriber::fmt().with_writer(non_blocking).init();

match setup_webserver("127.0.0.1:8000").await {
match setup_webserver("0.0.0.0:8000").await {
Ok(server) => server.await,
Err(e) => {
let e = e.context("unable to start the server");
Expand Down

0 comments on commit 53f4157

Please sign in to comment.