|
1 | | -FROM python:3.9-slim-bullseye AS PREBUILD |
| 1 | +FROM python:3.9-slim-bookworm AS builder |
2 | 2 |
|
3 | | -# Install dependencies |
4 | | -RUN apt-get update && apt-get -y upgrade && apt-get install -y git-core |
5 | | - |
6 | | -COPY requirements.txt /tmp/requirements.txt |
7 | | - |
8 | | -RUN pip3 install --upgrade pip && \ |
9 | | - pip3 install wheel && \ |
10 | | - pip3 install -r /tmp/requirements.txt && \ |
11 | | - pip3 install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git |
12 | | - |
13 | | - |
14 | | -FROM python:3.9-slim-bullseye |
| 3 | +COPY requirements.txt . |
15 | 4 |
|
16 | 5 | # Install dependencies |
17 | | -RUN apt-get update && apt-get -y upgrade |
| 6 | +RUN apt-get update && apt-get install -y --no-install-recommends git && \ |
| 7 | + rm -rf /var/lib/apt/lists/* && \ |
| 8 | + python3 -m venv /opt/netbox-sync/venv && \ |
| 9 | + /opt/netbox-sync/venv/bin/python3 -m pip install --upgrade pip && \ |
| 10 | + /opt/netbox-sync/venv/bin/pip install -r requirements.txt && \ |
| 11 | + /opt/netbox-sync/venv/bin/pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git |
18 | 12 |
|
19 | | -# Run the application |
20 | | -WORKDIR /app |
| 13 | +FROM python:3.9-slim-bookworm AS netbox-sync |
21 | 14 |
|
22 | | -RUN set -eux; \ |
23 | | - addgroup --gid 1000 netbox-sync; \ |
24 | | - adduser --uid 1000 --ingroup netbox-sync --shell /bin/sh --home /home/netbox-sync --disabled-password \ |
25 | | - --gecos "netbox-sync,0815,2342,9001" netbox-sync |
| 15 | +# Copy installed packages |
| 16 | +COPY --from=builder /opt/netbox-sync/venv /opt/netbox-sync/venv |
26 | 17 |
|
27 | | -# Prepare the application |
28 | | -COPY Dockerfile LICENSE.txt netbox-sync.py README.md requirements.txt settings-example.ini /app/ |
29 | | -COPY module /app/module |
| 18 | +# Add netbox-sync user |
| 19 | +RUN groupadd --gid 1000 netbox-sync && \ |
| 20 | + useradd --uid 1000 --gid netbox-sync --shell /bin/sh \ |
| 21 | + --no-create-home --system netbox-sync |
30 | 22 |
|
31 | | -RUN chown -R netbox-sync:netbox-sync /app |
| 23 | +USER netbox-sync |
32 | 24 |
|
33 | | -# disable upgrading setup tools due to bug in setuptools and automation sdk |
34 | | -# once this is fixed, switch back to: pip3 install --upgrade pip setuptools |
35 | | -COPY --from=PREBUILD /usr/local /usr/local |
| 25 | +# Prepare the application |
| 26 | +WORKDIR /app |
| 27 | +COPY --chown=netbox-sync:netbox-sync . . |
36 | 28 |
|
37 | | -USER netbox-sync |
| 29 | +# Use virtual env packages and allow timezone setup |
| 30 | +ENV PATH=/opt/netbox-sync/venv/bin:$PATH |
| 31 | +ENV TZ=Europe/Berlin |
38 | 32 |
|
39 | 33 | ENTRYPOINT ["python3", "netbox-sync.py"] |
0 commit comments