Skip to content

Commit

Permalink
fix: use smaller images, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumichocopengin8 committed Dec 8, 2024
1 parent 4ac086e commit 09a5f77
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 5 deletions.
1 change: 1 addition & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
.DS_Store
.env
.git
114 changes: 114 additions & 0 deletions api/Cargo.lock

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

8 changes: 6 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ tokio = { version = "1.42.0", features = ["full"] }
tower = { version = "0.5.1", features = [
"util", # `util` feature for unit test (oneshot func etc)
] }
tower-http = { version = "0.6.2", features = ["cors", "trace"] }
tower-http = { version = "0.6.2", features = [
"cors",
"trace",
"compression-full",
] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[profile.release]
lto = true
codegen-units = 1
strip = true # same as strip command on Linux
strip = true # same as strip command on Linux
4 changes: 2 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ WORKDIR /app
COPY . .
RUN cargo build --release

FROM amazonlinux:2023
RUN yum install -y openssl openssl-devel
FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
RUN dnf install -y openssl openssl-devel
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter
COPY --from=builder /app/target/release/crate_trends_api /app
CMD ["/app"]
9 changes: 8 additions & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

## Set up

- In api directory, run `HOST=127.0.0.1 cargo run`. Then access `http://localhost:8080`. Default host is `0.0.0.0`
### Local

- In the current directory, run `HOST=127.0.0.1 cargo run`. Then access `http://localhost:8080`. Default host is `0.0.0.0`
- You may setup custom port as well with `PORT=80`. Default port is `8080`. However, front page uses `8080` port, so you should use default port.

### Docker

- In the current directory, run `docker compose up` (`docker compose up -d` for background). Then access `http://localhost:8080`.
- The docker image is depoyable on AWS Lambda

After starting a server, access `http://localhost:8080/up`. All set if you see `You're up!!` message.
8 changes: 8 additions & 0 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use axum::{
};
use std::time::Duration;
use tower_http::{
compression::CompressionLayer,
cors::{AllowOrigin, CorsLayer},
trace::TraceLayer,
};
Expand Down Expand Up @@ -72,6 +73,13 @@ fn app() -> Router {
.max_age(Duration::from_secs(60) * 5),
)
.layer(TraceLayer::new_for_http())
.layer(
CompressionLayer::new()
.br(true)
.gzip(true)
.zstd(true)
.deflate(true),
)
}

async fn get_crate_data(Path(id): Path<String>) -> impl IntoResponse {
Expand Down

0 comments on commit 09a5f77

Please sign in to comment.