Added Docker and short instructions

Better documentation and process to come
This commit is contained in:
Camerin Figueroa 2024-03-07 21:57:25 +00:00
parent da0f1ddf2d
commit 540fd269df
6 changed files with 84 additions and 1 deletions

2
.env
View File

@ -1 +1 @@
DATABASE_URL=postgres://username:password@localhost/request_mirror_db DATABASE_URL=postgres://postgres:password@localhost/request_mirror_db

1
.env.docker Normal file
View File

@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:password@postgres/request_mirror_db

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM rustlang/rust:nightly as builder
WORKDIR ./app
COPY . .
RUN cargo install --path .
FROM debian:bookworm-slim as runner
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
ENV ROCKET_ADDRESS=0.0.0.0
ENV ROCKET_ENV=production
EXPOSE 8000
CMD ["request-mirror"]

View File

@ -4,3 +4,16 @@ This application provides a web ui for sending get/post requests and provides a
## TODO: ## TODO:
- Update Readme - Update Readme
- Document - 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.
```bash
cd request-mirror
sh deploy.sh
```
This will setup the container. A better setup will come in the future.

21
deploy.sh Normal file
View File

@ -0,0 +1,21 @@
# Set Rust to nightly
rustup default nightly
# Install Diesel
cargo install diesel_cli --no-default-features --features postgres
# New Network
docker network create postgres-net
# Setup postgres container
docker pull postgres
docker run -d --rm -p 5432:5432 --name postgres --net postgres-net -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password postgres
# Setup db with diesel
diesel database run
diesel migration run
# Build and start request-mirror
docker build . -t raspberrypi99/request-mirror
docker run -d --rm -p 8000:8000 --name request-mirror --net postgres-net raspberrypi99/request-mirror

34
docker-compose.yml Normal file
View File

@ -0,0 +1,34 @@
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:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=request_mirror_db
volumes:
- db-data:/var/lib/postgresql/data
networks:
- app-network
networks:
app-network:
driver: bridge
ipam:
config:
- subnet: 172.16.0.0/24
volumes:
db-data: