diff --git a/Makefile b/Makefile index 3b9a8645ce92..38e90f2bfae0 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ DOCKER_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 $(SLAVE_IMAGE) \ sonic-slave && \ docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG) @@ -36,7 +37,7 @@ DOCKER_BUILD = docker build --no-cache \ -C sonic \ -f slave.mk \ PLATFORM=$(PLATFORM) \ - DEBUG_BUILD=$(DEBUG_BUILD) \ + BUILD_NUMBER=$(BUILD_NUMBER) \ ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \ $@ diff --git a/build_debian.sh b/build_debian.sh index 0bce39736b9f..a796a243363d 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -257,6 +257,17 @@ sudo cp files/dhcp/graphserviceurl $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/ +## Version file +sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic +sudo tee $FILESYSTEM_ROOT/etc/sonic/sonic_version.yml > /dev/null < files/Aboot/boot0 pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd pushd files/Aboot && zip -g $OLDPWD/$ABOOT_BOOT_IMAGE boot0; popd - echo "$GIT_REVISION" >> .imagehash + echo "$IMAGE_VERSION" >> .imagehash zip -g $OUTPUT_ABOOT_IMAGE .imagehash zip -g $ABOOT_BOOT_IMAGE .imagehash rm .imagehash diff --git a/dockers/docker-snmp-sv2/sysDescription.j2 b/dockers/docker-snmp-sv2/sysDescription.j2 index 54860a229d8b..648ed161046e 100644 --- a/dockers/docker-snmp-sv2/sysDescription.j2 +++ b/dockers/docker-snmp-sv2/sysDescription.j2 @@ -1 +1 @@ -SONiC Software Version: {{ build_version }}.SONiC.v2 - HwSku: {{ minigraph_hwsku }} - Distribution: Debian {{ debian_version }} - Kernel: {{ kernel_version }} +SONiC Software Version: SONiC.{{ build_version }} - HwSku: {{ minigraph_hwsku }} - Distribution: Debian {{ debian_version }} - Kernel: {{ kernel_version }} diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index ed9d7d0b5075..77fcd1f38655 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -125,13 +125,6 @@ sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf" # Copy SNMP configuration files sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/ -# Generate build version file -export git_revision=$(git rev-parse --short HEAD) -export debian_version=$(cat $FILESYSTEM_ROOT/etc/debian_version) -export kernel_version={{kversion}} -j2 $BUILD_TEMPLATES/sonic_version.yml.j2 > sonic_version.yml -sudo mv sonic_version.yml $FILESYSTEM_ROOT/etc/sonic/ - # Copy sudoers configuration file sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/ diff --git a/files/build_templates/sonic_version.yml.j2 b/files/build_templates/sonic_version.yml.j2 deleted file mode 100644 index 6eb8a6d6c5e4..000000000000 --- a/files/build_templates/sonic_version.yml.j2 +++ /dev/null @@ -1,5 +0,0 @@ -build_version: {{git_revision}} -debian_version: {{debian_version}} -kernel_version: {{kernel_version}} -asic_type: {{sonic_asic_platform}} - diff --git a/functions.sh b/functions.sh index b808f727278f..8b2cdb7c50dd 100644 --- a/functions.sh +++ b/functions.sh @@ -49,3 +49,18 @@ docker_try_rmi() { docker rmi $image_name } } + +sonic_get_version() { + local describe=$(git describe --tags) + local latest_tag=$(git describe --tags --abbrev=0) + if [ -n "$(git status --untracked-files=no -s --ignore-submodules)" ]; then + local dirty="-dirty" + fi + BUILD_NUMBER=${BUILD_NUMBER:-0} + ## Check if we are on tagged commit + if [ "$describe" == "$latest_tag" ]; then + echo "${latest_tag}${dirty}" + else + echo "${latest_tag}.${BUILD_NUMBER}${dirty:--$(git rev-parse --short HEAD)}" + fi +} diff --git a/rules/config b/rules/config index d016288e4776..dcfa40c7459e 100644 --- a/rules/config +++ b/rules/config @@ -11,10 +11,6 @@ # Uncomment next line to enable: # SONIC_CONFIG_PRINT_DEPENDENCIES = y -# DEBUG_BUILD - enable building image with uncommitted local changes. -# Uncomment next line to enable: -# DEBUG_BUILD = y - # SONIC_CONFIG_BUILD_JOBS - set number of jobs for parallel build. # Corresponding -j argument will be passed to make command inside docker # container. diff --git a/slave.mk b/slave.mk index 77967c858bdf..4f3761aa2263 100644 --- a/slave.mk +++ b/slave.mk @@ -26,6 +26,7 @@ PROJECT_ROOT = $(shell pwd) CONFIGURED_PLATFORM := $(shell [ -f .platform ] && cat .platform || echo generic) PLATFORM_PATH = platform/$(CONFIGURED_PLATFORM) +export BUILD_NUMBER ############################################################################### ## Utility rules @@ -342,7 +343,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform ) ./build_debian.sh "$(USERNAME)" "$(shell perl -e 'print crypt("$(PASSWORD)", "salt"),"\n"')" $(LOG) - TARGET_MACHINE=$($*_MACHINE) IMAGE_TYPE=$($*_IMAGE_TYPE) DEBUG_BUILD=$(DEBUG_BUILD) ./build_image.sh $(LOG) + TARGET_MACHINE=$($*_MACHINE) IMAGE_TYPE=$($*_IMAGE_TYPE) ./build_image.sh $(LOG) $(foreach docker, $($*_DOCKERS), \ rm -f $($(docker)_CONTAINER_NAME).sh diff --git a/sonic-slave/Dockerfile b/sonic-slave/Dockerfile index b8b31940a98d..bec18bfbaed7 100644 --- a/sonic-slave/Dockerfile +++ b/sonic-slave/Dockerfile @@ -110,6 +110,10 @@ RUN echo "DOCKER_OPTS=\"--experimental\"" >> /etc/default/docker ARG user ARG uid ARG guid +ARG hostname + +ENV BUILD_HOSTNAME $hostname +ENV USER $user RUN groupadd -f -r -g $guid g$user