Skip to content

Commit

Permalink
updates Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Jan 10, 2025
1 parent f90b85f commit bd98f1f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
54 changes: 32 additions & 22 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update \
locales-all \
nginx \
postgresql-client \
postgresql-client-15 \
python3-gdal \
python3-psycopg2 \
&& locale-gen --no-purge uk_UA.UTF-8 \
Expand Down Expand Up @@ -53,41 +54,51 @@ LABEL distro="tests"
LABEL org.opencontainers.image.created="$BUILD_DATE"
LABEL org.opencontainers.image.version="$VERSION"

ENV PATH=/app/.venv/bin:/usr/local/bin/:/usr/bin:/bin \
ENV PATH=/venv/bin:/usr/local/bin/:/usr/bin:/bin \
DJANGO_SETTINGS_MODULE=aurora.config.settings \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=""\
UV_PROJECT_ENVIRONMENT=/venv \
VIRTUAL_ENV=/venv \
UWSGI_PROCESSES=4

WORKDIR /app
ADD uv.lock README.md MANIFEST.in pyproject.toml /app/
ADD src /app/src/

RUN --mount=type=cache,target=/root/.uv-cache \
--mount=type=bind,source=uv.lock,target=/app/uv.lock \
--mount=type=bind,source=pyproject.toml,target=/app/pyproject.toml \
--mount=type=bind,source=MANIFEST.in,target=/app/MANIFEST.in \
--mount=type=bind,source=./src/aurora,target=/app/src/aurora \
--mount=type=bind,source=./src/dbtemplates,target=/app/src/dbtemplates \
uv sync --cache-dir=/root/.uv-cache --no-editable --frozen --extra distribution
uv sync --cache-dir=/root/.uv-cache \
--python=/usr/local/bin/python \
--python-preference=system \
--frozen

# ------- production only deps-------
FROM builder AS production

WORKDIR /app
COPY uv.lock README.md MANIFEST.in pyproject.toml /app/
COPY src /app/src/
ENV PATH=/venv/bin:/usr/local/bin/:/usr/bin:/bin \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=""\
UV_PROJECT_ENVIRONMENT=/venv \
VIRTUAL_ENV=/venv

RUN --mount=type=cache,target=/root/.uv-cache \
uv sync --cache-dir=/root/.uv-cache \
--python=/usr/local/bin/python \
--python-preference=system \
--no-dev --no-editable --frozen --extra distribution
--no-dev --no-editable --frozen


FROM base AS dist
ARG BUILD_DATE
ARG VERSION
ARG GIT_SHA

ENV PATH=/app/.venv/bin:/usr/local/bin/:/usr/bin:/bin:/usr/sbin/:/usr/local/sbin/ \
ENV PATH=/venv/bin:/usr/local/bin/:/usr/bin:/bin:/usr/sbin/:/usr/local/sbin/ \
BUILD_DATE="${BUILD_DATE}" \
DJANGO_SETTINGS_MODULE=aurora.config.settings \
GIT_SHA="${GIT_SHA}" \
Expand All @@ -99,25 +110,24 @@ ENV PATH=/app/.venv/bin:/usr/local/bin/:/usr/bin:/bin:/usr/sbin/:/usr/local/sbin
STATIC_ROOT=/var/aurora/static/ \
STATIC_URL="/static/" \
UWSGI_PROCESSES=4 \
UV_PROJECT_ENVIRONMENT=/venv \
VIRTUAL_ENV=/venv \
VERSION="${VERSION}"


WORKDIR app/
WORKDIR /app
ADD docker/conf /conf/
ADD docker/bin/* /usr/local/bin/

ADD uv.lock README.md MANIFEST.in pyproject.toml /app/
ADD src /app/src/

COPY docker/conf /conf/
COPY docker/bin/* /usr/local/bin/
COPY LICENSE README.md /
COPY --from=production /app/.venv /app/.venv
COPY --from=builder /usr/local/bin/uv /usr/local/bin/
COPY --from=production /venv /venv
COPY --from=builder /usr/local/bin/uwsgi /usr/local/bin/uv /usr/local/bin/

RUN --mount=type=cache,target=/root/.uv-cache \
--mount=type=bind,source=uv.lock,target=/app/uv.lock \
--mount=type=bind,source=pyproject.toml,target=/app/pyproject.toml \
--mount=type=bind,source=MANIFEST.in,target=/app/MANIFEST.in \
--mount=type=bind,source=README.md,target=/app/README.md \
--mount=type=bind,source=./src/aurora,target=/app/src/aurora \
--mount=type=bind,source=./src/dbtemplates,target=/app/src/dbtemplates \
uv --cache-dir=/root/.uv-cache pip install --no-deps .
uv --cache-dir=/root/.uv-cache pip install --no-deps . \
&& rm -fr /app/*


EXPOSE 8000
Expand Down
14 changes: 11 additions & 3 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ TAG?=${VERSION}

.build:
DOCKER_BUILDKIT=1 cd .. && docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=${BUILD_DATE} \
--build-arg GIT_SHA=${SOURCE_COMMIT} \
--cache-from ${DOCKER_IMAGE_NAME}:${VERSION}-base \
--cache-from ${DOCKER_IMAGE_NAME}:${VERSION}-builder \
--cache-from ${DOCKER_IMAGE_NAME}:${VERSION}-production \
--cache-to type=inline,mode=max \
--target ${STAGE} \
--no-cache \
${BUILD_OPTIONS} \
-t ${DOCKER_IMAGE} \
-f docker/Dockerfile .
Expand All @@ -35,6 +39,9 @@ builder:
STAGE=builder $(MAKE) .build-stage


tests:
STAGE=tests $(MAKE) .build-stage

production:
STAGE=production $(MAKE) .build-stage

Expand All @@ -44,8 +51,9 @@ dist:

step1: base
step2: builder
step3: production
step4: dist
step3: tests
step4: production
step5: dist

.run:
cd .. && docker run \
Expand Down
2 changes: 1 addition & 1 deletion docker/conf/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[uwsgi]

http-socket=0.0.0.0:8888
env=PYTHONPATH=/code/src/:/code/__pypackages__/3.12/lib
virtualenv=/venv
enable-threads=0
honour-range=1
master=1
Expand Down

0 comments on commit bd98f1f

Please sign in to comment.