diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3d2bf..1174b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v1.1.0] + ### Added - Added pre-commit configuration for linting and formatting [!6](https://github.com/dmidk/sunflow/pull/6), @khintz @@ -15,7 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Add .gitignore file and remove unnecessary files from the repository [!1](https://github.com/dmidk/sunflow/pull/1), @khintz +- Optimize container image size using multi-stage build and removing build-time dependencies [#9](https://github.com/dmidk/sunflow/pull/9), @khintz -## [1.0.0] +## [v1.0.0] Initial release of Sunflow. The application performs real-time or historical short-term solar irradiance nowcasting using probabilistic advection (via [SolarSTEPS](https://github.com/EnergyWeatherAI/SolarSTEPS)) with satellite data from KNMI MSG-CPP or DWD SIS. It supports local file, API download, and S3 run modes, produces CF-compliant NetCDF4 forecast files, and can be run as a container via Podman/Docker. diff --git a/ContainerFile b/ContainerFile index b5d2b1d..2b56d6a 100644 --- a/ContainerFile +++ b/ContainerFile @@ -1,10 +1,10 @@ -FROM python:3.12 +FROM python:3.12-slim-bookworm AS builder ENV DEBIAN_FRONTEND=noninteractive -# Install system dependencies including git and Python dev headers +# Install build-time dependencies only in the builder stage. RUN apt-get update -y && \ - apt-get install -y \ + apt-get install -y --no-install-recommends \ build-essential \ python3-dev \ libgeos-dev \ @@ -18,27 +18,52 @@ RUN apt-get update -y && \ curl && \ rm -rf /var/lib/apt/lists/* -# Set up container environment ENV USER_ID=1000 ENV GROUP_ID=1000 -# Install uv for fast dependency resolution and installation +# Install uv only in the builder stage. RUN curl -LsSf https://astral.sh/uv/install.sh | sh - ENV PATH="${PATH}:/root/.local/bin" -# Create application directories -RUN mkdir -p /data/nowcasts /data/satellite_data WORKDIR /project -# Copy project files COPY pyproject.toml /project/ COPY uv.lock /project/ COPY sunflow/ /project/sunflow/ COPY README.md /project/ COPY config.yaml /project/ -# Install project dependencies -RUN uv sync --frozen --no-dev +RUN uv sync --frozen --no-dev && \ + rm -rf /root/.cache/uv /root/.cache/pip + +FROM python:3.12-slim-bookworm + +ENV DEBIAN_FRONTEND=noninteractive + +# Install only the runtime shared libraries needed by the wheels. +RUN apt-get update -y && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + libgomp1 \ + libgeos-c1v5 \ + libproj25 \ + proj-data \ + proj-bin \ + libhdf5-103-1 \ + libnetcdf19 && \ + rm -rf /var/lib/apt/lists/* + +ENV USER_ID=1000 +ENV GROUP_ID=1000 +ENV VIRTUAL_ENV=/project/.venv +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" + +WORKDIR /project + +COPY --from=builder /project/.venv /project/.venv +COPY pyproject.toml /project/ +COPY sunflow/ /project/sunflow/ +COPY README.md /project/ +COPY config.yaml /project/ -ENTRYPOINT ["uv", "run", "python", "-m", "sunflow.main"] +ENTRYPOINT ["/project/.venv/bin/python", "-m", "sunflow.main"] diff --git a/pyproject.toml b/pyproject.toml index 43f92c9..57f5e34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dependencies = [ "isodate>=0.7.2", "fsspec>=2023.1.0", "s3fs>=2023.1.0", + "PyYAML>=6.0.2", ] requires-python = ">=3.12" readme = "README.md" diff --git a/uv.lock b/uv.lock index 0f30a1f..6e93b87 100644 --- a/uv.lock +++ b/uv.lock @@ -1599,6 +1599,7 @@ dependencies = [ { name = "opencv-python-headless" }, { name = "pvlib" }, { name = "pysteps" }, + { name = "pyyaml" }, { name = "requests" }, { name = "s3fs" }, { name = "solarsteps" }, @@ -1622,6 +1623,7 @@ requires-dist = [ { name = "opencv-python-headless", specifier = ">=4.5.0" }, { name = "pvlib", specifier = ">=0.10.0" }, { name = "pysteps", specifier = ">=1.7.0" }, + { name = "pyyaml", specifier = ">=6.0.2" }, { name = "requests", specifier = ">=2.31.0" }, { name = "s3fs", specifier = ">=2023.1.0" }, { name = "solarsteps", git = "https://github.com/dmidk/SolarSTEPS?rev=18012d7b11c56895e14abc39c3800f68a9a44ecb" },