diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fd4b210 --- /dev/null +++ b/Dockerfile @@ -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"] + diff --git a/build_and_push.sh b/build_and_push.sh new file mode 100755 index 0000000..6056a67 --- /dev/null +++ b/build_and_push.sh @@ -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 diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..6ae831f --- /dev/null +++ b/deploy.sh @@ -0,0 +1,34 @@ +#!/bin/sh +REGION=ca-central-1 +ENVIRONMENT=${1:-staging} +CLUSTER_NAME=$ENVIRONMENT-renegade-dealer-cluster +SERVICE_NAME=$ENVIRONMENT-renegade-dealer-service +TASK_FAMILY=$ENVIRONMENT-renegade-dealer-task-def +ECR_URL=377928551571.dkr.ecr.ca-central-1.amazonaws.com/renegade-dealer-$ENVIRONMENT + +# Fetch the latest image URI from ECR +IMAGE_URI=$(aws ecr describe-images --repository-name renegade-dealer-$ENVIRONMENT --region $REGION --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text) +FULL_IMAGE_URI="$ECR_URL:$IMAGE_URI" +echo "Using image URI: $FULL_IMAGE_URI" + +# Fetch the existing definition of the task and create a new revision with the updated URI +TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition $TASK_FAMILY --region $REGION --query 'taskDefinition') +NEW_TASK_DEF=$(echo $TASK_DEFINITION | \ + jq --arg IMAGE_URI "$FULL_IMAGE_URI" '.containerDefinitions[0].image = $IMAGE_URI' | \ + jq 'del(.taskDefinitionArn)' | \ + jq 'del(.revision)' | \ + jq 'del(.status)' | \ + jq 'del(.requiresAttributes)' | \ + jq 'del(.compatibilities)' | \ + jq 'del(.registeredAt)' | \ + jq 'del(.registeredBy)' | \ + jq -c) + +# Register the new task definition +NEW_TASK_INFO=$(aws ecs register-task-definition --cli-input-json "$NEW_TASK_DEF" --region $REGION) +NEW_REVISION=$(echo $NEW_TASK_INFO | jq -r '.taskDefinition.revision') +echo "Created new task revision: $NEW_REVISION" + +# Update the ECS cluster to the new revision +aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --task-definition $TASK_FAMILY:$NEW_REVISION --region $REGION >/dev/null 2>&1 +echo "ECS cluster updated to new revision" diff --git a/renegade-dealer/src/main.rs b/renegade-dealer/src/main.rs index d2c5f52..bb7fc10 100644 --- a/renegade-dealer/src/main.rs +++ b/renegade-dealer/src/main.rs @@ -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::()) @@ -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.