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

Bin optimize #10718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kalimuthu-Velappan
Copy link
Contributor

Sonic image build optimization

The current SONIC build infrastructure always prepares the rootfs for final image generation.
Because of rootfs preparation, final image generation takes long regardless of SONiC changes.

The rootfs preparation consists of two parts.
Debian packages installation
Bootstrap preparation
General packages installation, such as curl, vim, sudo, python3, etc
Sonic packages installation
Packages that are built and installed from the sonic repo.
Docker images that are built and installed from the sonic repo

The build time can be optimized by generating the Debian packages as a base image and
it can be run in parallel with the other targets, before the final image.
Benefits:
- High hit rate, for fewer dependencies.
- Reduce the cache size.
- Improve the concurrency when the cache is not hit, the step has small dependencies and can be run with any other steps.
The docker load is also optimized by running in parallel.
Added support for gipz compression
Added tmpfs support for rootfs and final image generation.

Why I did it

How I did it

How to verify it

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@lgtm-com
Copy link

lgtm-com bot commented Apr 29, 2022

This pull request introduces 1 alert when merging 8c1df69b4b2748909ee6734a8491182b95e5ebf9 into 53e5fe6 - view on LGTM.com

new alerts:

  • 1 for Modification of parameter with default

Makefile.cache Outdated
Comment on lines 74 to 75
$(SONIC_VERSION_CONTROL_COMPONENTS) \
$(SONIC_VERSION_CACHE) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please fix the TAB/SPACE alignment issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Makefile.work Outdated
scripts/generate_buildinfo_config.sh)

# Generate the slave Dockerfile, and prepare build info for it
$(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) MULTIARCH_QEMU_ENVIRON=$(MULTIARCH_QEMU_ENVIRON) DOCKER_EXTRA_OPTS=$(DOCKER_EXTRA_OPTS) DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY) j2 $(SLAVE_DIR)/Dockerfile.j2 > $(SLAVE_DIR)/Dockerfile)
$(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) MULTIARCH_QEMU_ENVIRON=$(MULTIARCH_QEMU_ENVIRON) j2 $(SLAVE_DIR)/Dockerfile.user.j2 > $(SLAVE_DIR)/Dockerfile.user)
$(shell BUILD_SLAVE=y DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY) scripts/prepare_docker_buildinfo.sh $(SLAVE_BASE_IMAGE) $(SLAVE_DIR)/Dockerfile $(CONFIGURED_ARCH) "" $(BLDENV))
Copy link
Collaborator

Choose a reason for hiding this comment

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

It has impact on the value of SLAVE_BASE_TAG, we may need to run it before line 160.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -0,0 +1,25 @@
libhiredis-dev==0.14.0-3~bpo9+1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are the files in files/build/versions checked in by mistake? We will not enable reproducible build on master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean to remove all the files in files/build/versions.

@@ -668,8 +673,10 @@ sudo LANG=C DOCKER_HOST="$DOCKER_HOST" chroot $FILESYSTEM_ROOT docker info
{% set imagefilepath = image.split(':')|first -%}
{% set imagefilename = imagefilepath.split('/')|last -%}
{% set imagename = imagefilename.split('.')|first -%}
function {{imagename}}()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why dynamic function name? Can we use static function name and pass parameter instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 700 to 563
if [ ! -z "${USE_TMPFS}" ]; then
NPROC=$(nproc)
if [ ${NPROC} -gt 16 ]; then NPROC=16; fi
printf '%s\n' "${DLIST[@]}" | xargs -I{} -P ${NPROC} bash -c " SONIC_IMAGE_VERSION=${SONIC_IMAGE_VERSION} {}"
else
printf '%s\n' "${DLIST[@]}" | xargs -I{} -P 1 bash -c "SONIC_IMAGE_VERSION=${SONIC_IMAGE_VERSION} {}"
fi

Copy link
Collaborator

@xumia xumia May 5, 2022

Choose a reason for hiding this comment

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

Could you please improve the logic? The line 703 and 705 can be called only once.
Why there is a space chareacter in the command line before SONIC_IMAGE_VERSION in line 703, comparing to line 705?

NPROC=$(nproc)
[ $NPROC > 16 ]  && NPROC=16
[ In some conditions ] && NPROC=1
printf '%s\n' "${DLIST[@]}" | xargs -I{} -P ${NPROC}  bash -c " SONIC_IMAGE_VERSION=${SONIC_IMAGE_VERSION} {}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lgtm-com
Copy link

lgtm-com bot commented May 5, 2022

This pull request introduces 1 alert when merging d33da70678d70e9e095792d0c6ed289d91fd13f0 into 7c4ee43 - view on LGTM.com

