A rocket.rs webserver designed to mirror a request back to a client that made it. This was originally designed to test requests from the browser or http clients. The backend keeps track of requests made by users.
Go to file
RaspberryProgramming e358f8b3a7 Added information on deployment with an ansible playbook 2024-07-25 00:22:18 +00:00
.github/workflows Update docker-test.yml 2024-07-17 20:05:03 -04:00
.vscode Added Additional features 2024-03-04 22:19:39 +00:00
migrations Updated docker image to default to port 80 2024-06-18 15:28:10 -04:00
src Ownership Registration - New functionality 2024-07-19 14:57:49 +00:00
templates Fixed bug where owner_id was hardcoded 2024-07-19 15:29:06 +00:00
.env Added Docker and short instructions 2024-03-07 21:57:25 +00:00
.env.docker Added Docker and short instructions 2024-03-07 21:57:25 +00:00
.gitignore Updated Docker compose and docker image to pass DATABASE_URL as environment var to Request Mirror 2024-05-03 00:46:49 +00:00
Cargo.lock Updated version and README 2024-07-19 15:14:22 +00:00
Cargo.toml Updated version and README 2024-07-19 15:14:22 +00:00
Dockerfile v0.5 Upgrade - Upgraded and modified project to support rocket.rs v0.5.1 2024-07-03 23:34:25 +00:00
README.md Added information on deployment with an ansible playbook 2024-07-25 00:22:18 +00:00
Rocket.toml v0.5 Upgrade - Upgraded and modified project to support rocket.rs v0.5.1 2024-07-03 23:34:25 +00:00
deploy.sh Updated docker image to default to port 80 2024-06-18 15:28:10 -04:00
diesel.toml Added Additional features 2024-03-04 22:19:39 +00:00
docker-compose.yml Updated docker image to default to port 80 2024-06-18 15:28:10 -04:00

README.md

Request Mirror

This application provides a web ui for sending get/post requests and provides a visual ui for looking at what the application received. This is written in rust.

Build and Publish Docker Image Build and Test Rust

TODO:

N/a

Docker

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

First you'll want to ensure you have build the container. Do that by running

docker build . -t raspberrypi99/request-mirror

Next you can start up the application using docker compose

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.

The following command will stop the deployed containers

docker compose down

Pushing to dockerhub

The image can then be pushed to docker using the following command. You may also want to modify it a little to your need

First login

docker login

Then push the image

docker push raspberrypi99/request-mirror:latest

Development Environment

During development, you'll want to use a few tools to help work on this project.

First, you'll want to install docker.

For environments with a GUI: https://docs.docker.com/desktop/ For environments without a GUI: https://docs.docker.com/engine/install/

You can use docker for many things. This project has a set of files for creating and deploying as a docker container. In order to start development, you'll need a postgres container. By default in the .env file, the rust code will attempt to connect a localhost instance of postgres.

Use the following command to start a postgres container.

docker run --name postgres -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_USER=postgres -e POSTGRES_DB=request_mirror_db -d postgres

This will start up an instance of postgres to only localhost. Remote computers can't connect to the database. This setup does not use any volumes, meaning that when the container is removed, the data will be gone. If you'd like to add volumes, you can run the following command instead which maps a new postgres-data volume to /var/lib/postgresql/data.

docker run --name postgres -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_USER=postgres -e POSTGRES_DB=request_mirror_db -v postgres-data:/var/lib/postgresql/data  -d postgres:latest

Now that postgres is running, you can now install rust if you haven't already. Follow the instructions on the following site rustup.rs

Follow the instructions for installing the stable toolchain for rust. You may need to log in and log out after installation.

Notice: Older versions of request mirror used rocket v0.4.x which required the nightly toolchain, please update your repo/fork.

Next, we can install diesel, an ORM and query builder for rust. This is how we deploy tables to our database. Install diesel cli:

cargo install diesel_cli --no-default-features --features postgres

You can deploy the database with the following command:

Notice: If you are not adding a volume to your postgres database, you may need to re-run this step each time you create the postgres docker container.

diesel migration run

Now that the database is ready and rust is installed, we can move onto running the project.

cargo run

You can also run the following to run a release binary

cargo run --release

Build Docker Image and Run Locally

You can build the docker image by running the following comand

docker build . -t raspberrypi99/request-mirror

Next, you can run the project using the following command. This can be run even with the development postgres container running. This will open port 80 for the user to connect to.

docker compose up -d

Ansible Playbook

You can get access to an ansible playbook and associated files by checking out the following repository

https://github.com/RaspberryProgramming/CamsAnsibleLibrary/

You can clone the repository

git clone https://github.com/RaspberryProgramming/CamsAnsibleLibrary

cd CamsAnsibleLibrary/Request\ Mirror/

Next, you can create your "inventory" file

[request-mirror-host]
10.1.2.3

If you haven't already, setup an ssh key so you can automatically log into your remote host as root. If you decide to use a user with sudo privileges you may need to modify the playbook on your own.

ansible-playbook request_mirror_deployment.yml -i inventory

If you need to enter a root password, you can add the -K argument

ansible-playbook request_mirror_deployment.yml -i inventory -K