Skip to content

Commit

Permalink
Merge pull request #26 from ainize-team/feature/donghoon/use-docker-c…
Browse files Browse the repository at this point in the history
…ompose

Feature/donghoon/use docker compose
  • Loading branch information
DHBaek authored Jun 27, 2023
2 parents f3d510b + 4f31d70 commit 5f48446
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .env.sample

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COPY ./src/ /app/

EXPOSE 8000

COPY ./start.sh /app/start.sh
COPY ./scripts/start.sh /app/start.sh
RUN chmod +x /app/start.sh

CMD ./start.sh
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,55 @@
# TTI-FastAPI

Serving Text to Image Model Using FastAPI and Celery
Serving Text to Image Model Using FastAPI, RabbitMQ and Celery worker

## Installation
1. build docker image
## How to start
### Using docker-compose(recommended)
1. Clone repository
```shell
git clone https://github.com/ainize-team/TTI-FastAPI
cd TTI-FastAPI
docker build -t tti-fast-api .
```

2. Run Docker Image
2. Edit [docker-compose.yml](./docker-compose.yml), [rabbitmq.env](./envs/rabbimq.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 tti-rabbitmq -it /bin/bash
cd scripts
./init_rabbitmq
```

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

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

3. Create docker container
```
docker run -d --name tti-fastapi -p 8000:8000 \
-e BROKER_URI=<broker_uri> \
-e FIREBASE_DATABASE_URL=<firebase_realtime_database_url> \
-v <firebase_credential_dir_path>:/app/key tti-fastapi
```

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

```shell
docker build -t tti-fast-api .
docker build -t tti-fastapi .
docker run -d --name tti-fastapi -p 8000:8000 \
--env-file {.env_file_path} \
--env-file .env \
-v <firebase_credential_dir_path>:/app/key tti-fastapi
```

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: tti-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: tti-api
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
4 changes: 4 additions & 0 deletions envs/fastapi.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APP_NAME="Stable Diffusion FastAPI Dev Server"
BROKER_BASE_URI=amqp://<user_name>:<password>@<rabbitmq_container_name>:5672
FIREBASE_DATABASE_URL=<firebase_realtime_database_url>
FIREBASE_APP_NAME=text-to-art
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
File renamed without changes.

0 comments on commit 5f48446

Please sign in to comment.