Skip to content

Commit

Permalink
smaller docker image + back to axum
Browse files Browse the repository at this point in the history
  • Loading branch information
m1guelpf committed Sep 7, 2023
1 parent 64a114a commit 65dec11
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 188 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
Dockerfile
README.md
Tiltfile
161 changes: 0 additions & 161 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ description = "A bridge between the World ID SDK and the World App"
[dependencies]
axum = "0.6.20"
tower = "0.4.13"
serde = "1.0.183"
serde = { version = "1.0.183", features = ["derive"] }
dotenvy = "0.15.7"
lambda_http = "0.8.1"
axum-aws-lambda = "0.5.0"
tracing = { version = "0.1", features = ["log"] }
tokio = { version = "1.31.0", features = ["full"] }
tower-http = { version = "0.4.3", features = ["cors"] }
Expand Down
30 changes: 14 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
####################################################################################################
## Base image
####################################################################################################
FROM rust:latest AS builder

RUN update-ca-certificates

FROM clux/muslrust:stable AS chef
USER root
WORKDIR /app
RUN cargo install cargo-chef

COPY ./Cargo.toml .
COPY ./Cargo.lock .

RUN mkdir ./src && echo 'fn main() { println!("you lost the game"); }' > ./src/main.rs

RUN cargo build --release

RUN rm -rf ./src

COPY src src
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

RUN cargo build --release
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl

####################################################################################################
## Final image
Expand All @@ -27,6 +23,8 @@ FROM gcr.io/distroless/cc

WORKDIR /app

COPY --from=builder /app/target/release/world-id-bridge /app/world-id-bridge
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/world-id-bridge /app/world-id-bridge

USER 100
EXPOSE 8000
CMD ["/app/world-id-bridge"]
21 changes: 13 additions & 8 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use axum::Extension;
use axum_aws_lambda::LambdaLayer;
use std::{env, net::SocketAddr};

use axum::{Extension, Server};
use redis::aio::ConnectionManager;
use tower::ServiceBuilder;

use crate::routes;

pub async fn start(redis: ConnectionManager) {
let router = routes::handler().layer(Extension(redis));
let app = routes::handler().layer(Extension(redis));

let app = ServiceBuilder::new()
.layer(LambdaLayer::default())
.service(router);
let address = SocketAddr::from((
[0, 0, 0, 0],
env::var("PORT").map_or(8000, |p| p.parse().unwrap()),
));

lambda_http::run(app).await.unwrap();
println!("🪩 World Bridge started on http://{address}");
Server::bind(&address)
.serve(app.into_make_service())
.await
.expect("Failed to start server");
}

0 comments on commit 65dec11

Please sign in to comment.