Skip to content

Commit

Permalink
reduce docker file size
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Nov 27, 2024
1 parent 13685c5 commit 1a0c742
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ FROM python:3.11-slim-bookworm AS builder

COPY requirements.txt .

ARG VENV=/opt/netbox-sync/venv

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends git && \
rm -rf /var/lib/apt/lists/* && \
python3 -m venv /opt/netbox-sync/venv && \
/opt/netbox-sync/venv/bin/python3 -m pip install --upgrade pip && \
/opt/netbox-sync/venv/bin/pip install -r requirements.txt && \
/opt/netbox-sync/venv/bin/pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
python3 -m venv $VENV && \
$VENV/bin/python3 -m pip install --upgrade pip && \
$VENV/bin/pip install -r requirements.txt && \
$VENV/bin/pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git && \
find $VENV -type d -name "__pycache__" -print0 | xargs -0 -n1 rm -rf

FROM python:3.11-slim-bookworm AS netbox-sync

ARG VENV=/opt/netbox-sync/venv

# Copy installed packages
COPY --from=builder /opt/netbox-sync/venv /opt/netbox-sync/venv
COPY --from=builder $VENV $VENV

# Add netbox-sync user
RUN groupadd --gid 1000 netbox-sync && \
Expand All @@ -27,7 +32,7 @@ WORKDIR /app
COPY --chown=netbox-sync:netbox-sync . .

# Use virtual env packages and allow timezone setup
ENV PATH=/opt/netbox-sync/venv/bin:$PATH
ENV PATH=$VENV/bin:$PATH
ENV TZ=Europe/Berlin

ENTRYPOINT ["python3", "netbox-sync.py"]
2 changes: 1 addition & 1 deletion scripts/publi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unset DOCKER_TLS_VERIFY
unset DOCKER_HOST
unset DOCKER_CERT_PATH

find module -type d -name "__pycache__" -exec rm -rf {} \;
find module -type d -name "__pycache__" -print0 | xargs -0 -n1 rm -rf
docker --config ./docker-tmp login
docker --config ./docker-tmp buildx create --use
if [[ $FINAL == true ]]; then
Expand Down

0 comments on commit 1a0c742

Please sign in to comment.