diff --git a/.gitignore b/.gitignore index dbc8fd9..0a5c0a9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ discord_bot/graph.png discord_bot/config.py env_win/ velconnect.db +db/ velconnect*.db .idea/ velconnect/data/ diff --git a/README.md b/README.md index 7a32a93..c4cb176 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,37 @@ ## VELConnect API Setup -### Option 1: Pull from Docker Hub: +## Option 1: Build and run using Docker Compose +```sh +cd velconnect +docker compose up -d ``` + +and visit http://localhost:8000 in your browser. + +This will set up autorestart of the docker image. To pull updates, just run `docker compose up -d` again. + +## Option 2: Pull from Docker Hub: + +```sh docker run -p 80:80 velaboratory/velconnect ``` + and visit http://localhost in your browser. -or +or ```sh docker run -p 8000:80 --name web velaboratory/velconnect ``` - to access from http://localhost:8000 in your browser and name the container "web". -### Option 2: Build Docker Image: +to access from http://localhost:8000 in your browser and name the container "web". + +## Option 3: Build Docker Image: Make sure you're in the `velconnect/` folder. -``` + +```sh docker build --tag velconnect . docker rm web docker run -p 80:80 --name web velconnect @@ -25,31 +39,35 @@ docker run -p 80:80 --name web velconnect or run `./rebuild.sh` -### Option 3: Run Python locally (WSL or native Linux) +## Option 4: Run Python locally (WSL or native Linux) + 1. `cd velconnect` 2. Create pip env: `python3 -m venv env` 3. Activate the env `. env/bin/activate` 4. Install packages `pip install -r requirements.txt` 5. Add `config_mysql.py` - - Get from some old server - - Or copy and fill out the values from `config_mysql_template.py` + - Get from some old server + - Or copy and fill out the values from `config_mysql_template.py` 6. Run `./run_server.sh` - - Or set up systemctl service: - ```ini - [Unit] - Description=VELConnect API - Requires=network.target - After=network.target - [Service] - User=ubuntu - Group=ubuntu - Environment="PATH=/home/ubuntu/VEL-Connect/velconnect/env/bin" - WorkingDirectory=/home/ubuntu/VEL-Connect/velconnect - ExecStart=/home/ubuntu/VEL-Connect/velconnect/env/bin/uvicorn --port 8005 main:app - [Install] - WantedBy=multi-user.target - ``` - - Enter the above in `/etc/systemd/system/velconnect.service` - - `sudo systemctl enable velconnect` - - `sudo systemctl start velconnect` \ No newline at end of file + - Or set up systemctl service: + + ```ini + [Unit] + Description=VELConnect API + Requires=network.target + After=network.target + + [Service] + User=ubuntu + Group=ubuntu + Environment="PATH=/home/ubuntu/VEL-Connect/velconnect/env/bin" + WorkingDirectory=/home/ubuntu/VEL-Connect/velconnect + ExecStart=/home/ubuntu/VEL-Connect/velconnect/env/bin/uvicorn --port 8005 main:app + [Install] + WantedBy=multi-user.target + ``` + + - Enter the above in `/etc/systemd/system/velconnect.service` + - `sudo systemctl enable velconnect` + - `sudo systemctl start velconnect` diff --git a/velconnect/docker-compose.yml b/velconnect/docker-compose.yml new file mode 100644 index 0000000..b3eed2a --- /dev/null +++ b/velconnect/docker-compose.yml @@ -0,0 +1,9 @@ +version: "1.0" +services: + web: + build: . + restart: always + ports: + - "8000:80" + volumes: + - ./db:/usr/src/velconnect/db diff --git a/velconnect/routes/api.py b/velconnect/routes/api.py index b23d48f..624e90f 100644 --- a/velconnect/routes/api.py +++ b/velconnect/routes/api.py @@ -12,7 +12,7 @@ from enum import Enum import db -db = db.DB("velconnect.db") +db = db.DB("db/velconnect.db") # APIRouter creates path operations for user module router = fastapi.APIRouter( diff --git a/velconnect/routes/user_count.py b/velconnect/routes/user_count.py index f51d0d9..5daa6b0 100644 --- a/velconnect/routes/user_count.py +++ b/velconnect/routes/user_count.py @@ -2,7 +2,7 @@ import fastapi import db -db = db.DB("velconnect.db") +db = db.DB("db/velconnect.db") # APIRouter creates path operations for user module router = fastapi.APIRouter(