From 1f7d9e2698dc4324abb522069ff25ef4ed38b957 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:03:12 +0200 Subject: [PATCH] [docker_img_ctl.j2] make tmpfs mounts optional and add ability to run container by image id (#6439) - Why I did it I made the docker_img_ctl.j2 applicable for more dockers (including application extensions dockers) by adding an option not to mount tmpfs on /tmp/ and /var/tmp/. In some applications /tmp/ is a different docker volume which can't be tmpfs. Also, I added and ability to pass REPO[:TAG]|[@digest]/IMAGE_ID instead of just REPO name. - How I did it Modified docker_img_ctl.j2 and docker makefiles. - How to verify it Run it on the switch. --- files/build_templates/docker_image_ctl.j2 | 16 ++++++++++++++-- slave.mk | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 388451fe72..e6d5483412 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -31,7 +31,7 @@ function updateSyslogConf() { # On multiNPU platforms, change the syslog target ip to docker0 ip to allow logs from containers # running on the namespace to reach the rsyslog service running on the host - # Also update the container name + # Also update the container name if [[ ($NUM_ASIC -gt 1) ]]; then TARGET_IP=$(docker network inspect bridge --format={{ "'{{(index .IPAM.Config 0).Gateway}}'" }}) CONTAINER_NAME="$DOCKERNAME" @@ -380,9 +380,11 @@ start() { -e SX_API_SOCKET_FILE=/var/run/sx_sdk/sx_api.sock \ -v /dev/shm:/dev/shm:rw \ {%- else %} +{%- if mount_default_tmpfs|default("n") == "y" %} --tmpfs /tmp \ {%- endif %} {%- endif %} +{%- endif %} {%- if sonic_asic_platform == "broadcom" %} {%- if docker_container_name == "syncd" %} -v /var/run/docker-syncd$DEV:/var/run/sswsyncd \ @@ -404,13 +406,23 @@ start() { $REDIS_MNT \ -v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \ {%- if sonic_asic_platform != "mellanox" %} +{%- if mount_default_tmpfs|default("n") == "y" %} --tmpfs /tmp \ {%- endif %} +{%- endif %} +{%- if mount_default_tmpfs|default("n") == "y" %} --tmpfs /var/tmp \ +{%- endif %} --env "NAMESPACE_ID"="$DEV" \ --env "NAMESPACE_PREFIX"="$NAMESPACE_PREFIX" \ --env "NAMESPACE_COUNT"=$NUM_ASIC \ - --name=$DOCKERNAME {{docker_image_name}}:latest || { + --name=$DOCKERNAME \ +{%- if docker_image_name is defined %} + {{docker_image_name}}:latest \ +{%- else %} + {{docker_image_id}} \ +{%- endif %} + || { echo "Failed to docker run" >&1 exit 4 } diff --git a/slave.mk b/slave.mk index 7bde5d2392..3db689e5e5 100644 --- a/slave.mk +++ b/slave.mk @@ -931,6 +931,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ export docker_image="$(docker)" export docker_image_name="$(basename $(docker))" export docker_container_name="$($(docker:-dbg.gz=.gz)_CONTAINER_NAME)" + export mount_default_tmpfs="y" $(eval $(docker:-dbg.gz=.gz)_RUN_OPT += $($(docker:-dbg.gz=.gz)_$($*_IMAGE_TYPE)_RUN_OPT)) export docker_image_run_opt="$($(docker:-dbg.gz=.gz)_RUN_OPT)"