Skip to content

Commit bc2e3a4

Browse files
[build]: Include SONiC version into installer.
Signed-off-by: marian-pritsak <[email protected]>
1 parent bd6976a commit bc2e3a4

File tree

9 files changed

+35
-32
lines changed

9 files changed

+35
-32
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DOCKER_BUILD = docker build --no-cache \
2020
--build-arg user=$(USER) \
2121
--build-arg uid=$(shell id -u) \
2222
--build-arg guid=$(shell id -g) \
23+
--build-arg hostname=$(shell echo $$HOSTNAME) \
2324
-t $(SLAVE_IMAGE) \
2425
sonic-slave && \
2526
docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG)
@@ -36,8 +37,7 @@ DOCKER_BUILD = docker build --no-cache \
3637
-C sonic \
3738
-f slave.mk \
3839
PLATFORM=$(PLATFORM) \
39-
DEBUG_BUILD=$(DEBUG_BUILD) \
40-
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
40+
BUILD_NUMBER=$(BUILD_NUMBER) \
4141
$@
4242

4343
sonic-slave-build :

build_debian.sh

+11
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ sudo cp files/dhcp/graphserviceurl $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks
257257
sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
258258
sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/
259259

260+
## Version file
261+
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic
262+
sudo tee $FILESYSTEM_ROOT/etc/sonic/sonic_version.yml > /dev/null <<EOF
263+
build_version: $(sonic_get_version)
264+
debian_version: $(cat $FILESYSTEM_ROOT/etc/debian_version)
265+
kversion: $kversion
266+
asic_type: $sonic_asic_platform
267+
build_date: $(date -u)
268+
built_by: $USER@$BUILD_HOSTNAME
269+
EOF
270+
260271
if [ -f sonic_debian_extension.sh ]; then
261272
./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR
262273
fi

build_image.sh

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@
1212
exit 1
1313
}
1414

15-
## Retrieval short version of Git revision hash for partition metadata
16-
if [ -z "$(git status --untracked-files=no -s --ignore-submodules)" ]; then
17-
GIT_REVISION=$(git rev-parse --short HEAD)
18-
elif [ ! "$DEBUG_BUILD" = "y" ]; then
19-
echo "Error: There are local changes not committed to git repo. Cannot get a revision hash for partition metadata."
20-
exit 1
21-
else
22-
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."
23-
GIT_REVISION=$(git rev-parse --short HEAD)"_local_debug"
24-
fi
15+
IMAGE_VERSION=$(. functions.sh && sonic_get_version)
2516

2617
if [ "$IMAGE_TYPE" = "onie" ]; then
2718
echo "Build ONIE installer"
@@ -42,7 +33,7 @@ if [ "$IMAGE_TYPE" = "onie" ]; then
4233
## Generate an ONIE installer image
4334
## Note: Don't leave blank between lines. It is single line command.
4435
./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \
45-
installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $GIT_REVISION $ONIE_IMAGE_PART_SIZE \
36+
installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $IMAGE_VERSION $ONIE_IMAGE_PART_SIZE \
4637
$ONIE_INSTALLER_PAYLOAD
4738
## Use 'aboot' as target machine category which includes Aboot as bootloader
4839
elif [ "$IMAGE_TYPE" = "aboot" ]; then
@@ -56,7 +47,7 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
5647
j2 -f env files/Aboot/boot0.j2 ./onie-image.conf > files/Aboot/boot0
5748
pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd
5849
pushd files/Aboot && zip -g $OLDPWD/$ABOOT_BOOT_IMAGE boot0; popd
59-
echo "$GIT_REVISION" >> .imagehash
50+
echo "$IMAGE_VERSION" >> .imagehash
6051
zip -g $OUTPUT_ABOOT_IMAGE .imagehash
6152
zip -g $ABOOT_BOOT_IMAGE .imagehash
6253
rm .imagehash

files/build_templates/sonic_debian_extension.j2

-7
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
125125
# Copy SNMP configuration files
126126
sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/
127127

128-
# Generate build version file
129-
export git_revision=$(git rev-parse --short HEAD)
130-
export debian_version=$(cat $FILESYSTEM_ROOT/etc/debian_version)
131-
export kernel_version={{kversion}}
132-
j2 $BUILD_TEMPLATES/sonic_version.yml.j2 > sonic_version.yml
133-
sudo mv sonic_version.yml $FILESYSTEM_ROOT/etc/sonic/
134-
135128
# Copy sudoers configuration file
136129
sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/
137130

files/build_templates/sonic_version.yml.j2

-5
This file was deleted.

functions.sh

+12
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ docker_try_rmi() {
4949
docker rmi $image_name
5050
}
5151
}
52+
53+
sonic_get_version() {
54+
local describe=$(git describe --tags)
55+
local latest_tag=$(git describe --tags --abbrev=0)
56+
BUILD_NUMBER=${BUILD_NUMBER:-dev}
57+
## Cehck if we are on tagged commit
58+
if [ "$describe" == "$latest_tag" ]; then
59+
echo "$latest_tag"
60+
else
61+
echo "${latest_tag}.${BUILD_NUMBER}-$(git rev-parse --short HEAD)"
62+
fi
63+
}

rules/config

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
# Uncomment next line to enable:
1212
# SONIC_CONFIG_PRINT_DEPENDENCIES = y
1313

14-
# DEBUG_BUILD - enable building image with uncommitted local changes.
15-
# Uncomment next line to enable:
16-
# DEBUG_BUILD = y
17-
1814
# SONIC_CONFIG_BUILD_JOBS - set number of jobs for parallel build.
1915
# Corresponding -j argument will be passed to make command inside docker
2016
# container.
21-
SONIC_CONFIG_BUILD_JOBS = 1
17+
SONIC_CONFIG_BUILD_JOBS = 12
2218

2319
# SONIC_CONFIG_LOG_TO_FILES - print output from execution of rule for each
2420
# target into separate log file under target/log/.

slave.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ PROJECT_ROOT = $(shell pwd)
2626

2727
CONFIGURED_PLATFORM := $(shell [ -f .platform ] && cat .platform || echo generic)
2828
PLATFORM_PATH = platform/$(CONFIGURED_PLATFORM)
29+
export BUILD_NUMBER
2930

3031
###############################################################################
3132
## Utility rules
@@ -342,7 +343,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform
342343
)
343344

344345
./build_debian.sh "$(USERNAME)" "$(shell perl -e 'print crypt("$(PASSWORD)", "salt"),"\n"')" $(LOG)
345-
TARGET_MACHINE=$($*_MACHINE) IMAGE_TYPE=$($*_IMAGE_TYPE) DEBUG_BUILD=$(DEBUG_BUILD) ./build_image.sh $(LOG)
346+
TARGET_MACHINE=$($*_MACHINE) IMAGE_TYPE=$($*_IMAGE_TYPE) ./build_image.sh $(LOG)
346347

347348
$(foreach docker, $($*_DOCKERS), \
348349
rm -f $($(docker)_CONTAINER_NAME).sh

sonic-slave/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ RUN echo "DOCKER_OPTS=\"--experimental\"" >> /etc/default/docker
110110
ARG user
111111
ARG uid
112112
ARG guid
113+
ARG hostname
114+
115+
ENV BUILD_HOSTNAME $hostname
116+
ENV USER $user
113117

114118
RUN groupadd -f -r -g $guid g$user
115119

0 commit comments

Comments
 (0)