Skip to content

Commit

Permalink
[dockers] save extension dockers with an image tag (#12829)
Browse files Browse the repository at this point in the history
Fixes: #11521

- Why I did it
When build SONiC dockers, SONiC build system tags all of them with latest tag. This is Ok for all built-in dockers because we will also tag them with image version tag in sonic_debian_extension.j2 script. On the other hand, some of these dockers are SONiC packages and they are installed by sonic-package-manager which creates a only one tag whcih is recorded in the corresponding .gz file. This leads to having these dockers tagged only with latest tag. This change saves the tag as an image version string in .gz file, so that these dockers have version identification in their tag.

- How I did it
I modified slave.mk to save the version tag instead of latest tag.

- How to verify it
I verified this change by running show version

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored Nov 30, 2022
1 parent 7d38b45 commit d22cf46
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,15 @@ export vs_build_prepare_mem=$(VS_PREPARE_MEM)
##
## docker-swss:latest <=SAVE/LOAD=> docker-swss-<user>:<tag>

# $(call docker-get-tag,tag)
# Get the docker tag. For packages it is an image version, for other dockers it stays latest.
#
# $(1) => Docker name

define docker-get-tag
$(shell [ ! -z $(filter $(1).gz,$(SONIC_PACKAGES_LOCAL)) ] && echo $(SONIC_IMAGE_VERSION) || echo latest)
endef

# $(call docker-image-save,from,to)
# Sonic docker images are always created with username as extension. During the save operation,
# it removes the username extension from docker image and saved them as compressed tar file for SONiC image generation.
Expand All @@ -452,13 +461,13 @@ define docker-image-save
@echo "Attempting docker image lock for $(1) save" $(LOG)
$(call MOD_LOCK,$(1),$(DOCKER_LOCKDIR),$(DOCKER_LOCKFILE_SUFFIX),$(DOCKER_LOCKFILE_TIMEOUT))
@echo "Obtained docker image lock for $(1) save" $(LOG)
@echo "Tagging docker image $(1)-$(DOCKER_USERNAME):$(DOCKER_USERTAG) as $(1):latest" $(LOG)
docker tag $(1)-$(DOCKER_USERNAME):$(DOCKER_USERTAG) $(1):latest $(LOG)
@echo "Saving docker image $(1):latest" $(LOG)
docker save $(1):latest | gzip -c > $(2)
@echo "Tagging docker image $(1)-$(DOCKER_USERNAME):$(DOCKER_USERTAG) as $(1):$(call docker-get-tag,$(1))" $(LOG)
docker tag $(1)-$(DOCKER_USERNAME):$(DOCKER_USERTAG) $(1):$(call docker-get-tag,$(1)) $(LOG)
@echo "Saving docker image $(1):$(call docker-get-tag,$(1))" $(LOG)
docker save $(1):$(call docker-get-tag,$(1)) | gzip -c > $(2)
if [ x$(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD) == x"y" ]; then
@echo "Removing docker image $(1):latest" $(LOG)
docker rmi -f $(1):latest $(LOG)
@echo "Removing docker image $(1):$(call docker-get-tag,$(1))" $(LOG)
docker rmi -f $(1):$(call docker-get-tag,$(1)) $(LOG)
fi
$(call MOD_UNLOCK,$(1))
@echo "Released docker image lock for $(1) save" $(LOG)
Expand Down Expand Up @@ -1027,6 +1036,7 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform
-t $(DOCKER_IMAGE_REF) $($*.gz_PATH) $(LOG)
if [ x$(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD) == x"y" ]; then docker tag $(DOCKER_IMAGE_REF) $*; fi
scripts/collect_docker_version_files.sh $(DOCKER_IMAGE_REF) $(TARGET_PATH)
if [ ! -z $(filter $*.gz,$(SONIC_PACKAGES_LOCAL)) ]; then docker tag $(DOCKER_IMAGE_REF) $*:$(SONIC_IMAGE_VERSION); fi
$(call docker-image-save,$*,$@)
# Clean up
if [ -f $($*.gz_PATH).patch/series ]; then pushd $($*.gz_PATH) && quilt pop -a -f; [ -d .pc ] && rm -rf .pc; popd; fi
Expand Down Expand Up @@ -1080,6 +1090,7 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_DBG_IMAGES)) : $(TARGET_PATH)/%-$(DBG_IMAG
-t $(DOCKER_DBG_IMAGE_REF) $($*.gz_PATH) $(LOG)
if [ x$(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD) == x"y" ]; then docker tag $(DOCKER_IMAGE_REF) $*; fi
scripts/collect_docker_version_files.sh $(DOCKER_DBG_IMAGE_REF) $(TARGET_PATH)
if [ ! -z $(filter $*.gz,$(SONIC_PACKAGES_LOCAL)) ]; then docker tag $(DOCKER_IMAGE_REF) $*:$(SONIC_IMAGE_VERSION); fi
$(call docker-image-save,$*-$(DBG_IMAGE_MARK),$@)
# Clean up
docker rmi -f $(DOCKER_IMAGE_REF) &> /dev/null || true
Expand Down

0 comments on commit d22cf46

Please sign in to comment.