Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,7 +37,7 @@ DOCKER_BUILD = docker build --no-cache \
-C sonic \
-f slave.mk \
PLATFORM=$(PLATFORM) \
DEBUG_BUILD=$(DEBUG_BUILD) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why DEBUG_BUILD option is removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is redundant. In case build contains local changes, "dirty" will be appended to version or used instead of git revision.

BUILD_NUMBER=$(BUILD_NUMBER) \
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to keep ENABLE_DHCP_GRAPH_SERVICE

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$@

Expand Down
11 changes: 11 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
build_version: $(sonic_get_version)
debian_version: $(cat $FILESYSTEM_ROOT/etc/debian_version)
kversion: $kversion
Copy link
Contributor

@taoyl-ms taoyl-ms Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the variable name?
If we do have a concrete reason to change the name, please update sysDescription.j2 in snmp docker as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree that it is probably better to keep prev name, kernel_version: $kversion

Copy link
Collaborator

@lguohan lguohan Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In sysDescription.j2, do we want to remove SONiC.v2 from {{ build_version }}.SONiC.v2? Or, maybe change to SONiC.{{build_version}}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kversion was a typo. Thanks for comment.

asic_type: $sonic_asic_platform
build_date: $(date -u)
built_by: $USER@$BUILD_HOSTNAME
EOF

if [ -f sonic_debian_extension.sh ]; then
./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR
fi
Expand Down
15 changes: 3 additions & 12 deletions build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@
exit 1
}

## Retrieval short version of Git revision hash for partition metadata
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
IMAGE_VERSION=$(. functions.sh && sonic_get_version)

if [ "$IMAGE_TYPE" = "onie" ]; then
echo "Build ONIE installer"
Expand All @@ -42,7 +33,7 @@ if [ "$IMAGE_TYPE" = "onie" ]; then
## Generate an ONIE installer image
## 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 \
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
## Use 'aboot' as target machine category which includes Aboot as bootloader
elif [ "$IMAGE_TYPE" = "aboot" ]; then
Expand All @@ -56,7 +47,7 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
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/$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
Expand Down
7 changes: 0 additions & 7 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
5 changes: 0 additions & 5 deletions files/build_templates/sonic_version.yml.j2

This file was deleted.

15 changes: 15 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 0 additions & 4 deletions rules/config
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sonic-slave/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down