diff --git a/.dockerignore b/.dockerignore index 13f1689..59b6df8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,3 +4,4 @@ !poetry.lock !pyproject.toml !README.md +!ContainerFile \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 4f989d4..6fd5dbb 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -3,6 +3,15 @@ name: Docker Build on: push jobs: - DockerBuild: - uses: openclimatefix/.github/.github/workflows/build-docker.yml@v1.8.2 \ No newline at end of file + name: Build docker + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build + run: docker build . -f ContainerFile --no-cache diff --git a/ContainerFile b/ContainerFile new file mode 100644 index 0000000..8fcc13e --- /dev/null +++ b/ContainerFile @@ -0,0 +1,31 @@ +FROM python:3.11-slim + +RUN apt-get update +RUN apt-get install -y git + +ENV PYTHONFAULTHANDLER=1 \ + PYTHONHASHSEED=random \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +RUN apt-get update +RUN apt-get install -y gdal-bin libgdal-dev g++ + +ENV PIP_DEFAULT_TIMEOUT=100 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_NO_CACHE_DIR=1 \ + POETRY_VERSION=1.7.1 + +RUN pip install "poetry==$POETRY_VERSION" + +COPY pyproject.toml poetry.lock README.md . +RUN poetry install --no-dev --no-root + +COPY india_forecast_app ./india_forecast_app +RUN poetry build +RUN poetry install + +COPY nwp.zarr ./nwp.zarr + +ENTRYPOINT ["poetry", "run" , "python3", "india_forecast_app/app.py", "--write-to-db"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index c07dab7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -FROM python:3.11-slim as base - -RUN apt-get update -RUN apt-get install -y git - -ENV PYTHONFAULTHANDLER=1 \ - PYTHONHASHSEED=random \ - PYTHONUNBUFFERED=1 - -WORKDIR /app - -FROM base as builder - -RUN apt-get update -RUN apt-get install -y gdal-bin libgdal-dev g++ - -ENV PIP_DEFAULT_TIMEOUT=100 \ - PIP_DISABLE_PIP_VERSION_CHECK=1 \ - PIP_NO_CACHE_DIR=1 \ - POETRY_VERSION=1.7.1 - -RUN pip install "poetry==$POETRY_VERSION" - -RUN python -m venv /venv - -RUN . /venv/bin/activate && pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu - -COPY pyproject.toml poetry.lock README.md . -RUN . /venv/bin/activate && poetry install --no-dev --no-root - -COPY india_forecast_app ./india_forecast_app -RUN . /venv/bin/activate && poetry build - -FROM base as final - -ENV PATH="/venv/bin:$PATH" - -COPY --from=builder /venv /venv -COPY --from=builder /app/dist . -COPY nwp.zarr ./nwp.zarr -RUN . /venv/bin/activate && pip install *.whl - -ENTRYPOINT ["app", "--write-to-db"] \ No newline at end of file diff --git a/india_forecast_app/app.py b/india_forecast_app/app.py index 7a5433d..b217510 100644 --- a/india_forecast_app/app.py +++ b/india_forecast_app/app.py @@ -15,7 +15,7 @@ from pvsite_datamodel.write import insert_forecast_values from sqlalchemy.orm import Session -from .models import DummyModel, PVNetModel +from india_forecast_app.models import DummyModel, PVNetModel log = logging.getLogger(__name__) @@ -60,6 +60,7 @@ def get_generation_data( # pad by 1 second to ensure get_pv_generation_by_sites returns correct data end = timestamp + dt.timedelta(seconds=1) + log.info(f'Getting generation data for sites: {site_uuids}, from {start=} to {end=}') generation_data = get_pv_generation_by_sites( session=db_session, site_uuids=site_uuids, start_utc=start, end_utc=end ) @@ -243,7 +244,10 @@ def app(timestamp: dt.datetime | None, write_to_db: bool, log_level: str): asset_sites = pv_sites if asset_type == "pv" else wind_sites if len(asset_sites) > 0: log.info(f"Reading latest historic {asset_type} generation data...") - generation_data = get_generation_data(session, asset_sites, timestamp) + if asset_type == "wind": + generation_data = get_generation_data(session, asset_sites, timestamp) + else: + generation_data = {"data": pd.DataFrame(), "metadata": pd.DataFrame()} log.info(f"Loading {asset_type} model...") models[asset_type] = get_model(asset_type, timestamp, generation_data) log.info(f"{asset_type} model loaded") diff --git a/poetry.lock b/poetry.lock index e908f75..d769939 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6916,4 +6916,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "f91b17343770adb25f34906d8737eb89792b536e5c204dba4bc1c79b1c8d9d5a" +content-hash = "177aa91a107b9db9ffb80c281b4c36dfa724275f23151972113a62d0df20be63"