Skip to content

Commit

Permalink
Issue/cleaner docker (#22)
Browse files Browse the repository at this point in the history
* update lock file

* make docker more simple

* remove cpu only

* tidy

* remove venv

* update entrypoint

* fix docker (runs locally)

* update generation data for pv

* update work flow

* fix

* update github workflow

* add logging

* tidy up

* remove "as base" from docker file

* no-cache

* ContainerFile

* include ContainerFile

* remove main ref

* use v1 docker buildx

* remove docker file
  • Loading branch information
peterdudfield authored Feb 26, 2024
1 parent 7dcd777 commit dc6ab1d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 48 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
!poetry.lock
!pyproject.toml
!README.md
!ContainerFile
13 changes: 11 additions & 2 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: Docker Build
on: push

jobs:

DockerBuild:
uses: openclimatefix/.github/.github/workflows/[email protected]
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
31 changes: 31 additions & 0 deletions ContainerFile
Original file line number Diff line number Diff line change
@@ -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"]
43 changes: 0 additions & 43 deletions Dockerfile

This file was deleted.

8 changes: 6 additions & 2 deletions india_forecast_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc6ab1d

Please sign in to comment.