Skip to content

Commit

Permalink
開発環境と本番環境の切り替え実装[#34]
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-harutaro committed Jul 30, 2024
1 parent 4a72cdd commit 47d822e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ cd futarin-api
3. Create `.env` file
```
touch .env
# default 0(prod)
echo "DEV_MODE=1"
echo "VOICEVOX_API_KEY=[voicevox api key]" >> .env
echo "VOICEVOX_URL=[endpoint url]" >> .env
echo "OPENAI_API_KEY=[openAI api key]" >> .env
# Only production mode (NOT DEV_MODE=1)
# Only production mode(開発環境用)
echo "STORAGE_ACCOUNT_NAME=[azure storage-account-name]" >> .env
echo "SAS_TOKEN=[azure storage-account SAS token]" >> .env
```
Expand All @@ -41,8 +37,12 @@ sudo docker compose build

5. Build and Start image
```
# Production(本番環境)
sudo docker compose up
sudo docker compose up -d # detach
# Development(開発環境)
sudo docker compose -f docker-compose.yml -f docker-compose.dev.yml up
# Detachモード
sudo docker compose up -d
```
6. access to localhost to check docs
http://localhost/docs
Expand Down Expand Up @@ -76,10 +76,12 @@ http://localhost/docs
│   │   ├── voicevox.py
│   │   ├── voicevox_api.py
│   │   └── whisper.py
│   ├── uploads
│   └── utils
│   ├── __init__.py
│   ├── config.py
│   └── log.py
├── docker-compose.dev.yml
└── docker-compose.yml
```

Expand Down
4 changes: 2 additions & 2 deletions api/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def check_env_variables():
raise EnvironmentError(f"Missing environment variables: {', '.join(missing_vars)}")

def get_is_dev_mode() -> bool:
IS_DEV = os.getenv("DEV_MODE")
return True if IS_DEV==1 else False
is_dev_mode = os.getenv("IS_DEV_MODE")
return int(is_dev_mode)==1

def get_voicevox_url():
return os.getenv("VOICEVOX_URL")
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
api:
environment:
- IS_DEV_MODE=1
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
api:
container_name: api
image: futarin-api
environment:
- IS_DEV_MODE=0
env_file:
- .env
build:
Expand Down

0 comments on commit 47d822e

Please sign in to comment.