[docker-base-buster][docker-config-engine-buster] No longer install Python 2 (#6162)

**- Why I did it**

As part of migrating SONiC codebase from Python 2 to Python 3

**- How I did it**

- No longer install Python 2 in docker-base-buster or docker-config-engine-buster.
- Install Python 2 and pip2 in the following containers until we can completely eliminate it there:
    - docker-platform-monitor
    - docker-sonic-mgmt-framework
    - docker-sonic-vs
- Pin pip2 version <21 where it is still temporarily needed, as pip version 21 will drop support for Python 2
- Also preform some other cleanup, ensuring that pip3, setuptools and wheel packages are installed in docker-base-buster, and then removing any attempts to re-install them in derived containers
This commit is contained in:
Joe LeVeque 2020-12-25 21:29:25 -08:00 committed by GitHub
parent 9a51505215
commit d40c9a1e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 60 additions and 69 deletions

View File

@ -44,9 +44,8 @@ RUN apt-get update && \
less \ less \
perl \ perl \
procps \ procps \
python \
python-pip \
python3 \ python3 \
python3-distutils \
python3-pip \ python3-pip \
rsyslog \ rsyslog \
vim-tiny \ vim-tiny \
@ -57,7 +56,6 @@ RUN apt-get update && \
lua-bitop \ lua-bitop \
lua-cjson \ lua-cjson \
# common dependencies # common dependencies
libpython2.7 \
libdaemon0 \ libdaemon0 \
libdbus-1-3 \ libdbus-1-3 \
libjansson4 \ libjansson4 \
@ -84,15 +82,16 @@ RUN dpkg -i redis-tools_6.0.6-1~bpo10+1_amd64.deb || apt-get install -f -y
RUN rm redis-tools_6.0.6-1~bpo10+1_amd64.deb RUN rm redis-tools_6.0.6-1~bpo10+1_amd64.deb
{% endif %} {% endif %}
# Some Python packages require setuptools (or pkg_resources, which is supplied by setuptools) # Upgrade pip via PyPI and uninstall the Debian version
# and some require wheel RUN pip3 install --upgrade pip
RUN pip install setuptools==40.8.0 RUN apt-get purge -y python3-pip
RUN pip3 install setuptools==49.6.00
RUN pip install wheel # setuptools and wheel are necessary for installing some Python wheel packages
RUN pip3 install wheel RUN pip3 install --no-cache-dir setuptools==49.6.00
RUN pip3 install --no-cache-dir wheel==0.35.1
# For templating # For templating
RUN pip2 install j2cli RUN pip3 install j2cli
# Install supervisor # Install supervisor
RUN pip3 install supervisor==4.2.1 RUN pip3 install supervisor==4.2.1

View File

@ -52,6 +52,9 @@ COPY ["etc/rsyslog.conf", "/etc/rsyslog.conf"]
COPY ["etc/rsyslog.d/*", "/etc/rsyslog.d/"] COPY ["etc/rsyslog.d/*", "/etc/rsyslog.d/"]
COPY ["root/.vimrc", "/root/.vimrc"] COPY ["root/.vimrc", "/root/.vimrc"]
RUN pip install --upgrade 'pip<21'
RUN apt-get purge -y python-pip
# Some Python packages require setuptools (or pkg_resources, which is supplied by setuptools) # Some Python packages require setuptools (or pkg_resources, which is supplied by setuptools)
# and some require wheel # and some require wheel
RUN pip install setuptools==40.8.0 RUN pip install setuptools==40.8.0

View File

@ -6,22 +6,15 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
build-essential \
python-pip \
python3-pip \
python-dev \
python3-dev \
apt-utils \ apt-utils \
{%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %} build-essential \
libxslt-dev \ python3-dev
libz-dev \
{%- endif %}
python-setuptools \
python3-setuptools
RUN pip3 install --upgrade pip {%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %}
RUN pip2 install --upgrade pip RUN apt-get install -y \
RUN apt-get purge -y python-pip python3-pip libxslt-dev \
libz-dev
{%- endif %}
# For sonic-config-engine Python 3 package # For sonic-config-engine Python 3 package
# Explicitly install pyangbind here, as pyangbind causes enum34 to be installed. # Explicitly install pyangbind here, as pyangbind causes enum34 to be installed.
@ -51,7 +44,6 @@ COPY ["files/swss_vars.j2", "/usr/share/sonic/templates/"]
## Clean up ## Clean up
RUN apt-get purge -y \ RUN apt-get purge -y \
python-dev \
python3-dev \ python3-dev \
build-essential && \ build-essential && \
apt-get clean -y && \ apt-get clean -y && \

View File

@ -8,15 +8,13 @@ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
# Dependencies for sonic-cfggen # Dependencies for sonic-cfggen
build-essential \ build-essential \
python-pip \ python-dev
python-dev \
{%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %}
libxslt-dev \
libz-dev \
{%- endif %}
python-setuptools
RUN pip install --upgrade pip {%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %}
RUN apt-get install -y \
libxslt-dev \
libz-dev
{%- endif %}
{% if docker_config_engine_stretch_debs.strip() %} {% if docker_config_engine_stretch_debs.strip() %}
# Copy locally-built Debian package dependencies # Copy locally-built Debian package dependencies
@ -40,7 +38,6 @@ COPY ["files/swss_vars.j2", "/usr/share/sonic/templates/"]
## Clean up ## Clean up
RUN apt-get purge -y \ RUN apt-get purge -y \
build-essential \ build-essential \
python-pip \
python-dev && \ python-dev && \
apt-get clean -y && \ apt-get clean -y && \
apt-get autoclean -y && \ apt-get autoclean -y && \

View File

@ -6,11 +6,7 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update RUN apt-get update
# Dependencies for sonic-cfggen # Dependencies for sonic-cfggen
RUN apt-get install -y build-essential python-pip python-dev RUN apt-get install -y build-essential python-dev
RUN pip install --upgrade pip
RUN apt-get purge -y python-pip
{% if docker_config_engine_debs.strip() %} {% if docker_config_engine_debs.strip() %}
COPY \ COPY \

View File

@ -79,7 +79,7 @@ rm $db_cfg_file_tmp
# copy dump.rdb file to each instance for restoration # copy dump.rdb file to each instance for restoration
DUMPFILE=/var/lib/redis/dump.rdb DUMPFILE=/var/lib/redis/dump.rdb
redis_inst_list=`/usr/bin/python -c "import swsssdk; print(' '.join(swsssdk.SonicDBConfig.get_instancelist().keys()))"` redis_inst_list=`/usr/bin/python3 -c "import swsssdk; print(' '.join(swsssdk.SonicDBConfig.get_instancelist().keys()))"`
for inst in $redis_inst_list for inst in $redis_inst_list
do do
mkdir -p /var/lib/$inst mkdir -p /var/lib/$inst

View File

@ -18,7 +18,7 @@ stdout_logfile=syslog
stderr_logfile=syslog stderr_logfile=syslog
{% if INSTANCES %} {% if INSTANCES %}
{% for redis_inst, redis_items in INSTANCES.iteritems() %} {% for redis_inst, redis_items in INSTANCES.items() %}
[program: {{ redis_inst }}] [program: {{ redis_inst }}]
{% if redis_items['hostname'] != '127.0.0.1' and redis_inst != 'redis_chassis' %} {% if redis_items['hostname'] != '127.0.0.1' and redis_inst != 'redis_chassis' %}
{%- set LOOPBACK_IP = '127.0.0.1' -%} {%- set LOOPBACK_IP = '127.0.0.1' -%}

View File

@ -21,7 +21,6 @@ RUN apt-get update && \
ndppd \ ndppd \
# Needed for installing netifaces Python package # Needed for installing netifaces Python package
build-essential \ build-essential \
python-dev \
python3-dev python3-dev
{% if ( CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" ) %} {% if ( CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" ) %}
@ -36,14 +35,6 @@ RUN ln -s -f /usr/bin/gcc-8 /usr/bin/arm-linux-gnueabihf-gcc
RUN ln -s -f /usr/bin/gcc-8 /usr/bin/aarch64-linux-gnu-gcc RUN ln -s -f /usr/bin/gcc-8 /usr/bin/aarch64-linux-gnu-gcc
{% endif %} {% endif %}
RUN pip2 install \
scapy==2.4.2 \
setuptools \
pyroute2==0.5.3
RUN pip2 install \
netifaces==0.10.7 \
monotonic==1.5
# Dependencies of restore_neighbors.py # Dependencies of restore_neighbors.py
RUN pip3 install \ RUN pip3 install \
scapy==2.4.4 \ scapy==2.4.4 \
@ -66,7 +57,6 @@ RUN apt-get remove -y gcc-8
# Clean up # Clean up
RUN apt-get purge -y \ RUN apt-get purge -y \
build-essential \ build-essential \
python-dev \
python3-dev && \ python3-dev && \
apt-get clean -y && \ apt-get clean -y && \
apt-get autoclean -y && \ apt-get autoclean -y && \

View File

@ -14,7 +14,7 @@ ENV IMAGE_VERSION=$image_version
# Install required packages # Install required packages
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
python-dev \ build-essential \
python3-dev \ python3-dev \
ipmitool \ ipmitool \
librrd8 \ librrd8 \
@ -26,6 +26,11 @@ RUN apt-get update && \
i2c-tools \ i2c-tools \
python-jsonschema python-jsonschema
# TODO: Remove these lines once we no longer need Python 2
RUN apt-get install -f -y python-dev python-pip
RUN pip2 install --upgrade 'pip<21'
RUN apt-get purge -y python-pip
# On Arista devices, the sonic_platform wheel is not installed in the container. # On Arista devices, the sonic_platform wheel is not installed in the container.
# Instead, the installation directory is mounted from the host OS. However, this method # Instead, the installation directory is mounted from the host OS. However, this method
# doesn't ensure all dependencies are installed in the container. So here we # doesn't ensure all dependencies are installed in the container. So here we
@ -64,9 +69,13 @@ RUN pip3 install thrift==0.13.0
{{ install_python_wheels(docker_platform_monitor_whls.split(' ')) }} {{ install_python_wheels(docker_platform_monitor_whls.split(' ')) }}
{% endif %} {% endif %}
# TODO: Remove this line once we no longer need Python 2
RUN apt-get purge -y python-dev
# Clean up # Clean up
RUN apt-get purge -y \ RUN apt-get purge -y \
python-dev \ build-essential \
python3-dev && \ python3-dev && \
apt-get clean -y && \ apt-get clean -y && \
apt-get autoclean -y && \ apt-get autoclean -y && \

View File

@ -40,12 +40,8 @@ ENV LC_CTYPE=en_US.UTF-8
RUN sed -i '/^#.* en_US.* /s/^#//' /etc/locale.gen RUN sed -i '/^#.* en_US.* /s/^#//' /etc/locale.gen
RUN locale-gen RUN locale-gen
# Install up-to-date version of pip # Install dependencies used by some plugins
RUN pip3 install --no-cache-dir setuptools wheel RUN pip3 install --no-cache-dir \
# Install pyyaml dependency for use by some plugins
# Install smbus dependency for use by some plugins
RUN python3 -m pip install --no-cache-dir \
hiredis \ hiredis \
pyyaml \ pyyaml \
smbus smbus

View File

@ -7,8 +7,14 @@ RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%s
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y g++ python-dev python3-dev libxml2 apt-get install -y g++ python3-dev libxml2
# TODO: Remove these lines once we no longer need Python 2
RUN apt-get install -f -y python-dev python-pip
RUN pip2 install --upgrade 'pip<21'
RUN apt-get purge -y python-pip
RUN pip2 install setuptools==40.8.0
RUN pip2 install wheel==0.35.1
RUN pip2 install connexion==1.1.15 \ RUN pip2 install connexion==1.1.15 \
setuptools==21.0.0 \ setuptools==21.0.0 \
grpcio-tools==1.20.0 \ grpcio-tools==1.20.0 \
@ -40,7 +46,10 @@ COPY ["start.sh", "rest-server.sh", "/usr/bin/"]
COPY ["mgmt_vars.j2", "/usr/share/sonic/templates/"] COPY ["mgmt_vars.j2", "/usr/share/sonic/templates/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
RUN apt-get remove -y g++ python-dev python3-dev # TODO: Remove this line once we no longer need Python 2
RUN apt-get purge -y python-dev
RUN apt-get remove -y g++ python3-dev
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs RUN rm -rf /debs

View File

@ -42,13 +42,13 @@ RUN apt-get install -y net-tools \
python-scapy \ python-scapy \
conntrack \ conntrack \
iptables \ iptables \
python3-pip \
jq \ jq \
libzmq5 \ libzmq5 \
# For installing Python m2crypto package # For installing Python m2crypto package
# (these can be uninstalled after installation) # (these can be uninstalled after installation)
build-essential \ build-essential \
python-dev \ python-dev \
python-pip \
python3-dev \ python3-dev \
libssl-dev \ libssl-dev \
swig \ swig \
@ -73,8 +73,10 @@ RUN dpkg -i redis-tools_6.0.6-1~bpo10+1_amd64.deb redis-server_6.0.6-1~bpo10+1_a
RUN rm redis-tools_6.0.6-1~bpo10+1_amd64.deb redis-server_6.0.6-1~bpo10+1_amd64.deb RUN rm redis-tools_6.0.6-1~bpo10+1_amd64.deb redis-server_6.0.6-1~bpo10+1_amd64.deb
{% endif %} {% endif %}
RUN pip2 install setuptools RUN pip2 install --upgrade 'pip<21'
RUN pip3 install setuptools RUN apt-get purge -y python-pip
RUN pip2 install setuptools==40.8.0
RUN pip2 install wheel==0.33.6
RUN pip2 install py2_ipaddress RUN pip2 install py2_ipaddress
RUN pip2 install six RUN pip2 install six
RUN pip2 install pyroute2==0.5.3 netifaces==0.10.7 RUN pip2 install pyroute2==0.5.3 netifaces==0.10.7

View File

@ -4,11 +4,8 @@ DOCKER_CONFIG_ENGINE_BUSTER = docker-config-engine-buster.gz
$(DOCKER_CONFIG_ENGINE_BUSTER)_PATH = $(DOCKERS_PATH)/docker-config-engine-buster $(DOCKER_CONFIG_ENGINE_BUSTER)_PATH = $(DOCKERS_PATH)/docker-config-engine-buster
$(DOCKER_CONFIG_ENGINE_BUSTER)_DEPENDS += $(LIBSWSSCOMMON) $(PYTHON3_SWSSCOMMON) $(DOCKER_CONFIG_ENGINE_BUSTER)_DEPENDS += $(LIBSWSSCOMMON) $(PYTHON3_SWSSCOMMON)
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SWSSSDK_PY2)
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SWSSSDK_PY3) $(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SWSSSDK_PY3)
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2)
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3) $(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3)
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY2)
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY3) $(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY3)
$(DOCKER_CONFIG_ENGINE_BUSTER)_LOAD_DOCKERS += $(DOCKER_BASE_BUSTER) $(DOCKER_CONFIG_ENGINE_BUSTER)_LOAD_DOCKERS += $(DOCKER_BASE_BUSTER)
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(SWSS_VARS_TEMPLATE) $(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(SWSS_VARS_TEMPLATE)

View File

@ -14,6 +14,7 @@ $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY3) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY3) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD)

View File

@ -370,7 +370,7 @@ RUN export VERSION=1.14.2 \
&& rm go$VERSION.linux-*.tar.gz && rm go$VERSION.linux-*.tar.gz
RUN pip3 install --upgrade pip RUN pip3 install --upgrade pip
RUN pip2 install --upgrade pip RUN pip2 install --upgrade 'pip<21'
RUN apt-get purge -y python-pip python3-pip RUN apt-get purge -y python-pip python3-pip
# For building Python packages # For building Python packages

View File

@ -339,7 +339,7 @@ RUN export VERSION=1.14.2 \
&& rm go$VERSION.linux-*.tar.gz && rm go$VERSION.linux-*.tar.gz
RUN pip3 install --upgrade pip RUN pip3 install --upgrade pip
RUN pip2 install --upgrade pip RUN pip2 install --upgrade 'pip<21'
RUN apt-get purge -y python-pip python3-pip RUN apt-get purge -y python-pip python3-pip
# For p4 build # For p4 build