new alerts:

  • 1 for Modification of parameter with default

@lgtm-com
Copy link

lgtm-com bot commented May 5, 2022

This pull request introduces 1 alert when merging 5a9bb2222fc70ca54f6fcd29092cc54a025b8c36 into db94886 - view on LGTM.com

new alerts:

  • 1 for Modification of parameter with default

Makefile.work Outdated

PREPARE_DOCKER=BUILD_SLAVE=y DBGOPT='$(DBGOPT)' SONIC_VERSION_CACHE=$(SONIC_VERSION_CACHE) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing one of the options of command scripts/prepare_docker_buildinfo.sh as below:

DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done as part of #10613

@xumia
Copy link
Collaborator

xumia commented May 6, 2022

@Kalimuthu-Velappan , can we split the PR into several small ones?

@Kalimuthu-Velappan
Copy link
Contributor Author

@Kalimuthu-Velappan , can we split the PR into several small ones?

It is already split into separate PR for version cache.
#10613

@Kalimuthu-Velappan
Copy link
Contributor Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

The current SONIC build infrastructure always prepares the rootfs for final image generation.
Because of rootfs preparation, final image generation takes long regardless of SONiC changes.

The rootfs preparation consists of two parts.
	Debian packages installation
		Bootstrap preparation
		General packages installation, such as curl, vim, sudo, python3, etc
	Sonic packages installation
		Packages that are built and installed from the sonic repo.
		Docker images that are built and installed from the sonic repo

The build time can be optimized by generating the Debian packages as a base image and
it can be run in parallel with the other targets, before the final image.
	Benefits:
		- High hit rate, for fewer dependencies.
		- Reduce the cache size.
		- Improve the concurrency when the cache is not hit, the step has small dependencies and can be run with any other steps.

Other enhancements:
	- The docker load is also optimized by running in parallel.
	- Added support for gipz compression
	- Added tmpfs support for rootfs and final image generation.
if $( unzip -l $ONIE_INSTALLER_PAYLOAD 2>/dev/null 1>/dev/null ); then
unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir
else
tar -C $demo_mnt/$image_dir -xvf $ONIE_INSTALLER_PAYLOAD
Copy link
Collaborator

@xumia xumia Apr 16, 2023

Choose a reason for hiding this comment

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

Do you add the new ONIE_INSTALLER_PAYLOAD format? Why need to handle the tar case? It is relative to new feature SONIC_FS_IMAGE_COMPRESSION_TYPE? If yes, suggest to send a new PR for the different feature.

Comment on lines +47 to +55
umount_allfs
delete_rootfs_image
if [[ -e ${FSROOT_IMAGE_FILE} ]]; then
return
fi

if [[ "${SONIC_USE_TMPFS_BUILD}" == "y" ]] ; then
sudo mount -t tmpfs -o size=${BUILD_TMP_ROOTFS_SIZE} tmpfs ${FSROOT_IMAGE_DIR}
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

If SONIC_USE_TMPFS_BUILD != y, all the options can be skipped, right? Do we need to check if SONIC_USE_TMPFS_BUILD == y before running the lines from 47~51?

Comment on lines +47 to +48
umount_allfs
delete_rootfs_image
Copy link
Collaborator

@xumia xumia Apr 16, 2023

Choose a reason for hiding this comment

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

Looks likes mount_imagefs does some additional cleanup operations? Can we remove them? Better to have another command to do the cleanup explicitly.

Comment on lines +316 to +320





Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the empty lines at the end of the script file, thanks.

rootfs)
rootfs_fun $1 $2
;;
overlayfs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not find any reference to overlayfs, can we remove it?

Comment on lines +148 to +151
#sudo mount -o rw,loop ${FSROOT_IMAGE_FILENAME} ${FILESYSTEM_BASE}/${FSROOT_IMAGE_FILENAME} || true
#sudo mkdir -p ${FILESYSTEM_BASE}/fsroot ${FILESYSTEM_BASE}/upper ${FILESYSTEM_BASE}/work
#sudo chmod 777 ${FILESYSTEM_BASE}
#sudo mount -t overlay overlay -o lowerdir=${FILESYSTEM_BASE}/${FSROOT_IMAGE_FILENAME},upperdir=${FILESYSTEM_BASE}/upper,workdir=${FILESYSTEM_BASE}/work ${FILESYSTEM_BASE}/fsroot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the no use lines?

## the ONIE installer image generation to speed up the processing.
##
## USAGE:
## ./tmpfs <storage> <operation>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The description looks like out of date, right? Change ./tmpfs to fsutil.sh? And the script does not only handle the tmpfs for different mount point, right?

@qiluo-msft
Copy link
Collaborator

@Kalimuthu-Velappan Could you resolve the conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants