Skip to content

Commit d67ed0c

Browse files
authored
Merge pull request #1386 from tobiasge/uv-build
Improved image build
2 parents b1d6e3c + 542538b commit d67ed0c

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ARG FROM
22
FROM ${FROM} AS builder
33

4+
COPY --from=ghcr.io/astral-sh/uv:0.5 /uv /usr/local/bin/
45
RUN export DEBIAN_FRONTEND=noninteractive \
56
&& apt-get update -qq \
67
&& apt-get upgrade \
@@ -20,24 +21,19 @@ RUN export DEBIAN_FRONTEND=noninteractive \
2021
libxslt-dev \
2122
pkg-config \
2223
python3-dev \
23-
python3-pip \
24-
python3-venv \
25-
&& python3 -m venv /opt/netbox/venv \
26-
&& /opt/netbox/venv/bin/python3 -m pip install --upgrade \
27-
pip \
28-
setuptools \
29-
wheel
24+
&& /usr/local/bin/uv venv /opt/netbox/venv
3025

3126
ARG NETBOX_PATH
3227
COPY ${NETBOX_PATH}/requirements.txt requirements-container.txt /
28+
ENV VIRTUAL_ENV=/opt/netbox/venv
3329
RUN \
3430
# Gunicorn is not needed because we use Nginx Unit
3531
sed -i -e '/gunicorn/d' /requirements.txt && \
3632
# We need 'social-auth-core[all]' in the Docker image. But if we put it in our own requirements-container.txt
3733
# we have potential version conflicts and the build will fail.
3834
# That's why we just replace it in the original requirements.txt.
3935
sed -i -e 's/social-auth-core/social-auth-core\[all\]/g' /requirements.txt && \
40-
/opt/netbox/venv/bin/pip install \
36+
/usr/local/bin/uv pip install \
4137
-r /requirements.txt \
4238
-r /requirements-container.txt
4339

@@ -75,12 +71,13 @@ RUN export DEBIAN_FRONTEND=noninteractive \
7571
unit-python3.12=1.34.1-1~noble \
7672
&& rm -rf /var/lib/apt/lists/*
7773

74+
# Copy the modified 'requirements*.txt' files, to have the files actually used during installation
75+
COPY --from=builder /requirements.txt /requirements-container.txt /opt/netbox/
76+
COPY --from=builder /usr/local/bin/uv /usr/local/bin/
7877
COPY --from=builder /opt/netbox/venv /opt/netbox/venv
7978

8079
ARG NETBOX_PATH
8180
COPY ${NETBOX_PATH} /opt/netbox
82-
# Copy the modified 'requirements*.txt' files, to have the files actually used during installation
83-
COPY --from=builder /requirements.txt /requirements-container.txt /opt/netbox/
8481

8582
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
8683
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
@@ -100,11 +97,11 @@ RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \
10097
&& chmod -R g+w /opt/unit/ media reports scripts \
10198
&& cd /opt/netbox/ && SECRET_KEY="dummyKeyWithMinimumLength-------------------------" /opt/netbox/venv/bin/python -m mkdocs build \
10299
--config-file /opt/netbox/mkdocs.yml --site-dir /opt/netbox/netbox/project-static/docs/ \
103-
&& SECRET_KEY="dummyKeyWithMinimumLength-------------------------" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input \
100+
&& DEBUG="true" SECRET_KEY="dummyKeyWithMinimumLength-------------------------" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input \
104101
&& mkdir /opt/netbox/netbox/local \
105-
&& echo "edition: Community (Docker image $(cat /opt/netbox/VERSION))" > /opt/netbox/netbox/local/release.yaml
102+
&& echo "build: Docker-$(cat /opt/netbox/VERSION)" > /opt/netbox/netbox/local/release.yaml
106103

107-
ENV LANG=C.utf8 PATH=/opt/netbox/venv/bin:$PATH
104+
ENV LANG=C.utf8 PATH=/opt/netbox/venv/bin:$PATH VIRTUAL_ENV=/opt/netbox/venv UV_NO_CACHE=1
108105
ENTRYPOINT [ "/usr/bin/tini", "--" ]
109106

110107
CMD [ "/opt/netbox/docker-entrypoint.sh", "/opt/netbox/launch-netbox.sh" ]

requirements-container.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
django-auth-ldap==5.1.0
22
django-storages[azure,boto3,dropbox,google,libcloud,sftp]==1.14.4
33
dulwich==0.22.7
4-
python3-saml==1.16.0 --no-binary lxml,xmlsec
4+
python3-saml==1.16.0
5+
--no-binary lxml
6+
--no-binary xmlsec
57
sentry-sdk[django]==2.20.0

0 commit comments

Comments
 (0)