From 7013b058992f29e372f10b7a2412fe42bc2c0c27 Mon Sep 17 00:00:00 2001 From: ShiyanWangMS Date: Fri, 3 Nov 2023 09:04:01 +0800 Subject: [PATCH] Add new docker-sonic-mgmt makefile flag: LEGACY_SONIC_MGMT_DOCKER (#17070) Why I did it This is part of Python3 migration project. This PR will add a new makefile flag: LEGACY_SONIC_MGMT_DOCKER Now by default: LEGACY_SONIC_MGMT_DOCKER = y will build sonic-mgmt-docker with Python2 and Python3 If LEGACY_SONIC_MGMT_DOCKER = n will will sonic-mgmt-docker with Python3 only Work item tracking Microsoft ADO (number only): 25254349 How I did it Add makefile flag: LEGACY_SONIC_MGMT_DOCKER How to verify it By default will build sonic-mgmt-docker with Python2 and Python3. No change compared to before. Set LEGACY_SONIC_MGMT_DOCKER=n will build sonic-mgmt-docker with Python3 only --- Makefile.work | 5 +++++ dockers/docker-sonic-mgmt/Dockerfile.j2 | 4 ++++ slave.mk | 1 + 3 files changed, 10 insertions(+) diff --git a/Makefile.work b/Makefile.work index e98503a132..d9b3212b4e 100644 --- a/Makefile.work +++ b/Makefile.work @@ -147,6 +147,10 @@ ifeq ($(ENABLE_DOCKER_BASE_PULL),) override ENABLE_DOCKER_BASE_PULL = n endif +ifeq ($(LEGACY_SONIC_MGMT_DOCKER),) + override LEGACY_SONIC_MGMT_DOCKER = y +endif + ifneq ($(GZ_COMPRESS_PROGRAM), pigz) override GZ_COMPRESS_PROGRAM = gzip endif @@ -572,6 +576,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \ ONIE_IMAGE_PART_SIZE=$(ONIE_IMAGE_PART_SIZE) \ SONIC_OS_VERSION=$(SONIC_OS_VERSION) \ PIP_HTTP_TIMEOUT=$(PIP_HTTP_TIMEOUT) \ + LEGACY_SONIC_MGMT_DOCKER=$(LEGACY_SONIC_MGMT_DOCKER) \ $(SONIC_OVERRIDE_BUILD_VARS) .PHONY: sonic-slave-build sonic-slave-bash init reset diff --git a/dockers/docker-sonic-mgmt/Dockerfile.j2 b/dockers/docker-sonic-mgmt/Dockerfile.j2 index e4f3e07d63..0c578fa2b1 100755 --- a/dockers/docker-sonic-mgmt/Dockerfile.j2 +++ b/dockers/docker-sonic-mgmt/Dockerfile.j2 @@ -1,6 +1,8 @@ {% set prefix = DEFAULT_CONTAINER_REGISTRY %} FROM {{ prefix }}ubuntu:20.04 +{% set legacy = LEGACY_SONIC_MGMT_DOCKER %} + ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y apt-transport-https \ @@ -117,6 +119,7 @@ RUN python3 -m pip install aiohttp \ && rm -f 1.2.tar.gz \ && python3 -m pip install nnpy +{% if legacy == 'y' or legacy == '1' %} RUN curl -fsSL https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py \ && python2 get-pip.py \ && rm -f get-pip.py @@ -185,6 +188,7 @@ RUN python2 -m pip install allure-pytest==2.8.22 \ textfsm==1.1.3 \ thrift==0.11.0 \ virtualenv +{% endif %} # Install docker-ce-cli RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \ diff --git a/slave.mk b/slave.mk index a09adbaa7d..30689d4dc6 100644 --- a/slave.mk +++ b/slave.mk @@ -443,6 +443,7 @@ $(info "BUILD_MULTIASIC_KVM" : "$(BUILD_MULTIASIC_KVM)") endif $(info "CROSS_BUILD_ENVIRON" : "$(CROSS_BUILD_ENVIRON)") $(info "GZ_COMPRESS_PROGRAM" : "$(GZ_COMPRESS_PROGRAM)") +$(info "LEGACY_SONIC_MGMT_DOCKER" : "$(LEGACY_SONIC_MGMT_DOCKER)") $(info ) else $(info SONiC Build System for $(CONFIGURED_PLATFORM):$(CONFIGURED_ARCH))