From b9585ad47dd55a12592ea5c7a949029af322d561 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Mon, 6 Feb 2017 02:03:15 +0000 Subject: [PATCH] [docker]: change hardcoded value to DOCKERFS_DIR for docker directory on the disk --- build_debian.sh | 2 +- files/Aboot/boot0.j2 | 8 +++++--- .../{arista-convertfs => arista-convertfs.j2} | 2 +- files/initramfs-tools/{union-mount => union-mount.j2} | 2 +- installer/x86_64/install.sh | 2 +- onie-image.conf | 3 +++ slave.mk | 5 ++++- 7 files changed, 16 insertions(+), 8 deletions(-) rename files/initramfs-tools/{arista-convertfs => arista-convertfs.j2} (94%) rename files/initramfs-tools/{union-mount => union-mount.j2} (88%) diff --git a/build_debian.sh b/build_debian.sh index e113e6925107..76cd4467ce10 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -267,7 +267,7 @@ sudo du -hs $FILESYSTEM_ROOT sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker ## Compress docker files -pushd $FILESYSTEM_ROOT && sudo tar czf $OLDPWD/$FILESYSTEM_DOCKERFS var/lib/docker; popd +pushd $FILESYSTEM_ROOT && sudo tar czf $OLDPWD/$FILESYSTEM_DOCKERFS -C var/lib/docker .; popd ## Compress together with /boot and /var/lib/docker as an installer payload zip file pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/; popd diff --git a/files/Aboot/boot0.j2 b/files/Aboot/boot0.j2 index edd052450ed2..8ec50ef7f9e3 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -45,7 +45,7 @@ extract_image() { rm -rf "$target_path/rw" ## Clean docker directory - rm -rf "$target_path/var" + rm -rf "$target_path/{{ DOCKERFS_DIR }}" ## Unzip the image unzip -oq "$swipath" -x boot0 -d "$target_path" @@ -58,8 +58,10 @@ extract_image() { ## vfat does not support symbol link if [ $rootfs_type != "vfat" ]; then - ## Further extract docker archive - tar xf "$target_path/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path" + mkdir -p "$target_path/{{ DOCKERFS_DIR }}" + + ## extract docker archive + tar xf "$target_path/{{ FILESYSTEM_DOCKERFS }}" -C "$target_path/{{ DOCKERFS_DIR }}" ## clean up docker archive rm -f "$target_path/{{ FILESYSTEM_DOCKERFS }}" diff --git a/files/initramfs-tools/arista-convertfs b/files/initramfs-tools/arista-convertfs.j2 similarity index 94% rename from files/initramfs-tools/arista-convertfs rename to files/initramfs-tools/arista-convertfs.j2 index 676cbab4cc8b..8847bc69bdfa 100644 --- a/files/initramfs-tools/arista-convertfs +++ b/files/initramfs-tools/arista-convertfs.j2 @@ -165,7 +165,7 @@ cmd="mount -t ext4 $root_dev $root_mnt" run_cmd "$cmd" "$err_msg" err_msg="Error: extract docker directory" -cmd="[ -f $tmp_mnt/dockerfs.tar.gz ] && rm -rf $tmp_mnt/var && tar xzf $tmp_mnt/dockerfs.tar.gz -C $root_mnt && rm -f $tmp_mnt/dockerfs.tar.gz" +cmd="[ -f $tmp_mnt/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/{{ DOCKERFS_DIR }} && mkdir $root_mnt/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/{{ FILESYSTEM_DOCKERFS }}" run_cmd "$cmd" "$err_msg" err_msg="Error: copying files form $tmp_mnt to $root_mnt failed" diff --git a/files/initramfs-tools/union-mount b/files/initramfs-tools/union-mount.j2 similarity index 88% rename from files/initramfs-tools/union-mount rename to files/initramfs-tools/union-mount.j2 index b343d56c6e22..531436c39a2f 100644 --- a/files/initramfs-tools/union-mount +++ b/files/initramfs-tools/union-mount.j2 @@ -12,7 +12,7 @@ mount -n -o dirs=${rootmnt}/host/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt} mount ${ROOT} ${rootmnt}/host ## Mount the working directory of docker engine in the raw partition, bypass the aufs mkdir -p ${rootmnt}/var/lib/docker -mount --bind ${rootmnt}/host/var/lib/docker ${rootmnt}/var/lib/docker +mount --bind ${rootmnt}/host/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker ## Mount the boot directory in the raw partition, bypass the aufs mkdir -p ${rootmnt}/boot mount --bind ${rootmnt}/host/boot ${rootmnt}/boot diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index b8177462a55c..2ff663c188eb 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -398,7 +398,7 @@ ${onie_bin} mount -t ext4 -o defaults,rw $demo_dev $demo_mnt || { unzip $ONIE_INSTALLER_PAYLOAD -d $demo_mnt if [ -f $demo_mnt/$FILESYSTEM_DOCKERFS ]; then - cd $demo_mnt && tar xf $FILESYSTEM_DOCKERFS; cd $OLDPWD + cd $demo_mnt && mkdir -p $DOCKERFS_DIR && tar xf $FILESYSTEM_DOCKERFS -C $DOCKERFS_DIR; cd $OLDPWD fi # Store machine description in target file system diff --git a/onie-image.conf b/onie-image.conf index 70228bbf2498..f12e23f7414b 100644 --- a/onie-image.conf +++ b/onie-image.conf @@ -21,6 +21,9 @@ ONIE_INSTALLER_PAYLOAD=fs.zip ## Filename for docker file system FILESYSTEM_DOCKERFS=dockerfs.tar.gz +## docker directory on the root filesystem +DOCKERFS_DIR=docker + ## Output file name for onie installer OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin diff --git a/slave.mk b/slave.mk index 485f8ff9206c..68ed227cdc6a 100644 --- a/slave.mk +++ b/slave.mk @@ -285,7 +285,7 @@ $(DOCKER_LOAD_TARGETS) : $(TARGET_PATH)/%.gz-load : .platform docker-start $$(TA ############################################################################### # targets for building installers with base image -$(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform $$(addprefix $(DEBS_PATH)/,$$($$*_DEPENDS)) $(addprefix $(DEBS_PATH)/,$(INITRAMFS_TOOLS) $(LINUX_KERNEL) $(IGB_DRIVER)) $(addprefix $(DEBS_PATH)/,$(SONIC_CONFIG_ENGINE)) $$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) +$(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform onie-image.conf $$(addprefix $(DEBS_PATH)/,$$($$*_DEPENDS)) $(addprefix $(DEBS_PATH)/,$(INITRAMFS_TOOLS) $(LINUX_KERNEL) $(IGB_DRIVER)) $(addprefix $(DEBS_PATH)/,$(SONIC_CONFIG_ENGINE)) $$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) $(HEADER) ## Pass initramfs and linux kernel explicitly. They are used for all platforms export initramfs_tools="$(DEBS_PATH)/$(INITRAMFS_TOOLS)" @@ -310,6 +310,9 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform export installer_start_scrips="$(foreach docker, $($*_DOCKERS),$(addsuffix .sh, $($(docker)_CONTAINER_NAME)))" export installer_services="$(foreach docker, $($*_DOCKERS),$(addsuffix .service, $($(docker)_CONTAINER_NAME)))" + j2 -f env files/initramfs-tools/union-mount.j2 onie-image.conf > files/initramfs-tools/union-mount + j2 -f env files/initramfs-tools/arista-convertfs.j2 onie-image.conf > files/initramfs-tools/arista-convertfs + $(if $($*_DOCKERS), j2 files/build_templates/sonic_debian_extension.j2 > sonic_debian_extension.sh chmod +x sonic_debian_extension.sh,