From 3fd2014e93ab75dec4396eebbaead23d208046fe Mon Sep 17 00:00:00 2001 From: lguohan Date: Wed, 19 Jul 2017 08:10:45 -0700 Subject: [PATCH] [sonic-mgmt]: move sonic-mgmt docker build into sonic-slave (#819) need to install sonic-device-data into sonic-mgmt docker --- .gitignore | 1 + Makefile | 19 +------------------ .../docker-sonic-mgmt/Dockerfile.j2 | 15 ++++++++++++++- .../docker-sonic-mgmt}/sonic-jenkins.pub | 0 rules/docker-sonic-mgmt.mk | 5 +++++ slave.mk | 7 +++++-- 6 files changed, 26 insertions(+), 21 deletions(-) rename sonic-mgmt/Dockerfile => dockers/docker-sonic-mgmt/Dockerfile.j2 (86%) rename {sonic-mgmt => dockers/docker-sonic-mgmt}/sonic-jenkins.pub (100%) create mode 100644 rules/docker-sonic-mgmt.mk diff --git a/.gitignore b/.gitignore index bf9967b04a..16d7b53f60 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ dockers/docker-orchagent/Dockerfile dockers/docker-platform-monitor/Dockerfile dockers/docker-snmp-sv2/Dockerfile dockers/docker-teamd/Dockerfile +dockers/docker-sonic-mgmt/Dockerfile platform/*/docker-syncd-*/Dockerfile platform/*/docker-syncd-*-rpc/Dockerfile diff --git a/Makefile b/Makefile index b2938221b2..5cf5f53ac3 100644 --- a/Makefile +++ b/Makefile @@ -25,21 +25,7 @@ DOCKER_BUILD = docker build --no-cache \ sonic-slave && \ docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG) - -MGMT_TAG = $(shell shasum sonic-mgmt/Dockerfile | awk '{print substr($$1,0,11);}') -MGMT_IMAGE = sonic-mgmt-$(USER) - -DOCKER_MGMT_BUILD = docker build --no-cache \ - --build-arg user=$(USER) \ - --build-arg uid=$(shell id -u) \ - --build-arg guid=$(shell id -g) \ - --build-arg hostname=$(shell echo $$HOSTNAME) \ - -t $(MGMT_IMAGE) \ - sonic-mgmt && \ - docker tag $(MGMT_IMAGE):latest $(MGMT_IMAGE):$(MGMT_TAG) - - -.PHONY: sonic-slave-build sonic-slave-bash sonic-mgmt-build +.PHONY: sonic-slave-build sonic-slave-bash .DEFAULT_GOAL := all @@ -67,6 +53,3 @@ sonic-slave-bash : { echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \ $(DOCKER_BUILD) ; } @$(DOCKER_RUN) -t $(SLAVE_IMAGE):$(SLAVE_TAG) bash - -sonic-mgmt-build : - @$(DOCKER_MGMT_BUILD) diff --git a/sonic-mgmt/Dockerfile b/dockers/docker-sonic-mgmt/Dockerfile.j2 similarity index 86% rename from sonic-mgmt/Dockerfile rename to dockers/docker-sonic-mgmt/Dockerfile.j2 index b30db8251f..6cfe286038 100644 --- a/sonic-mgmt/Dockerfile +++ b/dockers/docker-sonic-mgmt/Dockerfile.j2 @@ -20,7 +20,7 @@ RUN apt-get install -y \ libxslt1-dev \ python-setuptools -# For JNLP launcher +# For JNLP launcher RUN apt-get install -y default-jre # For syslog test @@ -44,6 +44,19 @@ RUN pip install ipaddr \ paramiko==2.1.2 \ adal + +## Copy and install sonic-mgmt docker dependencies +COPY \ +{% for deb in docker_sonic_mgmt_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor -%} +debs/ + +RUN dpkg -i \ +{% for deb in docker_sonic_mgmt_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} + RUN git clone https://github.com/ansible/ansible RUN cd ansible && git checkout v2.0.0.2-1 -b v2.0.0.2-1 && git submodule update --init --recursive && make && make install diff --git a/sonic-mgmt/sonic-jenkins.pub b/dockers/docker-sonic-mgmt/sonic-jenkins.pub similarity index 100% rename from sonic-mgmt/sonic-jenkins.pub rename to dockers/docker-sonic-mgmt/sonic-jenkins.pub diff --git a/rules/docker-sonic-mgmt.mk b/rules/docker-sonic-mgmt.mk new file mode 100644 index 0000000000..2f4908e43d --- /dev/null +++ b/rules/docker-sonic-mgmt.mk @@ -0,0 +1,5 @@ +# docker image for sonic-mgmt +DOCKER_SONIC_MGMT = docker-sonic-mgmt.gz +$(DOCKER_SONIC_MGMT)_PATH = $(DOCKERS_PATH)/docker-sonic-mgmt +$(DOCKER_SONIC_MGMT)_DEPENDS += $(SONIC_DEVICE_DATA) +SONIC_DOCKER_IMAGES += $(DOCKER_SONIC_MGMT) diff --git a/slave.mk b/slave.mk index 40e28d6d67..0d953d52c9 100644 --- a/slave.mk +++ b/slave.mk @@ -6,6 +6,9 @@ .ONESHELL: SHELL = /bin/bash .SHELLFLAGS += -e +USER = $(shell id -un) +UID = $(shell id -u) +GUID = $(shell id -g) .SECONDEXPANSION: @@ -297,7 +300,7 @@ docker-start : # targets for building simple docker images that do not depend on any debian packages $(addprefix $(TARGET_PATH)/, $(SONIC_SIMPLE_DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform docker-start $$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$($$*.gz_LOAD_DOCKERS))) $(HEADER) - docker build --squash --no-cache -t $* $($*.gz_PATH) $(LOG) + docker build --squash --no-cache --build-arg user=$(USER) --build-arg uid=$(UID) --build-arg guid=$(GUID) -t $* $($*.gz_PATH) $(LOG) docker save $* | gzip -c > $@ $(FOOTER) @@ -313,7 +316,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .pl $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_whls=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_PYTHON_WHEELS)))\n" | awk '!a[$$0]++')) $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_dbgs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DBG_PACKAGES)))\n" | awk '!a[$$0]++')) j2 $($*.gz_PATH)/Dockerfile.j2 > $($*.gz_PATH)/Dockerfile - docker build --squash --no-cache -t $* $($*.gz_PATH) $(LOG) + docker build --squash --no-cache --build-arg user=$(USER) --build-arg uid=$(UID) --build-arg guid=$(GUID) -t $* $($*.gz_PATH) $(LOG) docker save $* | gzip -c > $@ $(FOOTER)