From b374e7bc314ada430a0804a2760a5fc429bc614a Mon Sep 17 00:00:00 2001 From: Thomas Grimonet Date: Wed, 8 Nov 2023 17:08:12 +0100 Subject: [PATCH] chore: Reduce size of docker image (#444) * chore: Reduce size of docker image * chore: Add org.opencontainers.image.description field * chore: Update base image to use generic versions --- .dockerignore | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 21 ++++++++++-- 2 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..fbe1ace86 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,93 @@ +# Git +.git +.gitignore +.gitattributes + + +# CI +.codeclimate.yml +.travis.yml +.taskcluster.yml + +# Docker +docker-compose.yml +Dockerfile +.docker +.dockerignore + +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Virtual environment +.env +.venv/ +venv/ + +# PyCharm +.idea + +# Python mode for VIM +.ropeproject +**/.ropeproject + +# Vim swap files +**/*.swp + +# VS Code +.vscode/ + +tests/** +examples/** + diff --git a/Dockerfile b/Dockerfile index 43b588f04..2a0ef53f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ ARG PYTHON_VER=3.9 +ARG IMG_OPTION=alpine -FROM python:${PYTHON_VER}-slim +### BUILDER + +FROM python:${PYTHON_VER}-${IMG_OPTION} as BUILDER RUN pip install --upgrade pip @@ -8,7 +11,15 @@ WORKDIR /local COPY . /local ENV PYTHONPATH=/local -RUN pip --no-cache-dir install . +ENV PATH=$PATH:/root/.local/bin + +RUN pip --no-cache-dir install --user . + +# ----------------------------------- # + +### BASE + +FROM python:${PYTHON_VER}-${IMG_OPTION} as BASE # Opencontainer labels # Labels version and revision will be updating @@ -18,6 +29,7 @@ RUN pip --no-cache-dir install . # Doc: https://docs.docker.com/engine/reference/commandline/run/#label LABEL "org.opencontainers.image.title"="anta" \ "org.opencontainers.artifact.description"="network-test-automation in a Python package and Python scripts to test Arista devices." \ + "org.opencontainers.image.description"="network-test-automation in a Python package and Python scripts to test Arista devices." \ "org.opencontainers.image.source"="https://github.com/arista-netdevops-community/anta" \ "org.opencontainers.image.url"="https://www.anta.ninja" \ "org.opencontainers.image.documentation"="https://www.anta.ninja" \ @@ -28,4 +40,7 @@ LABEL "org.opencontainers.image.title"="anta" \ "org.opencontainers.image.revision"="dev" \ "org.opencontainers.image.version"="dev" -ENTRYPOINT [ "/usr/local/bin/anta" ] +COPY --from=BUILDER /root/.local/ /root/.local +ENV PATH=$PATH:/root/.local/bin + +ENTRYPOINT [ "/root/.local/bin/anta" ]