Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/donghoon/add docker compose #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .env.sample

This file was deleted.

44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,60 @@

FastAPI Server for Super Resolution Model.

## Installation
## How to start
### Using docker-compose(recommended)
1. Clone repository
```shell
git clone https://github.com/ainize-team/SR-FastAPI
cd SR-FastAPI
```

1. Build FastAPI Docker Image
2. Edit [docker-compose.yml](./docker-compose.yml), [rabbitmq.env](./envs/rabbitmq.env.sample) and [fastapi.env](./envs/fastapi.env.sample) for your project.

3. Run containers
```shell
docker-compose up -d
```

4. (Optional) config rabbimq user setting
```shell
docker exec sr-rabbitmq -it /bin/bash
cd scripts
./init_rabbitmq
```

### Using docker
1. Clone repository
```shell
git clone https://github.com/ainize-team/SR-FastAPI
cd SR-FastAPI
```

2. Build docker image
```shell
docker build -t sr-fastapi .
```

2. Run Docker Image
3. Create docker container

```shell
docker run -d --name <server_container_name> -p 8000:8000 \
-e APP_NAME=<server_app_name> \
-e BROKER_URI=<broker_uri> \
-e FIREBASE_APP_NAME=<firebase_app_name> \
-e DATABASE_URL=<firebase_realtime_database_url> \
-e STORAGE_BUCKET=<firebase_storage_url> \
-e FIREBASE_DATABASE_URL=<firebase_realtime_database_url> \
-e FIREBASE_STORAGE_BUCKET=<firebase_storage_url> \
-v <firebase_credential_path>:/app/key \
sr-fastapi
```

Or, you can use the .env file to run as follows.
Or, you can use the [.env file](./envs/fastapi.env.sample) to run as follows.

```shell
docker run -d --name <server_container_name> -p 8000:8000 \
--env-file <env filename> \
-v <firebase_credential_path>:/app/key \
sr-fastapi
docker build -t sr-fastapi .
docker run -d --name sr-fastapi -p 8000:8000 \
--env-file .env \
-v <firebase_credential_dir_path>:/app/key sr-fastapi
```

## For Developers
Expand Down
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3'

services:
rabbitmq:
image: rabbitmq:3.11.2-management
container_name: sr-rabbitmq
ports:
- 5672:5672
- 15672:15672
env_file:
- ./envs/rabbitmq.env
volumes:
- ./scripts/init_rabbitmq.sh:/scripts/init_rabbitmq.sh
networks:
- dev
restart: unless-stopped

api-server:
build:
context: .
dockerfile: Dockerfile
container_name: sr-fastapi
ports:
- 8000:8000
env_file:
- ./envs/fastapi.env
volumes:
- <firebase_credential_dir_path>:/app/key/
networks:
- dev
restart: unless-stopped
depends_on:
- rabbitmq

networks:
dev:
driver: bridge
5 changes: 5 additions & 0 deletions envs/fastapi.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
APP_NAME="Super Resolution FastAPI Dev Server"
BROKER_URI=amqp://<user_name>:<password>@<rabbitmq_container_name>:5672/<rabbitmq_vhost_name>
FIREBASE_DATABASE_URL=<firebase_realtime_database_url>
FIREBASE_STORAGE_BUCKET=<firebase_storage_url>
FIREBASE_APP_NAME=super-resolution
3 changes: 3 additions & 0 deletions envs/rabbitmq.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RABBITMQ_DEFAULT_USER=<rabbitmq_default_user>
RABBITMQ_DEFAULT_PASS=<rabbitmq_default_password>
RABBITMQ_VHOSTS=vhost1,vhost2
17 changes: 17 additions & 0 deletions scripts/init_rabbitmq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

echo "Init Rabbitmq config..."

USER=$RABBITMQ_DEFAULT_USER
VHOSTS=$RABBITMQ_VHOSTS

# Split the vhosts into an array using a comma (,) as the delimiter.
IFS=',' read -ra VHOST_ARRAY <<< "$VHOSTS"

echo ${VHOST_ARRAY}

for vhost in "${VHOST_ARRAY[@]}"
do
rabbitmqctl add_vhost $vhost
rabbitmqctl set_permissions -p $vhost $USER ".*" ".*" ".*"
done
2 changes: 1 addition & 1 deletion src/event_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _setup_firebase() -> None:
cred = credentials.Certificate(firebase_settings.cred_path)
firebase_admin.initialize_app(
cred,
{"databaseURL": firebase_settings.database_url, "storageBucket": firebase_settings.storage_bucket},
{"databaseURL": firebase_settings.firebase_database_url, "storageBucket": firebase_settings.firebase_storage_bucket},
)


Expand Down
4 changes: 2 additions & 2 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class CelerySettings(BaseSettings):
class FirebaseSettings(BaseSettings):
firebase_app_name: str = "super-resolution"
cred_path: str = "./key/serviceAccountKey.json"
database_url: str
storage_bucket: str
firebase_database_url: str
firebase_storage_bucket: str


server_settings = ServerSettings()
Expand Down
Loading