From 5f2f64c5a6b13f28e9be37eadf8f92312a4e8835 Mon Sep 17 00:00:00 2001 From: Aryan Bhosale <36108149+aryanbhosale@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:58:07 +0530 Subject: [PATCH] dockerise (#182) * dockerise * Update docker-compose.yaml * Create Dockerfile --- Dockerfile | 23 +++++++++++++++++++++++ api/main.py | 2 +- docker-compose.yaml | 21 ++++++++++++++++++--- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..1272cf3c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use an official Python runtime as a parent image +FROM python:3.11-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements.txt file +COPY requirements.txt . + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the entire project directory (including quartz_solar_forecast) +COPY . /app + +# Install the quartz_solar_forecast package in editable mode +RUN pip install -e . + +# Expose port 8000 to the outside world +EXPOSE 8000 + +# Run the application using python main.py +CMD ["python", "api/main.py"] diff --git a/api/main.py b/api/main.py index a3151bf3..37c772d8 100644 --- a/api/main.py +++ b/api/main.py @@ -1,4 +1,4 @@ import uvicorn if __name__ == "__main__": - uvicorn.run("app.api:app", host="localhost", port=8000, reload=True) \ No newline at end of file + uvicorn.run("app.api:app", host="0.0.0.0", port=8000, reload=True) diff --git a/docker-compose.yaml b/docker-compose.yaml index 1e2e7756..59cf7ea9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '3.8' - x-shared_environment: &shared_environment LOG_LEVEL: ${LOG_LEVEL:-info} @@ -15,6 +13,7 @@ services: restart: always environment: <<: *shared_environment + open-meteo-sync: image: ghcr.io/open-meteo/open-meteo container_name: open-meteo-sync @@ -25,5 +24,21 @@ services: environment: <<: *shared_environment + web: + build: + context: . + dockerfile: Dockerfile + container_name: fastapi-app + ports: + - "8000:8000" + env_file: + - .env + volumes: + - .:/app + depends_on: + - open-meteo-api + - open-meteo-sync + restart: always + volumes: - data: \ No newline at end of file + data: