-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #624 from wri/differently_named_uv_branch
Introduce UV to replace Pipenv; multi-stage Dockerfile (new PR)
- Loading branch information
Showing
12 changed files
with
3,375 additions
and
3,623 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
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,43 +1,98 @@ | ||
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim | ||
ARG ENV | ||
ARG PYTHON_VERSION="3.10" | ||
ARG USR_LOCAL_BIN=/usr/local/bin | ||
ARG UV_VERSION="0.5.24" | ||
ARG VENV_DIR=/app/.venv | ||
|
||
# Comment to trigger an image rebuild | ||
FROM ubuntu:noble AS build | ||
|
||
# Optional build argument for different environments | ||
ARG ENV | ||
ARG PYTHON_VERSION | ||
ARG USR_LOCAL_BIN | ||
ARG VENV_DIR | ||
|
||
RUN apt-get update -y \ | ||
&& apt-get install --no-install-recommends -y gcc g++ libc-dev \ | ||
postgresql-client libpq-dev make git jq libgdal-dev \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
RUN apt-get update -qy && \ | ||
apt-get install -qyy \ | ||
-o APT::Install-Recommends=false \ | ||
-o APT::Install-Suggests=false \ | ||
ca-certificates \ | ||
clang \ | ||
curl \ | ||
gcc \ | ||
git \ | ||
libgdal-dev \ | ||
libpq-dev \ | ||
make | ||
|
||
RUN pip install --upgrade pip && pip install pipenv==2024.0.1 | ||
#TODO move to pipfile when operational | ||
RUN pip install newrelic | ||
# Set uv env variables for behavior and venv directory | ||
ENV PATH=${USR_LOCAL_BIN}:${PATH} \ | ||
UV_LINK_MODE=copy \ | ||
UV_COMPILE_BYTECODE=1 \ | ||
UV_PROJECT_ENVIRONMENT=${VENV_DIR} \ | ||
UV_UNMANAGED_INSTALL=${USR_LOCAL_BIN} | ||
|
||
# Install python dependencies | ||
# Install everything for dev and test otherwise just core dependencies | ||
COPY Pipfile Pipfile | ||
COPY Pipfile.lock Pipfile.lock | ||
# Create a virtual environment with uv inside the container | ||
RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh && \ | ||
uv venv ${VENV_DIR} --python ${PYTHON_VERSION} --seed | ||
|
||
# Copy pyproject.toml and uv.lock to a temporary directory and install | ||
# dependencies into the venv | ||
COPY pyproject.toml /_lock/ | ||
COPY uv.lock /_lock/ | ||
RUN if [ "$ENV" = "dev" ] || [ "$ENV" = "test" ]; then \ | ||
echo "Install all dependencies" \ | ||
&& pipenv install --system --deploy --ignore-pipfile --dev; \ | ||
echo "Install all dependencies" && \ | ||
cd /_lock && \ | ||
uv sync --locked --no-install-project --dev; \ | ||
else \ | ||
echo "Install production dependencies only" \ | ||
&& pipenv install --system --deploy; \ | ||
echo "Install production dependencies only" && \ | ||
cd /_lock && \ | ||
uv sync --locked --no-install-project --no-dev; \ | ||
fi | ||
|
||
COPY ./app /app/app | ||
|
||
COPY alembic.ini /app/alembic.ini | ||
# Start the runtime stage | ||
FROM ubuntu:noble | ||
|
||
ARG USR_LOCAL_BIN | ||
ARG VENV_DIR | ||
|
||
SHELL ["sh", "-exc"] | ||
|
||
ENV PATH=${VENV_DIR}/bin:${USR_LOCAL_BIN}:${PATH} | ||
ENV TZ=UTC | ||
ENV VENV_DIR=${VENV_DIR} | ||
|
||
RUN echo $TZ > /etc/timezone | ||
|
||
RUN apt-get update -qy && \ | ||
apt-get install -qyy \ | ||
-o APT::Install-Recommends=false \ | ||
-o APT::Install-Suggests=false \ | ||
expat \ | ||
jq \ | ||
libgdal-dev \ | ||
postgresql-client && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists && \ | ||
rm -rf /var/cache/apt | ||
|
||
COPY --chmod=777 wait_for_postgres.sh /usr/local/bin/wait_for_postgres.sh | ||
|
||
# Set the entry point and signal handling | ||
ENTRYPOINT [ "/app/start.sh" ] | ||
STOPSIGNAL SIGINT | ||
|
||
# Copy the pre-built `/app` directory from the build stage | ||
COPY --from=build --chmod=777 /app /app | ||
COPY --from=build --chmod=777 /root /root | ||
|
||
COPY app/settings/prestart.sh /app/prestart.sh | ||
COPY app/settings/start.sh /app/start.sh | ||
COPY newrelic.ini /app/newrelic.ini | ||
COPY alembic.ini /app/alembic.ini | ||
|
||
COPY --chmod=777 app/settings/gunicorn_conf.py /app/gunicorn_conf.py | ||
COPY --chmod=777 app/settings/prestart.sh /app/prestart.sh | ||
COPY --chmod=777 app/settings/start.sh /app/start.sh | ||
|
||
COPY wait_for_postgres.sh /usr/local/bin/wait_for_postgres.sh | ||
RUN chmod +x /usr/local/bin/wait_for_postgres.sh | ||
RUN chmod +x /app/start.sh | ||
COPY ./app /app/app | ||
|
||
ENTRYPOINT [ "/app/start.sh" ] | ||
WORKDIR /app |
Oops, something went wrong.