Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmindlin committed Feb 20, 2024
1 parent 5989ff2 commit 44198d0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ POSTGRES_USER=testuser
POSTGRES_PASSWORD=testuserpwd
POSTGRES_DB=locust
POSTGRES_HOST=postgres-locust
POSTGRES_PORT=5436
POSTGRES_PORT=5432
6 changes: 3 additions & 3 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app

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

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --bin locust

# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/locust /usr/local/bin
ENTRYPOINT ["/usr/local/bin/locust"]
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
services:
locust:
networks:
- locust-net
image: locust:latest
container_name: locust
build:
context: .
env_file: .env
depends_on:
- postgres-locust
- flyway-locust

postgres-locust:
networks:
- locust-net
container_name: postgres-locust
image: postgres:15-alpine
environment:
Expand All @@ -17,6 +31,8 @@ services:
- postgres-locust:/var/lib/postgresql/data/

flyway-locust:
networks:
- locust-net
container_name: flyway-locust
environment:
FLYWAY_USER: ${POSTGRES_USER}
Expand All @@ -30,5 +46,9 @@ services:
depends_on:
- postgres-locust

networks:
locust-net:
external: false

volumes:
postgres-locust:
4 changes: 2 additions & 2 deletions locust-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pub async fn new_pool() -> Result<PgPool, Error> {
let user = env::var("POSTGRES_USER").unwrap();
let pwd = env::var("POSTGRES_PASSWORD").unwrap_or("password".into());
let db = env::var("POSTGRES_DB").unwrap_or("postgres".into());
// let host = env::var("POSTGRES_HOST").unwrap_or("localhost".into());
let host = "localhost";
let host = env::var("POSTGRES_HOST").unwrap_or("localhost".into());
let port = env::var("POSTGRES_PORT")
.unwrap_or("5432".into())
.parse::<usize>()
.expect("Invalid psql port");
let conn_string = format!("postgresql://{}:{}@{}:{}/{}", user, pwd, host, port, db);
println!("{}", conn_string);

let pool = PgPoolOptions::new().connect(&conn_string).await?;

Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ impl ServiceWrapper {
async fn main() {
tracing_subscriber::fmt::init();

let mut private_key_bytes: &[u8] = include_bytes!("ca/hudsucker.key");
let mut ca_cert_bytes: &[u8] = include_bytes!("ca/hudsucker.cer");
let mut private_key_bytes: &[u8] = include_bytes!("ca/locust.key");
let mut ca_cert_bytes: &[u8] = include_bytes!("ca/locust.cer");
let private_key = tokio_rustls::rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
Expand All @@ -84,6 +84,7 @@ async fn main() {
db: Arc::new(db_pool),
};

println!("Starting up proxy server!");
if let Err(e) = wrapper.start(shutdown_signal()).await {
error!("{}", e);
}
Expand Down

0 comments on commit 44198d0

Please sign in to comment.