Skip to content

Commit

Permalink
Working local setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Feb 6, 2024
1 parent b2412a9 commit b8164f8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ RUN apt-get update && \
# Install rustup
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

COPY ./src ./src
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
COPY ./rust-toolchain.toml ./rust-toolchain.toml
COPY ./rustfmt.toml ./rustfmt.toml
COPY ./migrations ./migrations
COPY ./bin ./bin
# Not needed for the final build
# but we specify benches in Cargo.toml so it's necessary
COPY ./benches ./benches

# Set environment variables
ENV PATH="/root/.cargo/bin:${PATH}"
Expand All @@ -32,6 +23,16 @@ ENV CARGO_HOME="/root/.cargo"
# Install the toolchain
RUN rustup component add cargo

COPY ./src ./src
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
COPY ./rustfmt.toml ./rustfmt.toml
COPY ./migrations ./migrations
COPY ./bin ./bin
# Not needed for the final build
# but we specify benches in Cargo.toml so it's necessary
COPY ./benches ./benches

# Build the binary
RUN cargo fetch
RUN cargo build --release --no-default-features
Expand Down
5 changes: 5 additions & 0 deletions bin/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct SQSQuery {
#[clap(short, long)]
pub endpoint_url: Option<String>,

/// The AWS region
#[clap(short, long)]
pub region: Option<String>,

/// The URL of the SQS queue
#[clap(short, long)]
pub queue_url: String,
Expand Down Expand Up @@ -54,6 +58,7 @@ async fn main() -> eyre::Result<()> {
Opt::SQSQuery(args) => {
let sqs_client = sqs_client_from_config(&AwsConfig {
endpoint: args.endpoint_url,
region: args.region,
})
.await?;

Expand Down
23 changes: 16 additions & 7 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: '3'
services:
localstack:
hostname: localstack_main
hostname: localstack
image: localstack/localstack
ports:
- "4566:4566"
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
Expand All @@ -14,26 +16,33 @@ services:
restart: always
environment:
- 'RUST_LOG=info'
- 'MPC__COORDINATOR__PARTICIPANTS=["127.0.0.1:8081"]'
- 'MPC__COORDINATOR__PARTICIPANTS=["participant:8080"]'
- 'MPC__COORDINATOR__HAMMING_DISTANCE_THRESHOLD=0.375'
- 'MPC__COORDINATOR__N_CLOSEST_DISTANCES=10'
- 'MPC__COORDINATOR__GATEWAY__TYPE=http'
- 'MPC__COORDINATOR__GATEWAY__SOCKET_ADDR=127.0.0.1:8080'
- 'MPC__COORDINATOR__GATEWAY__DISTANCE_RESULTS_URL=""'
- 'MPC__COORDINATOR__GATEWAY__FIRE_AND_FORGET=true'
- 'MPC__COORDINATOR__DB__URL=postgres://postgres:postgres@coordinator_db:5432/db'
- 'MPC__COORDINATOR__DB__MIGRATE=true'
- 'MPC__COORDINATOR__DB__CREATE=true'
- 'MPC__COORDINATOR__AWS__ENDPOINT=http://localstack:4566'
- 'MPC__COORDINATOR__AWS__REGION=us-east-1'
- 'MPC__COORDINATOR__QUEUES__SHARES_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/coordinator-uniqueness-check'
- 'MPC__COORDINATOR__QUEUES__DISTANCES_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/coordinator-results-queue'
- 'MPC__COORDINATOR__QUEUES__DB_SYNC_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/coordinator-db-sync-queue'
# AWS env vars - they don't matter but are required
- 'AWS_ACCESS_KEY_ID=test'
- 'AWS_SECRET_ACCESS_KEY=test'
- 'AWS_DEFAULT_REGION=us-east-1'

build:
context: .
dockerfile: Dockerfile
ports:
- 8080:8080
participant:
restart: always
hostname: participant
environment:
- 'RUST_LOG=info'
- 'MPC__PARTICIPANT__SOCKET_ADDR=127.0.0.1:8081'
- 'MPC__PARTICIPANT__SOCKET_ADDR=0.0.0.0:8080'
- 'MPC__PARTICIPANT__BATCH_SIZE=20000'
- 'MPC__PARTICIPANT__DB__URL=postgres://postgres:postgres@participant_db:5432/db'
- 'MPC__PARTICIPANT__DB__MIGRATE=true'
Expand Down
5 changes: 3 additions & 2 deletions init-scripts/ready.d/create_sqs_queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

# Create your SQS queues
echo "Creating SQS queues..."
awslocal sqs create-queue --queue-name coordinator-inbound
awslocal sqs create-queue --queue-name coordinator-outbound
awslocal sqs create-queue --queue-name coordinator-uniqueness-check
awslocal sqs create-queue --queue-name coordinator-results-queue
awslocal sqs create-queue --queue-name coordinator-db-sync-queue
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub struct AwsConfig {
///
/// Useful when using something like LocalStack
pub endpoint: Option<String>,

#[serde(default)]
pub region: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -111,6 +114,7 @@ mod tests {
},
aws: AwsConfig {
endpoint: Some("http://localhost:4566".to_string()),
region: None,
}
}),
participant: None,
Expand Down
8 changes: 6 additions & 2 deletions src/utils/aws.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aws_config::Region;
use aws_sdk_sqs::types::Message;
use eyre::{Context, ContextCompat};
use serde::de::DeserializeOwned;
use eyre::Context;
use serde::Serialize;

use crate::config::AwsConfig;
Expand All @@ -15,6 +15,10 @@ pub async fn sqs_client_from_config(
config_builder = config_builder.endpoint_url(endpoint_url);
}

if let Some(region) = config.region.as_ref() {
config_builder = config_builder.region(Region::new(region.clone()));
}

let aws_config = config_builder.load().await;

let aws_client = aws_sdk_sqs::Client::new(&aws_config);
Expand Down

0 comments on commit b8164f8

Please sign in to comment.