Skip to content

Commit

Permalink
updated docker
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanbhosale committed Sep 14, 2024
1 parent f749532 commit 46f3722
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Base URL for the API
FASTAPI_BASE_URL = 1. With Docker: "http://web:8000", 2. Local: "http://localhost:8000"
LOG_LEVEL = "info"

# User needs to add their Enphase API details
ENPHASE_SYSTEM_ID = 'user_enphase_system_id'
ENPHASE_CLIENT_ID = 'user_enphase_client_id'
Expand Down
28 changes: 20 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app

# Copy the entire project directory (including quartz_solar_forecast)
COPY . /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*

# Copy the pyproject.toml file
COPY pyproject.toml .

# Install the project and its dependencies
RUN pip install --no-cache-dir .

# Install the quartz_solar_forecast package in editable mode
RUN pip install -e .
# Install wait-for-it script
ADD https://github.com/vishnubob/wait-for-it/raw/master/wait-for-it.sh /usr/local/bin/wait-for-it
RUN chmod +x /usr/local/bin/wait-for-it

# Copy the entire project directory
COPY . /app

# Expose port 8000 to the outside world
EXPOSE 8000
# Expose ports 8000 (API) and 8501 (Streamlit) to the outside world
EXPOSE 8000 8501

# Run the application using python main.py
CMD ["python", "api/main.py"]
# The CMD will be provided by docker-compose.yml
CMD ["sh", "-c", "wait-for-it open-meteo-api:8080 -- $CMD"]
4 changes: 4 additions & 0 deletions api/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
allow_headers=["*"]
)

@app.get("/health")
async def root():
return {"status": "ok"}

@app.post("/forecast/")
def forecast(forecast_request: ForecastRequest):
site = forecast_request.site
Expand Down
2 changes: 1 addition & 1 deletion dashboards/dashboard_2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
st.session_state.redirect_url = ""

# Set up the base URL for the FastAPI server
FASTAPI_BASE_URL = "http://localhost:8000"
FASTAPI_BASE_URL = os.getenv("FASTAPI_BASE_URL")

# Get the directory of the current script
script_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
38 changes: 30 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
x-shared_environment: &shared_environment
LOG_LEVEL: ${LOG_LEVEL:-info}
LOG_LEVEL: ${LOG_LEVEL}

services:
open-meteo-api:
Expand Down Expand Up @@ -28,17 +28,39 @@ services:
build:
context: .
dockerfile: Dockerfile
container_name: fastapi-app
container_name: quartz-solar-forecast-api
ports:
- "8000:8000"
env_file:
- .env
volumes:
- .:/app
depends_on:
- open-meteo-api
- open-meteo-sync
restart: always
environment:
- LOG_LEVEL=${LOG_LEVEL}
command: python api/main.py
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s

streamlit:
build:
context: .
dockerfile: Dockerfile
container_name: quartz-solar-forecast-frontend
ports:
- "8501:8501"
volumes:
- .:/app
restart: always
environment:
- LOG_LEVEL=${LOG_LEVEL}
- FASTAPI_BASE_URL=${FASTAPI_BASE_URL}
command: streamlit run dashboards/dashboard_2/app.py
depends_on:
web:
condition: service_healthy

volumes:
data:
data:

0 comments on commit 46f3722

Please sign in to comment.