diff --git a/Dockerfile b/Dockerfile index 4c7074d..cb39dc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index f8d63a9..2bd5123 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/atm_service.py b/atm_service.py index bfa2ad0..b4bec16 100644 --- a/atm_service.py +++ b/atm_service.py @@ -28,6 +28,7 @@ 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(): @@ -35,7 +36,7 @@ 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() diff --git a/docker-compose.yml b/docker-compose.yml index 3631de5..9a5ad4e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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"