From d9fa9f3bb79eeb6f83b8bc62e78b64e52cafa503 Mon Sep 17 00:00:00 2001 From: DCCooper <1866858@gmail.com> Date: Wed, 10 Nov 2021 10:16:22 +0800 Subject: [PATCH] isula-build: add log info for layers processing Signed-off-by: DCCooper <1866858@gmail.com> --- VERSION-openeuler | 2 +- git-commit | 2 +- isula-build.spec | 8 +- ...log-info-to-show-the-image-layer-num.patch | 117 ++++++++++++++++++ series.conf | 1 + 5 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 patch/0090-enhancement-add-log-info-to-show-the-image-layer-num.patch diff --git a/VERSION-openeuler b/VERSION-openeuler index 1021efb..e25a04f 100644 --- a/VERSION-openeuler +++ b/VERSION-openeuler @@ -1 +1 @@ -0.9.5-19 +0.9.5-20 diff --git a/git-commit b/git-commit index f9f564e..5f58d59 100644 --- a/git-commit +++ b/git-commit @@ -1 +1 @@ -d69cf1b4393964819a1515a5399c1a2ac10c8d03 +91914cb21b35c8fb6f19bffb964cbf339b2db424 diff --git a/isula-build.spec b/isula-build.spec index 2664d08..ea42309 100644 --- a/isula-build.spec +++ b/isula-build.spec @@ -2,7 +2,7 @@ Name: isula-build Version: 0.9.5 -Release: 19 +Release: 20 Summary: A tool to build container images License: Mulan PSL V2 URL: https://gitee.com/openeuler/isula-build @@ -85,6 +85,12 @@ fi /usr/share/bash-completion/completions/isula-build %changelog +* Wed Nov 10 2021 DCCooper <1866858@gmail.com> - 0.9.5-20 +- Type:enhancement +- CVE:NA +- SUG:restart +- DESC:add log info for layers processing + * Thu Nov 04 2021 DCCooper <1866858@gmail.com> - 0.9.5-19 - Type:bugfix - CVE:NA diff --git a/patch/0090-enhancement-add-log-info-to-show-the-image-layer-num.patch b/patch/0090-enhancement-add-log-info-to-show-the-image-layer-num.patch new file mode 100644 index 0000000..c2e1262 --- /dev/null +++ b/patch/0090-enhancement-add-log-info-to-show-the-image-layer-num.patch @@ -0,0 +1,117 @@ +From 38bed99e8cb58ad3c7fe0ef386c66c558d16b569 Mon Sep 17 00:00:00 2001 +From: DCCooper <1866858@gmail.com> +Date: Tue, 9 Nov 2021 19:18:45 +0800 +Subject: [PATCH] enhancement: add log info to show the image layer number + +reason: when save separated image, the layer number should be +printed out into log + +Signed-off-by: DCCooper <1866858@gmail.com> +--- + daemon/save.go | 18 +++++++++++++----- + hack/unit_test.sh | 6 ++++-- + 2 files changed, 17 insertions(+), 7 deletions(-) + +diff --git a/daemon/save.go b/daemon/save.go +index 9c5e563..f14a485 100644 +--- a/daemon/save.go ++++ b/daemon/save.go +@@ -139,7 +139,7 @@ type tarballInfo struct { + BaseTarName string `json:"base"` + BaseHash string `json:"baseHash"` + BaseImageName string `json:"baseImageName"` +- BaseLayers []string `json:"baseLayer"` ++ BaseLayer string `json:"baseLayer"` + } + + func (b *Backend) getSaveOptions(req *pb.SaveRequest) saveOptions { +@@ -381,7 +381,7 @@ func (opts *saveOptions) checkRenameFile() error { + return nil + } + +-func getLayerHashFromStorage(store *store.Store, name string) ([]string, error) { ++func (s *separatorSave) getLayerHashFromStorage(store *store.Store, name string) ([]string, error) { + if len(name) == 0 { + return nil, nil + } +@@ -632,8 +632,11 @@ func (info imageInfo) processTarName(suffix string) string { + func (info *imageInfo) processBaseImg(sep *separatorSave, baseImagesMap map[string]string, tarball *tarballInfo) error { + // process base + tarball.BaseImageName = sep.base ++ if len(info.layers.base) != 0 { ++ sep.log.Infof("Base image %s has %d layers", sep.base, len(info.layers.base)) ++ tarball.BaseLayer = info.layers.base[0] ++ } + for _, layerID := range info.layers.base { +- tarball.BaseLayers = append(tarball.BaseLayers, layerID) + if baseImg, ok := baseImagesMap[layerID]; !ok { + srcLayerPath := filepath.Join(sep.tmpDir.untar, layerID) + destLayerPath := filepath.Join(sep.tmpDir.base, layerID) +@@ -673,6 +676,7 @@ func (info *imageInfo) processLibImg(sep *separatorSave, libImagesMap map[string + } + + tarball.LibImageName = sep.lib ++ sep.log.Infof("Lib image %s has %d layers", sep.lib, len(info.layers.lib)) + for _, layerID := range info.layers.lib { + tarball.LibLayers = append(tarball.LibLayers, layerID) + if libImg, ok := libImagesMap[layerID]; !ok { +@@ -709,6 +713,7 @@ func (info *imageInfo) processLibImg(sep *separatorSave, libImagesMap map[string + + func (info *imageInfo) processAppImg(sep *separatorSave, appImagesMap map[string]string, tarball *tarballInfo) error { + // process app ++ sep.log.Infof("App image %s has %d layers", info.nameTag, len(info.layers.app)) + appTarName := info.processTarName(appTarNameSuffix) + appTarName = sep.rename(appTarName) + appTarPath := filepath.Join(sep.dest, appTarName) +@@ -834,14 +839,17 @@ func (s *separatorSave) constructSingleImgInfo(mani imageManifest, store *store. + } + + func (s *separatorSave) checkLayersHash(layerHashMap map[string]string, store *store.Store) ([]string, []string, error) { +- libHash, err := getLayerHashFromStorage(store, s.lib) ++ libHash, err := s.getLayerHashFromStorage(store, s.lib) + if err != nil { + return nil, nil, errors.Wrapf(err, "get lib image %s layers failed", s.lib) + } +- baseHash, err := getLayerHashFromStorage(store, s.base) ++ baseHash, err := s.getLayerHashFromStorage(store, s.base) + if err != nil { + return nil, nil, errors.Wrapf(err, "get base image %s layers failed", s.base) + } ++ if len(baseHash) > 1 { ++ return nil, nil, errors.Errorf("number of base layers %d more than one", len(baseHash)) ++ } + if len(libHash) >= len(layerHashMap) || len(baseHash) >= len(layerHashMap) { + return nil, nil, errors.Errorf("number of base or lib layers is equal or greater than saved app layers") + } +diff --git a/hack/unit_test.sh b/hack/unit_test.sh +index 161feb6..b6a7978 100755 +--- a/hack/unit_test.sh ++++ b/hack/unit_test.sh +@@ -28,6 +28,8 @@ go_test_mod_method="-mod=vendor" + go_test_count_method="-count=1" + go_test_timeout_flag="-timeout=300s" + go_test_race_flag="-race" ++go_test_covermode_flag="-covermode=atomic" ++go_test_coverprofile_flag="-coverprofile=/dev/null" + + function precheck() { + if pgrep isula-builder > /dev/null 2>&1; then +@@ -54,13 +56,13 @@ function run_unit_test() { + echo "Start to test: ${package}" + if [[ -n ${run_coverage} ]]; then + coverprofile_file="${covers_folder}/$(echo "${package}" | tr / -).cover" +- coverprofile_flag="-coverprofile=${coverprofile_file}" ++ go_test_coverprofile_flag="-coverprofile=${coverprofile_file}" + go_test_covermode_flag="-covermode=set" + go_test_race_flag="" + fi + # TEST_ARGS is " -args SKIP_REG=foo", so no double quote for it + # shellcheck disable=SC2086 +- go test -v ${go_test_race_flag} "${go_test_mod_method}" ${coverprofile_flag} "${go_test_covermode_flag}" -coverpkg=${package} "${go_test_count_method}" "${go_test_timeout_flag}" "${package}" ${TEST_ARGS} >> "${testlog}" ++ go test -v "${go_test_race_flag}" "${go_test_mod_method}" "${go_test_coverprofile_flag}" "${go_test_covermode_flag}" -coverpkg=${package} "${go_test_count_method}" "${go_test_timeout_flag}" "${package}" ${TEST_ARGS} >> "${testlog}" + done + + if grep -E -- "--- FAIL:|^FAIL" "${testlog}"; then +-- +1.8.3.1 + diff --git a/series.conf b/series.conf index 6373b64..73a13ef 100644 --- a/series.conf +++ b/series.conf @@ -52,3 +52,4 @@ patch/0086-bugfix-fix-random-sequence-for-saving-separated-imag.patch patch/0087-bugfix-optimize-function-IsExist.patch patch/0088-bugfix-loaded-images-cover-existing-images-name-and-.patch patch/0089-isula-build-fix-panic-when-using-image-ID-to-save-se.patch +patch/0090-enhancement-add-log-info-to-show-the-image-layer-num.patch