-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move Flask application to production-grade Gunicorn WSGI server
- Add-on `dwd_global_rad_server_dev`: Migrated from Flask development server to Gunicorn WSGI server for production use. - Updated Dockerfile to install and configure Gunicorn. - Configured Gunicorn to log to stdout/stderr to ensure logs are captured by Docker. - Retained existing logging setup within `app.py` for consistency.
- Loading branch information
Showing
6 changed files
with
62 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,64 @@ | ||
FROM python:3.12-slim | ||
# Stage 1: Build Stage | ||
FROM continuumio/miniconda3:latest AS builder | ||
|
||
# Set environment variables for PROJ | ||
ENV PROJ_LIB=/usr/share/proj | ||
ENV PROJ_DIR=/usr | ||
ENV PATH="/opt/conda/bin:$PATH" | ||
|
||
# Set work directory | ||
WORKDIR /app | ||
|
||
# Install system dependencies and clean up APT lists | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
libfreetype6-dev \ | ||
libpng-dev \ | ||
pkg-config \ | ||
sudo \ | ||
git \ | ||
ffmpeg \ | ||
procps \ | ||
libhdf5-dev \ | ||
gcc \ | ||
g++ \ | ||
ncdu \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --upgrade pip setuptools wheel | ||
|
||
# Copy requirements file | ||
COPY requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
COPY app.py /app/app.py | ||
COPY main.py /app/main.py | ||
# Update Conda, create environment, install packages, and clean up caches | ||
RUN conda update -n base -c defaults conda && \ | ||
conda install -y -c conda-forge python=3.12 hdf5 netcdf4 proj gdal geos && \ | ||
pip install --upgrade pip && \ | ||
pip install --no-cache-dir -r requirements.txt && \ | ||
conda clean --all -y && \ | ||
pip cache purge && \ | ||
rm -rf /opt/conda/pkgs | ||
|
||
# Install Gunicorn in the base Conda environment | ||
RUN pip install gunicorn | ||
|
||
# Copy the rest of your application files | ||
COPY . . | ||
|
||
# Stage 2: Final Stage | ||
FROM continuumio/miniconda3:latest | ||
|
||
# Set environment variables for PROJ | ||
ENV PROJ_LIB=/usr/share/proj | ||
ENV PROJ_DIR=/usr | ||
ENV PATH="/opt/conda/bin:$PATH" | ||
|
||
# Set work directory | ||
WORKDIR /app | ||
|
||
EXPOSE 5002 | ||
# Run the application | ||
CMD ["python", "app.py"] | ||
# Copy the environment from the build stage | ||
COPY --from=builder /opt/conda /opt/conda | ||
|
||
# Copy application files | ||
COPY --from=builder /app /app | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 5001 | ||
|
||
# Run the application using Gunicorn with stdout/stderr logging | ||
CMD ["gunicorn", "--workers", "1", "--threads", "1", "-b", "0.0.0.0:5001", "--capture-output", "--access-logfile", "-", "--error-logfile", "-", "app:app"] | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
matplotlib | ||
cartopy | ||
numpy==2.0.0 | ||
numpy<2 | ||
xarray | ||
netCDF4==1.7.0 | ||
netCDF4 | ||
flask | ||
requests | ||
dwd_global_radiation | ||
|
4 changes: 0 additions & 4 deletions
4
dwd_global_rad_api_server_dev/services.d/dwd_global_rad_api_server/finish
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
dwd_global_rad_api_server_dev/services.d/dwd_global_rad_api_server/run
This file was deleted.
Oops, something went wrong.