-
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
42 additions
and
73 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,39 @@ | ||
FROM python:3.12-slim | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
libfreetype6-dev \ | ||
libpng-dev \ | ||
pkg-config \ | ||
sudo \ | ||
git \ | ||
ffmpeg \ | ||
procps \ | ||
libhdf5-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --upgrade pip setuptools wheel | ||
# Use Miniconda as the base image | ||
FROM continuumio/miniconda3:latest | ||
|
||
COPY requirements.txt . | ||
RUN pip install -r requirements.txt | ||
# Set shell | ||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
|
||
# Set environment variables for PROJ | ||
ENV PROJ_LIB=/usr/share/proj | ||
ENV PROJ_DIR=/usr | ||
ENV PATH="/opt/conda/bin:$PATH" | ||
|
||
COPY app.py /app/app.py | ||
COPY main.py /app/main.py | ||
# Set work directory | ||
WORKDIR /app | ||
|
||
EXPOSE 5002 | ||
# Run the application | ||
CMD ["python", "app.py"] | ||
# Copy requirements file | ||
COPY requirements.txt . | ||
|
||
# Create and activate a Conda environment, then install Python dependencies | ||
RUN conda update -n base -c defaults conda && \ | ||
conda create -n myenv python=3.12 && \ | ||
echo "source activate myenv" > ~/.bashrc && \ | ||
/bin/bash -c "source activate myenv" && \ | ||
conda install -y -n myenv -c conda-forge hdf5 netcdf4 proj gdal geos && \ | ||
/bin/bash -c "source activate myenv" && \ | ||
pip install --upgrade pip && \ | ||
pip install --no-cache-dir -r requirements.txt | ||
|
||
# Install Gunicorn in the Conda environment | ||
RUN /bin/bash -c "source activate myenv" && pip install gunicorn | ||
|
||
# Copy the rest of your application files | ||
COPY . . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 5001 | ||
|
||
# Run the application using Gunicorn with stdout/stderr logging | ||
CMD ["/bin/bash", "-c", "source activate myenv && exec gunicorn -w 4 -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.