Skip to content

Commit b5e1447

Browse files
committed
Replaced pip with uv
1 parent 6366d43 commit b5e1447

File tree

6 files changed

+178
-20
lines changed

6 files changed

+178
-20
lines changed

.diploi/helm/app.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ spec:
3838
- name: install-dependencies
3939
image: {{ .Values.images.app }}
4040
imagePullPolicy: Always
41-
command: ['pip3', 'install', '-r', 'requirements.txt','--no-cache-dir']
41+
command: ["/bin/sh", "-c"]
42+
args:
43+
- |
44+
uv sync --frozen --no-cache --link-mode=copy && \
45+
cp --remove-destination "$(readlink /app{{ .Values.folder }}/.venv/bin/python)" /app{{ .Values.folder }}/.venv/bin/python 2>/dev/null || :
4246
workingDir: /app{{ .Values.folder }}
4347
env:
4448
- name: DJANGO_ENV

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

Dockerfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
FROM python:3.13-alpine AS base
1+
FROM ghcr.io/astral-sh/uv:python3.13-alpine AS base
22

33
ARG FOLDER=/app
44

55
WORKDIR ${FOLDER}
66

7+
ENV UV_COMPILE_BYTECODE=1
8+
ENV UV_LINK_MODE=copy
9+
ENV UV_TOOL_BIN_DIR=/usr/local/bin
10+
11+
712
COPY . /app
13+
RUN uv sync --locked --no-dev --group deploy
14+
15+
ENV PATH="$FOLDER/.venv/bin:$PATH"
816

9-
RUN pip3 wheel --no-cache-dir --no-deps -r requirements.txt -w /wheels
1017

1118
FROM base AS release
1219

@@ -17,21 +24,16 @@ RUN apk add --no-cache shadow
1724
RUN groupadd -g 1000 devgroup && \
1825
useradd -u 1000 -g 1000 -m devuser
1926

20-
COPY --from=base /wheels /wheels
21-
22-
RUN chown -R devuser:devgroup /wheels
23-
24-
RUN pip3 install gunicorn --no-cache /wheels/*
25-
2627
RUN chown -R devuser:devgroup /app
2728

28-
RUN python3 manage.py collectstatic --noinput
29+
RUN uv run --locked --no-dev python manage.py collectstatic --noinput
2930

3031
USER devuser
3132

33+
ENTRYPOINT []
34+
3235
EXPOSE 8000
36+
ENV PORT=8000
37+
ENV HOST="0.0.0.0"
3338

34-
CMD ["gunicorn", "djangoapp.wsgi:application", \
35-
"--bind", "0.0.0.0:8000", \
36-
"--workers", "3", \
37-
"--log-level", "info"]
39+
CMD ["uv","run","gunicorn","djangoapp.wsgi:application","--bind", "0.0.0.0:8000","--workers", "3", "--log-level", "info"]

Dockerfile.dev

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
FROM python:3.13-alpine AS base
1+
FROM ghcr.io/astral-sh/uv:python3.13-alpine as BASE
22

33
ARG FOLDER=/app
44

55
WORKDIR ${FOLDER}
66

7-
RUN apk add --no-cache shadow
7+
ENV UV_COMPILE_BYTECODE=1
8+
ENV UV_TOOL_BIN_DIR=/usr/local/bin
9+
ENV UV_PROJECT_ENVIRONMENT="${FOLDER}/.venv"
10+
ENV PATH="${FOLDER}/.venv/bin:${PATH}"
11+
12+
RUN apk add --no-cache shadow \
13+
&& apk add --no-cache nodejs npm \
14+
&& npm install -g nodemon
815

916
RUN groupadd -g 1000 devgroup && \
1017
useradd -u 1000 -g 1000 -m devuser
1118

1219
COPY . /app
1320

21+
RUN mkdir -p /.cache/uv && chown devuser:devgroup -R /.cache /.cache/uv
22+
1423
RUN chown -R devuser:devgroup /app
1524

16-
RUN pip3 install -r requirements.txt --no-cache-dir
25+
RUN uv venv \
26+
&& uv sync
1727

1828
USER devuser
1929

2030
EXPOSE 8000
2131

22-
ENTRYPOINT [ "python3" ]
23-
24-
CMD [ "manage.py", "runserver", "0.0.0.0:8000" ]
32+
ENTRYPOINT [ ]
33+
34+
CMD ["/usr/local/bin/nodemon", \
35+
"--delay", "1", \
36+
"--watch", "requirements.txt", \
37+
"--watch", ".venv/lib/*", \
38+
"--watch", ".venv/lib64/*", \
39+
"--watch", "djangoapp", \
40+
"--watch", "manage.py", \
41+
"--ext", "py", \
42+
"--exec", "uv run --isolated python3 manage.py runserver 0.0.0.0:8000", \
43+
"--"]

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[project]
2+
name = "djangoapp"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"Django==5.2.3",
9+
"environs==14.2.0",
10+
]
11+
12+
[dependency-groups]
13+
deploy = ["gunicorn==22.0.0",]

uv.lock

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)