From f134f7e69028668702f2437aba4821a1215966f8 Mon Sep 17 00:00:00 2001 From: Camerin Figueroa Date: Mon, 29 Apr 2024 21:02:02 +0000 Subject: [PATCH] docker-compose_update - Updated docker-compose to be fully functional I updated Dockerfile and docker-compose.yml to work together. Each component of the app can now be deployed at once. --- Dockerfile | 8 +++-- README.md | 20 +++++++++---- docker-compose.yml | 29 +++++++++++-------- .../2024-03-02-000805_create_clients/up.sql | 4 ++- src/lib.rs | 14 ++++++--- 5 files changed, 49 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa6cd29..d3064ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,14 @@ WORKDIR ./app COPY . . RUN cargo install --path . -FROM debian:bookworm-slim as runner +FROM rustlang/rust:nightly as runner +COPY migrations /migrations +RUN cargo install diesel_cli --no-default-features --features postgres RUN apt update && apt install -y libpq-dev libc6 COPY --from=builder /usr/local/cargo/bin/request-mirror /usr/local/bin/request-mirror COPY ./templates /templates -COPY .env.docker .env +COPY .env.docker /.env ENV ROCKET_ADDRESS=0.0.0.0 ENV ROCKET_ENV=production EXPOSE 8000 -CMD ["request-mirror"] \ No newline at end of file +ENTRYPOINT diesel migration run --migration-dir /migrations && request-mirror \ No newline at end of file diff --git a/README.md b/README.md index c950952..34252c3 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,24 @@ This application provides a web ui for sending get/post requests and provides a ## TODO: - Update Readme - Document - - Setup Docker ## Docker -This is the current setup for getting the webapp to work with docker. This may not work on your machine, this is beta. +Please read through the documentation on setting up and installing docker on your machine. +We'll use the CLI commands to deploy the application to docker. + +See [Get Docker](https://docs.docker.com/get-docker/) + +First you'll want to ensure you have build the container. Do that by running ```bash -cd request-mirror - -sh deploy.sh +docker build . -t raspberrypi99/request-mirror ``` -This will setup the container. A better setup will come in the future. +Next you can start up the application using docker compose + +```bash +docker compose up -d +``` + +This will deploy the application to docker. It will setup the postgres server, deploy the database using diesel and start request-mirror. diff --git a/docker-compose.yml b/docker-compose.yml index 8d31fb0..c564ed6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,6 @@ -version: 3.8 +version: "3.8" services: - request-mirror: - image: request-mirror - ports: - - 80:80 - environment: - - DB_HOST=postgres - depends_on: - - postgres - networks: - - app-network - postgres: image: postgres environment: @@ -22,6 +11,22 @@ services: - db-data:/var/lib/postgresql/data networks: - app-network + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres -d request_mirror_db | grep 'accepting connections'"] + request-mirror: + #image: request-mirror + build: &request_mirror_build + context: . + dockerfile: ./Dockerfile + ports: + - 80:8000 + environment: + - DATABASE_URL=postgres://postgres:password@postgres/request_mirror_db + depends_on: + postgres: + condition: service_healthy + networks: + - app-network networks: app-network: diff --git a/migrations/2024-03-02-000805_create_clients/up.sql b/migrations/2024-03-02-000805_create_clients/up.sql index 61c54ae..310d1a7 100644 --- a/migrations/2024-03-02-000805_create_clients/up.sql +++ b/migrations/2024-03-02-000805_create_clients/up.sql @@ -28,4 +28,6 @@ CREATE TABLE IF NOT EXISTS pair_records pair_type SMALLINT NOT NULL, key TEXT NOT NULL, value TEXT NOT NULL -); \ No newline at end of file +); + +CREATE INDEX pair_records_history_id_idx ON pair_records(history_id); diff --git a/src/lib.rs b/src/lib.rs index 8d742ba..0f22014 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,10 @@ use schema::{ /// Establishes diesel Postgres connection that can be used to iteract with the database /// /// Example: -/// ``` +/// +/// ```rust +/// use request_mirror::establish_connection; +/// /// let connection = establish_connection(); /// ``` pub fn establish_connection() -> PgConnection { @@ -30,10 +33,13 @@ pub fn establish_connection() -> PgConnection { /// Used to create a new client in the database. You need to pass a connection, the ip and client_id /// /// Example: -/// ``` -/// let connection = establish_connection(); /// -/// create_client(connection, "192.168.0.1", "195222-222-123123"); +/// ```rust,ignore +/// use request_mirror::{establish_connection, create_client}; +/// +/// let mut connection = establish_connection(); +/// +/// create_client(&mut connection, "192.168.0.1", "195222-222-123123"); /// ``` /// /// create_client returns a value of usize which represents the number of entries created