[build]: Include SONiC version into installer. (#472)

* [build]: Include SONiC version into installer.

Signed-off-by: marian-pritsak <marianp@mellanox.com>

* Append dirty if contains local changes

Signed-off-by: marian-pritsak <marianp@mellanox.com>

* Update config

* Use correct name for kernel version field

* Update sysDescription.j2
This commit is contained in:
Marian Pritsak 2017-04-06 02:14:41 +03:00 committed by lguohan
parent 803c530adf
commit 6dbe979e5f
10 changed files with 38 additions and 31 deletions

View File

@ -20,6 +20,7 @@ DOCKER_BUILD = docker build --no-cache \
--build-arg user=$(USER) \ --build-arg user=$(USER) \
--build-arg uid=$(shell id -u) \ --build-arg uid=$(shell id -u) \
--build-arg guid=$(shell id -g) \ --build-arg guid=$(shell id -g) \
--build-arg hostname=$(shell echo $$HOSTNAME) \
-t $(SLAVE_IMAGE) \ -t $(SLAVE_IMAGE) \
sonic-slave && \ sonic-slave && \
docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG) docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG)
@ -36,7 +37,7 @@ DOCKER_BUILD = docker build --no-cache \
-C sonic \ -C sonic \
-f slave.mk \ -f slave.mk \
PLATFORM=$(PLATFORM) \ PLATFORM=$(PLATFORM) \
DEBUG_BUILD=$(DEBUG_BUILD) \ BUILD_NUMBER=$(BUILD_NUMBER) \
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \ ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
$@ $@

View File

@ -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/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/ 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 <<EOF
build_version: $(sonic_get_version)
debian_version: $(cat $FILESYSTEM_ROOT/etc/debian_version)
kernel_version: $kversion
asic_type: $sonic_asic_platform
build_date: $(date -u)
built_by: $USER@$BUILD_HOSTNAME
EOF
if [ -f sonic_debian_extension.sh ]; then if [ -f sonic_debian_extension.sh ]; then
./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR
fi fi

View File

@ -12,16 +12,7 @@
exit 1 exit 1
} }
## Retrieval short version of Git revision hash for partition metadata IMAGE_VERSION=$(. functions.sh && sonic_get_version)
if [ -z "$(git status --untracked-files=no -s --ignore-submodules)" ]; then
GIT_REVISION=$(git rev-parse --short HEAD)
elif [ ! "$DEBUG_BUILD" = "y" ]; then
echo "Error: There are local changes not committed to git repo. Cannot get a revision hash for partition metadata."
exit 1
else
echo "Warning: There are local changes not committed to git repo, revision hash won't be tracked. Never deploy this image for other than debugging purpose."
GIT_REVISION=$(git rev-parse --short HEAD)"_local_debug"
fi
if [ "$IMAGE_TYPE" = "onie" ]; then if [ "$IMAGE_TYPE" = "onie" ]; then
echo "Build ONIE installer" echo "Build ONIE installer"
@ -42,7 +33,7 @@ if [ "$IMAGE_TYPE" = "onie" ]; then
## Generate an ONIE installer image ## Generate an ONIE installer image
## Note: Don't leave blank between lines. It is single line command. ## Note: Don't leave blank between lines. It is single line command.
./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \ ./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \
installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $GIT_REVISION $ONIE_IMAGE_PART_SIZE \ installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $IMAGE_VERSION $ONIE_IMAGE_PART_SIZE \
$ONIE_INSTALLER_PAYLOAD $ONIE_INSTALLER_PAYLOAD
## Use 'aboot' as target machine category which includes Aboot as bootloader ## Use 'aboot' as target machine category which includes Aboot as bootloader
elif [ "$IMAGE_TYPE" = "aboot" ]; then elif [ "$IMAGE_TYPE" = "aboot" ]; then
@ -56,7 +47,7 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
j2 -f env files/Aboot/boot0.j2 ./onie-image.conf > files/Aboot/boot0 j2 -f env files/Aboot/boot0.j2 ./onie-image.conf > files/Aboot/boot0
pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd
pushd files/Aboot && zip -g $OLDPWD/$ABOOT_BOOT_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 $OUTPUT_ABOOT_IMAGE .imagehash
zip -g $ABOOT_BOOT_IMAGE .imagehash zip -g $ABOOT_BOOT_IMAGE .imagehash
rm .imagehash rm .imagehash

View File

@ -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 }}

View File

@ -125,13 +125,6 @@ sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
# Copy SNMP configuration files # Copy SNMP configuration files
sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/ 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 # Copy sudoers configuration file
sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/ sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/

View File

@ -1,5 +0,0 @@
build_version: {{git_revision}}
debian_version: {{debian_version}}
kernel_version: {{kernel_version}}
asic_type: {{sonic_asic_platform}}

View File

@ -49,3 +49,18 @@ docker_try_rmi() {
docker rmi $image_name 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
}

View File

@ -11,10 +11,6 @@
# Uncomment next line to enable: # Uncomment next line to enable:
# SONIC_CONFIG_PRINT_DEPENDENCIES = y # 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. # SONIC_CONFIG_BUILD_JOBS - set number of jobs for parallel build.
# Corresponding -j argument will be passed to make command inside docker # Corresponding -j argument will be passed to make command inside docker
# container. # container.

View File

@ -26,6 +26,7 @@ PROJECT_ROOT = $(shell pwd)
CONFIGURED_PLATFORM := $(shell [ -f .platform ] && cat .platform || echo generic) CONFIGURED_PLATFORM := $(shell [ -f .platform ] && cat .platform || echo generic)
PLATFORM_PATH = platform/$(CONFIGURED_PLATFORM) PLATFORM_PATH = platform/$(CONFIGURED_PLATFORM)
export BUILD_NUMBER
############################################################################### ###############################################################################
## Utility rules ## 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) ./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), \ $(foreach docker, $($*_DOCKERS), \
rm -f $($(docker)_CONTAINER_NAME).sh rm -f $($(docker)_CONTAINER_NAME).sh

View File

@ -110,6 +110,10 @@ RUN echo "DOCKER_OPTS=\"--experimental\"" >> /etc/default/docker
ARG user ARG user
ARG uid ARG uid
ARG guid ARG guid
ARG hostname
ENV BUILD_HOSTNAME $hostname
ENV USER $user
RUN groupadd -f -r -g $guid g$user RUN groupadd -f -r -g $guid g$user