Skip to content

Commit

Permalink
fix docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
euhoro committed Jun 18, 2024
1 parent f9353bd commit 48fbece
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ WORKDIR /app

RUN pip install -r requirements.txt

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
# Add curl installation
RUN apt-get update && apt-get install -y curl

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

# # Start the FastAPI app and run the curl command
# CMD uvicorn main:app --host 0.0.0.0 --port 80 & \
# sleep 3 && \
# curl -L -g -X GET 'http://127.0.0.1:8000/atm/maintenance' && \
# wait
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
./setup_and_run.sh
```

2. Access the application:
- [API Documentation](http://127.0.0.1:8000/docs)
- [Home](http://127.0.0.1:8000)

### On machine with docker

1. Make the setup script executable and run it
( python3.10 should be installed and in %PATH% ):
```bash
chmod +x setup_and_run.sh
./setup_and_run.sh
```

2. Access the application:
- [API Documentation](http://127.0.0.1:8000/docs)
- [Home](http://127.0.0.1:8000)
Expand Down Expand Up @@ -52,10 +39,21 @@
```bash
uvicorn main:app --reload
# alternative:
# alternative 1:
# Run with Redis
SETTINGS_MODE=redis docker-compose up --build
docker-compose up --build
3. Run to reload a full ATM`:
```bash
curl -L -g -X GET 'http://127.0.0.1:8000/atm/maintenance'
2. Access the application:
- [API Documentation](http://127.0.0.1:8000/docs)
- [Home](http://127.0.0.1:8000)
# alternative 2:
# Run with JSON file (for testing only - no real lock )
SETTINGS_MODE=text docker-compose up --build
3 changes: 2 additions & 1 deletion atm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
ERR_INSUFFICIENT_FUNDS = "Insufficient funds. Max available amount:"

SETTINGS_MODE = os.getenv("SETTINGS_MODE", "redis")
REDIS_HOST = os.getenv("REDIS_HOST", "127.0.0.1") # Default to 127.0.0.1 for local development


def get_db_service():

if SETTINGS_MODE == "redis":
import redis
inventory_service = RedisInventoryService(
redis.StrictRedis(host='localhost', port=6379, db=0))
redis.StrictRedis(host=REDIS_HOST, port=6379, db=0))
else:
from atm_service_json_file import JSONFileInventoryService
inventory_service = JSONFileInventoryService()
Expand Down
20 changes: 13 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
version: "3.8"

services:
redis:
image: "redis:latest"
container_name: redis_from_compose
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5

app:
build: .
container_name: fastapi_app
ports:
- "8000:80"
- "8000:8000"
environment:
- SETTINGS_MODE=${SETTINGS_MODE}
- REDIS_HOST=redis_from_compose
depends_on:
- redis

redis:
image: "redis:latest"
container_name: redis
ports:
- "6379:6379"

0 comments on commit 48fbece

Please sign in to comment.