Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

renegade-dealer: Add healthcheck endpoint and deployment setup #5

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM --platform=arm64 rust:latest AS chef

WORKDIR /build
COPY ./rust-toolchain ./rust-toolchain
RUN rustup install $(cat rust-toolchain)

RUN apt-get update && apt-get install -y libssl-dev

# Install chef and generate a recipe
RUN cargo install cargo-chef

COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
COPY ./renegade-dealer ./renegade-dealer
COPY ./renegade-dealer-api ./renegade-dealer-api
RUN cargo chef prepare --recipe-path recipe.json

# Disable compiler warnings and enable backtraces for panic
ENV RUSTFLAGS=-Awarnings
ENV RUST_BACKTRACE=1

# Build only the dependencies to cache them in this layer
RUN cargo chef cook --release --recipe-path recipe.json

# Copy back in the full sources and build the tests
WORKDIR /build
COPY ./Cargo.lock ./Cargo.lock
COPY ./renegade-dealer ./renegade-dealer
COPY ./renegade-dealer-api ./renegade-dealer-api

WORKDIR /build/renegade-dealer
RUN cargo build --release --quiet --all-features

ENTRYPOINT ["cargo", "run", "--release", "--all-features"]

10 changes: 10 additions & 0 deletions build_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
REGION=ca-central-1
ENVIRONMENT=${1:-staging}
ECR_URL=377928551571.dkr.ecr.ca-central-1.amazonaws.com/renegade-dealer-$ENVIRONMENT

docker build -t dealer:latest .
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ECR_URL

docker tag dealer:latest $ECR_URL:latest
docker push $ECR_URL:latest
8 changes: 8 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
REGION=ca-central-1
ENVIRONMENT=${1:-staging}
CLUSTER_NAME=$ENVIRONMENT-renegade-dealer-cluster
SERVICE_NAME=$ENVIRONMENT-renegade-dealer-service

# Update the ECS service to use the latest image
aws ecs update-service --region $REGION --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment
10 changes: 8 additions & 2 deletions renegade-dealer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn main() {
Dealer::start(dealer_recv);

// POST /v0/offline-phase/:request_id
let setup = warp::post()
let offline_phase = warp::post()
.and(warp::path("v0"))
.and(warp::path("offline-phase"))
.and(warp::path::param::<RequestId>())
Expand All @@ -82,7 +82,13 @@ async fn main() {
})
.recover(handle_rejection);

warp::serve(setup).run(([127, 0, 0, 1], cli.port)).await
// GET /ping
let ping = warp::get()
.and(warp::path("ping"))
.map(|| warp::reply::with_status("PONG", warp::http::StatusCode::OK));

let routes = offline_phase.or(ping);
warp::serve(routes).run(([0, 0, 0, 0], cli.port)).await
}

/// Validates the incoming request headers and body.
Expand Down
Loading