!234 isula-build: sync upstream patches
From: @meilier Reviewed-by: @jingxiaolu Signed-off-by: @jingxiaolu
This commit is contained in:
commit
7f6abe5f61
@ -1 +1 @@
|
||||
0.9.6-6
|
||||
0.9.6-8
|
||||
|
||||
@ -1 +1 @@
|
||||
e3a0acf9c3f50e99364a9ad70f9d40c4bf473feb
|
||||
34d92aa8caa0087e95ce28c4ca4ca2c347a028f7
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
Name: isula-build
|
||||
Version: 0.9.6
|
||||
Release: 7
|
||||
Release: 8
|
||||
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 Jun 15 2022 xingweizheng <xingweizheng@huawei.com> - 0.9.6-8
|
||||
- Type:bugfix
|
||||
- CVE:NA
|
||||
- SUG:restart
|
||||
- DESC:sync upstream patches
|
||||
|
||||
* Thu May 26 2022 loong_C <loong_c@yeah.net> - 0.9.6-7
|
||||
- fix spec changelog date
|
||||
|
||||
|
||||
@ -0,0 +1,274 @@
|
||||
From b45f5dbf100dff914c8f729e049ecaf26073030e Mon Sep 17 00:00:00 2001
|
||||
From: Lu Jingxiao <lujingxiao@huawei.com>
|
||||
Date: Tue, 4 Jan 2022 15:55:35 +0800
|
||||
Subject: [PATCH 01/20] isula-build: update go version in go.mod and README to
|
||||
1.15
|
||||
|
||||
After upgrade vendor, the required go version is 1.15 or later.
|
||||
|
||||
Fixes: #I4KE3A
|
||||
|
||||
Signed-off-by: Lu Jingxiao <lujingxiao@huawei.com>
|
||||
---
|
||||
README.md | 2 +-
|
||||
README.zh.md | 2 +-
|
||||
go.mod | 2 +-
|
||||
vendor/modules.txt | 33 +++++++++++++++++++++++++++++++++
|
||||
4 files changed, 36 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/README.md b/README.md
|
||||
index 8c09b1b..a864363 100644
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -39,7 +39,7 @@ In addition, the following capabilities are also provided:
|
||||
For compiling from source on openEuler, these packages are required on your OS:
|
||||
|
||||
- make
|
||||
-- golang (version 1.13 or later)
|
||||
+- golang (version 1.15 or later)
|
||||
- btrfs-progs-devel
|
||||
- device-mapper-devel
|
||||
- glib2-devel
|
||||
diff --git a/README.zh.md b/README.zh.md
|
||||
index 15301c0..e9c2747 100644
|
||||
--- a/README.zh.md
|
||||
+++ b/README.zh.md
|
||||
@@ -41,7 +41,7 @@ isula-build提供的命令行工具提供了很多功能,例如:
|
||||
为了顺利从源码编译,以下包需要被安装在你的操作系统中:
|
||||
|
||||
- make
|
||||
-- golang(大于等于1.13版本)
|
||||
+- golang(大于等于1.15版本)
|
||||
- btrfs-progs-devel
|
||||
- device-mapper-devel
|
||||
- glib2-devel
|
||||
diff --git a/go.mod b/go.mod
|
||||
index f60eeea..dbf9426 100644
|
||||
--- a/go.mod
|
||||
+++ b/go.mod
|
||||
@@ -1,6 +1,6 @@
|
||||
module isula.org/isula-build
|
||||
|
||||
-go 1.13
|
||||
+go 1.15
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.4.1
|
||||
diff --git a/vendor/modules.txt b/vendor/modules.txt
|
||||
index 660de5e..ec0b737 100644
|
||||
--- a/vendor/modules.txt
|
||||
+++ b/vendor/modules.txt
|
||||
@@ -1,4 +1,5 @@
|
||||
# github.com/BurntSushi/toml v0.4.1
|
||||
+## explicit
|
||||
github.com/BurntSushi/toml
|
||||
github.com/BurntSushi/toml/internal
|
||||
# github.com/Microsoft/go-winio v0.5.0
|
||||
@@ -35,8 +36,10 @@ github.com/acarl005/stripansi
|
||||
# github.com/beorn7/perks v1.0.1
|
||||
github.com/beorn7/perks/quantile
|
||||
# github.com/blang/semver v4.0.0+incompatible
|
||||
+## explicit
|
||||
github.com/blang/semver
|
||||
# github.com/bndr/gotabulate v1.1.3-0.20210209140214-21a495b00e22
|
||||
+## explicit
|
||||
github.com/bndr/gotabulate
|
||||
# github.com/cespare/xxhash/v2 v2.1.1
|
||||
github.com/cespare/xxhash/v2
|
||||
@@ -45,6 +48,7 @@ github.com/containerd/cgroups/stats/v1
|
||||
# github.com/containerd/console v1.0.2
|
||||
github.com/containerd/console
|
||||
# github.com/containerd/containerd v1.5.8
|
||||
+## explicit
|
||||
github.com/containerd/containerd/errdefs
|
||||
github.com/containerd/containerd/log
|
||||
github.com/containerd/containerd/pkg/userns
|
||||
@@ -52,11 +56,13 @@ github.com/containerd/containerd/platforms
|
||||
github.com/containerd/containerd/sys
|
||||
github.com/containerd/containerd/sys/reaper
|
||||
# github.com/containerd/go-runc v1.0.0
|
||||
+## explicit
|
||||
github.com/containerd/go-runc
|
||||
# github.com/containerd/stargz-snapshotter/estargz v0.9.0
|
||||
github.com/containerd/stargz-snapshotter/estargz
|
||||
github.com/containerd/stargz-snapshotter/estargz/errorutil
|
||||
# github.com/containers/image/v5 v5.17.0
|
||||
+## explicit
|
||||
github.com/containers/image/v5/copy
|
||||
github.com/containers/image/v5/directory
|
||||
github.com/containers/image/v5/directory/explicitfilepath
|
||||
@@ -104,6 +110,7 @@ github.com/containers/image/v5/transports/alltransports
|
||||
github.com/containers/image/v5/types
|
||||
github.com/containers/image/v5/version
|
||||
# github.com/containers/libtrust v0.0.0-20200511145503-9c3a6c22cd9a
|
||||
+## explicit
|
||||
github.com/containers/libtrust
|
||||
# github.com/containers/ocicrypt v1.1.2
|
||||
github.com/containers/ocicrypt
|
||||
@@ -121,6 +128,7 @@ github.com/containers/ocicrypt/spec
|
||||
github.com/containers/ocicrypt/utils
|
||||
github.com/containers/ocicrypt/utils/keyprovider
|
||||
# github.com/containers/storage v1.37.0
|
||||
+## explicit
|
||||
github.com/containers/storage
|
||||
github.com/containers/storage/drivers
|
||||
github.com/containers/storage/drivers/aufs
|
||||
@@ -166,10 +174,13 @@ github.com/containers/storage/pkg/truncindex
|
||||
github.com/containers/storage/pkg/unshare
|
||||
github.com/containers/storage/types
|
||||
# github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
|
||||
+## explicit
|
||||
github.com/coreos/go-systemd/daemon
|
||||
# github.com/cyphar/filepath-securejoin v0.2.3
|
||||
+## explicit
|
||||
github.com/cyphar/filepath-securejoin
|
||||
# github.com/docker/distribution v2.7.1+incompatible
|
||||
+## explicit
|
||||
github.com/docker/distribution
|
||||
github.com/docker/distribution/digestset
|
||||
github.com/docker/distribution/metrics
|
||||
@@ -182,6 +193,7 @@ github.com/docker/distribution/registry/client/transport
|
||||
github.com/docker/distribution/registry/storage/cache
|
||||
github.com/docker/distribution/registry/storage/cache/memory
|
||||
# github.com/docker/docker v20.10.11+incompatible
|
||||
+## explicit
|
||||
github.com/docker/docker/api
|
||||
github.com/docker/docker/api/types
|
||||
github.com/docker/docker/api/types/blkiodev
|
||||
@@ -215,14 +227,17 @@ github.com/docker/go-metrics
|
||||
# github.com/docker/go-units v0.4.0
|
||||
github.com/docker/go-units
|
||||
# github.com/docker/libnetwork v0.8.0-dev.2.0.20190625141545-5a177b73e316
|
||||
+## explicit
|
||||
github.com/docker/libnetwork/resolvconf
|
||||
github.com/docker/libnetwork/resolvconf/dns
|
||||
github.com/docker/libnetwork/types
|
||||
# github.com/ghodss/yaml v1.0.0
|
||||
github.com/ghodss/yaml
|
||||
# github.com/gofrs/flock v0.8.1
|
||||
+## explicit
|
||||
github.com/gofrs/flock
|
||||
# github.com/gogo/protobuf v1.3.2
|
||||
+## explicit
|
||||
github.com/gogo/protobuf/gogoproto
|
||||
github.com/gogo/protobuf/proto
|
||||
github.com/gogo/protobuf/protoc-gen-gogo/descriptor
|
||||
@@ -257,6 +272,7 @@ github.com/imdario/mergo
|
||||
# github.com/inconshreveable/mousetrap v1.0.0
|
||||
github.com/inconshreveable/mousetrap
|
||||
# github.com/ishidawataru/sctp v0.0.0-20191218070446-00ab2ac2db07
|
||||
+## explicit
|
||||
github.com/ishidawataru/sctp
|
||||
# github.com/json-iterator/go v1.1.12
|
||||
github.com/json-iterator/go
|
||||
@@ -282,6 +298,8 @@ github.com/miekg/pkcs11
|
||||
github.com/mistifyio/go-zfs
|
||||
# github.com/moby/sys/mountinfo v0.4.1
|
||||
github.com/moby/sys/mountinfo
|
||||
+# github.com/moby/term v0.0.0-20201216013528-df9cb8a40635
|
||||
+## explicit
|
||||
# github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
|
||||
github.com/modern-go/concurrent
|
||||
# github.com/modern-go/reflect2 v1.0.2
|
||||
@@ -289,16 +307,20 @@ github.com/modern-go/reflect2
|
||||
# github.com/mtrmac/gpgme v0.1.2
|
||||
github.com/mtrmac/gpgme
|
||||
# github.com/opencontainers/go-digest v1.0.0
|
||||
+## explicit
|
||||
github.com/opencontainers/go-digest
|
||||
# github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283
|
||||
+## explicit
|
||||
github.com/opencontainers/image-spec/specs-go
|
||||
github.com/opencontainers/image-spec/specs-go/v1
|
||||
# github.com/opencontainers/runc v1.0.2
|
||||
github.com/opencontainers/runc/libcontainer/user
|
||||
github.com/opencontainers/runc/libcontainer/userns
|
||||
# github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
|
||||
+## explicit
|
||||
github.com/opencontainers/runtime-spec/specs-go
|
||||
# github.com/opencontainers/runtime-tools v0.9.0
|
||||
+## explicit
|
||||
github.com/opencontainers/runtime-tools/error
|
||||
github.com/opencontainers/runtime-tools/filepath
|
||||
github.com/opencontainers/runtime-tools/generate
|
||||
@@ -314,6 +336,7 @@ github.com/opencontainers/selinux/pkg/pwalkdir
|
||||
github.com/ostreedev/ostree-go/pkg/glibobject
|
||||
github.com/ostreedev/ostree-go/pkg/otbuiltin
|
||||
# github.com/pkg/errors v0.9.1
|
||||
+## explicit
|
||||
github.com/pkg/errors
|
||||
# github.com/prometheus/client_golang v1.7.1
|
||||
github.com/prometheus/client_golang/prometheus
|
||||
@@ -322,6 +345,7 @@ github.com/prometheus/client_golang/prometheus/promhttp
|
||||
# github.com/prometheus/client_model v0.2.0
|
||||
github.com/prometheus/client_model/go
|
||||
# github.com/prometheus/common v0.11.1
|
||||
+## explicit
|
||||
github.com/prometheus/common/expfmt
|
||||
github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
|
||||
github.com/prometheus/common/model
|
||||
@@ -332,14 +356,17 @@ github.com/prometheus/procfs/internal/util
|
||||
# github.com/rivo/uniseg v0.2.0
|
||||
github.com/rivo/uniseg
|
||||
# github.com/sirupsen/logrus v1.8.1
|
||||
+## explicit
|
||||
github.com/sirupsen/logrus
|
||||
# github.com/spf13/cobra v1.2.1
|
||||
+## explicit
|
||||
github.com/spf13/cobra
|
||||
# github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/pflag
|
||||
# github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980
|
||||
github.com/stefanberger/go-pkcs11uri
|
||||
# github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
||||
+## explicit
|
||||
github.com/syndtr/gocapability/capability
|
||||
# github.com/tchap/go-patricia v2.3.0+incompatible
|
||||
github.com/tchap/go-patricia/patricia
|
||||
@@ -358,6 +385,7 @@ github.com/vbauerster/mpb/v7/cwriter
|
||||
github.com/vbauerster/mpb/v7/decor
|
||||
github.com/vbauerster/mpb/v7/internal
|
||||
# github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb
|
||||
+## explicit
|
||||
github.com/xeipuuv/gojsonpointer
|
||||
# github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
|
||||
github.com/xeipuuv/gojsonreference
|
||||
@@ -374,6 +402,7 @@ go.opencensus.io/trace
|
||||
go.opencensus.io/trace/internal
|
||||
go.opencensus.io/trace/tracestate
|
||||
# golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
|
||||
+## explicit
|
||||
golang.org/x/crypto/cast5
|
||||
golang.org/x/crypto/ed25519
|
||||
golang.org/x/crypto/ed25519/internal/edwards25519
|
||||
@@ -396,9 +425,11 @@ golang.org/x/net/internal/timeseries
|
||||
golang.org/x/net/proxy
|
||||
golang.org/x/net/trace
|
||||
# golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
+## explicit
|
||||
golang.org/x/sync/errgroup
|
||||
golang.org/x/sync/semaphore
|
||||
# golang.org/x/sys v0.0.0-20211124211545-fe61309f8881
|
||||
+## explicit
|
||||
golang.org/x/sys/execabs
|
||||
golang.org/x/sys/internal/unsafeheader
|
||||
golang.org/x/sys/plan9
|
||||
@@ -414,6 +445,7 @@ golang.org/x/text/unicode/norm
|
||||
# google.golang.org/genproto v0.0.0-20211005153810-c76a74d43a8e
|
||||
google.golang.org/genproto/googleapis/rpc/status
|
||||
# google.golang.org/grpc v1.42.0
|
||||
+## explicit
|
||||
google.golang.org/grpc
|
||||
google.golang.org/grpc/attributes
|
||||
google.golang.org/grpc/backoff
|
||||
@@ -497,6 +529,7 @@ gopkg.in/square/go-jose.v2/json
|
||||
# gopkg.in/yaml.v2 v2.4.0
|
||||
gopkg.in/yaml.v2
|
||||
# gotest.tools/v3 v3.0.3
|
||||
+## explicit
|
||||
gotest.tools/v3/assert
|
||||
gotest.tools/v3/assert/cmp
|
||||
gotest.tools/v3/fs
|
||||
--
|
||||
2.27.0
|
||||
|
||||
159
patch/0103-fix-some-mistake-in-isula-build-cli-program.patch
Normal file
159
patch/0103-fix-some-mistake-in-isula-build-cli-program.patch
Normal file
@ -0,0 +1,159 @@
|
||||
From cd55c2a7ba2351b65d983c504776732e9c8d26da Mon Sep 17 00:00:00 2001
|
||||
From: hlwqds <545743488@qq.com>
|
||||
Date: Wed, 5 Jan 2022 18:19:30 +0800
|
||||
Subject: [PATCH 02/20] fix some mistake in isula-build cli program Fixes:
|
||||
#I4OW7N Signed-off-by: hlwqds 545743488@qq.com
|
||||
|
||||
---
|
||||
cmd/cli/info.go | 6 ------
|
||||
cmd/cli/login.go | 16 ++++++++++++----
|
||||
cmd/cli/login_test.go | 33 +++++++++++++++++++++++++--------
|
||||
cmd/cli/logout.go | 2 +-
|
||||
cmd/cli/logout_test.go | 3 ++-
|
||||
5 files changed, 40 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/cmd/cli/info.go b/cmd/cli/info.go
|
||||
index 43ba637..1ed9038 100644
|
||||
--- a/cmd/cli/info.go
|
||||
+++ b/cmd/cli/info.go
|
||||
@@ -78,12 +78,6 @@ func infoCommand(c *cobra.Command, args []string) error {
|
||||
if len(args) > 1 {
|
||||
return errors.New("invalid args for info command")
|
||||
}
|
||||
- if c.Flag("verbose").Changed {
|
||||
- infoOpts.verbose = true
|
||||
- }
|
||||
- if c.Flag("human-readable").Changed {
|
||||
- infoOpts.humanReadable = true
|
||||
- }
|
||||
|
||||
ctx := context.Background()
|
||||
cli, err := NewClient(ctx)
|
||||
diff --git a/cmd/cli/login.go b/cmd/cli/login.go
|
||||
index 9a36eb9..06724b7 100644
|
||||
--- a/cmd/cli/login.go
|
||||
+++ b/cmd/cli/login.go
|
||||
@@ -87,6 +87,10 @@ func loginCommand(c *cobra.Command, args []string) error {
|
||||
}
|
||||
loginOpts.keyPath = util.DefaultRSAKeyPath
|
||||
|
||||
+ if err := checkAuthOpt(); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -131,6 +135,13 @@ func runLogin(ctx context.Context, cli Cli, c *cobra.Command) (string, error) {
|
||||
return resp.Content, err
|
||||
}
|
||||
|
||||
+func checkAuthOpt() error {
|
||||
+ if loginOpts.stdinPass && loginOpts.username == "" {
|
||||
+ return errLackOfFlags
|
||||
+ }
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
func getAuthInfo(c *cobra.Command) error {
|
||||
if err := getUsername(c); err != nil {
|
||||
return err
|
||||
@@ -192,7 +203,7 @@ func getUsername(c *cobra.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
- if !c.Flag("username").Changed {
|
||||
+ if loginOpts.username == "" {
|
||||
fmt.Print("Username: ")
|
||||
if _, err := fmt.Scanln(&username); err != nil {
|
||||
return errReadUsernameFromTerm
|
||||
@@ -215,9 +226,6 @@ func getPassword(c *cobra.Command) error {
|
||||
if loginOpts.password != "" {
|
||||
return nil
|
||||
}
|
||||
- if c.Flag("password-stdin").Changed && !c.Flag("username").Changed {
|
||||
- return errLackOfFlags
|
||||
- }
|
||||
|
||||
if loginOpts.stdinPass {
|
||||
if err := getPassFromStdin(os.Stdin); err != nil {
|
||||
diff --git a/cmd/cli/login_test.go b/cmd/cli/login_test.go
|
||||
index f5f1a44..28a11f4 100644
|
||||
--- a/cmd/cli/login_test.go
|
||||
+++ b/cmd/cli/login_test.go
|
||||
@@ -29,16 +29,33 @@ import (
|
||||
)
|
||||
|
||||
func TestNewLoginCmd(t *testing.T) {
|
||||
- loginCmd := NewLoginCmd()
|
||||
- loginCmd.SetArgs(strings.Split("test.org --username testuser --password-stdin", " "))
|
||||
- err := loginCmd.Execute()
|
||||
- args := []string{"test.org"}
|
||||
- err = loginCommand(loginCmd, args)
|
||||
- if err != nil {
|
||||
- assert.ErrorContains(t, err, "isula_build.sock")
|
||||
+ tests := []struct {
|
||||
+ name string
|
||||
+ args string
|
||||
+ errString string
|
||||
+ }{
|
||||
+ {
|
||||
+ name: "TC1 - normal case",
|
||||
+ args: "test.org --username testuser --password-stdin",
|
||||
+ errString: "isula_build.sock",
|
||||
+ },
|
||||
+ {
|
||||
+ name: "TC2 - abnormal case provides --password-stdin without --username ",
|
||||
+ args: "test.org --password-stdin",
|
||||
+ errString: "must provides --password-stdin with --username",
|
||||
+ },
|
||||
+ }
|
||||
+ for _, tt := range tests {
|
||||
+ t.Run(tt.name, func(t *testing.T) {
|
||||
+ cmd := NewLoginCmd()
|
||||
+ cmd.SetArgs(strings.Split(tt.args, " "))
|
||||
+ err := cmd.Execute()
|
||||
+ if err != nil {
|
||||
+ assert.ErrorContains(t, err, tt.errString)
|
||||
+ }
|
||||
+ })
|
||||
}
|
||||
}
|
||||
-
|
||||
func TestGetPassFromInput(t *testing.T) {
|
||||
type args struct {
|
||||
f passReader
|
||||
diff --git a/cmd/cli/logout.go b/cmd/cli/logout.go
|
||||
index 5d3affd..14f3c6c 100644
|
||||
--- a/cmd/cli/logout.go
|
||||
+++ b/cmd/cli/logout.go
|
||||
@@ -88,7 +88,7 @@ func newLogoutOptions(c *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// no need args check when all flag is set
|
||||
- if c.Flag("all").Changed {
|
||||
+ if logoutOpts.all {
|
||||
logoutOpts.all = true
|
||||
logoutOpts.server = ""
|
||||
return nil
|
||||
diff --git a/cmd/cli/logout_test.go b/cmd/cli/logout_test.go
|
||||
index 1328c2a..c8b890c 100644
|
||||
--- a/cmd/cli/logout_test.go
|
||||
+++ b/cmd/cli/logout_test.go
|
||||
@@ -125,11 +125,12 @@ func TestNewLogoutOptions(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.flag != "" {
|
||||
- tt.args.c.Flag("all").Changed = true
|
||||
+ logoutOpts.all = true
|
||||
}
|
||||
if err := newLogoutOptions(tt.args.c, tt.args.args); (err != nil) != tt.wantErr {
|
||||
t.Errorf("newLogoutOptions() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
+ logoutOpts.all = false
|
||||
})
|
||||
}
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
From a50afb463874aa4121c1a61f48b58992550329d6 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Mon, 10 Jan 2022 19:30:49 +0800
|
||||
Subject: [PATCH 03/20] fix wrong behavior when the image of image:tag is
|
||||
prefix of other image id
|
||||
|
||||
---
|
||||
daemon/remove.go | 3 ++-
|
||||
image/image.go | 9 +++++----
|
||||
2 files changed, 7 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/daemon/remove.go b/daemon/remove.go
|
||||
index 12acf0c..e0a9eed 100644
|
||||
--- a/daemon/remove.go
|
||||
+++ b/daemon/remove.go
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
+ constant "isula.org/isula-build"
|
||||
pb "isula.org/isula-build/api/services"
|
||||
"isula.org/isula-build/image"
|
||||
"isula.org/isula-build/store"
|
||||
@@ -121,7 +122,7 @@ func untagImage(imageID string, store storage.Store, image *storage.Image) (bool
|
||||
newNames := make([]string, 0)
|
||||
removed := false
|
||||
for _, imgName := range image.Names {
|
||||
- if imgName == imageID {
|
||||
+ if imgName == imageID || imgName == fmt.Sprintf("%s:%s", imageID, constant.DefaultTag) {
|
||||
removed = true
|
||||
continue
|
||||
}
|
||||
diff --git a/image/image.go b/image/image.go
|
||||
index 37cd7fa..357363a 100644
|
||||
--- a/image/image.go
|
||||
+++ b/image/image.go
|
||||
@@ -522,17 +522,18 @@ func ResolveName(name string, sc *types.SystemContext, store *store.Store) ([]st
|
||||
}
|
||||
|
||||
func tryResolveNameInStore(name string, store *store.Store) string {
|
||||
- logrus.Infof("Try to find image: %s in local storage", name)
|
||||
- img, err := store.Image(name)
|
||||
+ logrus.Infof("Try to find image: %s:%s in local storage", name, constant.DefaultTag)
|
||||
+ img, err := store.Image(fmt.Sprintf("%s:%s", name, constant.DefaultTag))
|
||||
if err == nil {
|
||||
return img.ID
|
||||
}
|
||||
|
||||
- logrus.Infof("Try to find image: %s:%s in local storage", name, constant.DefaultTag)
|
||||
- img, err = store.Image(fmt.Sprintf("%s:%s", name, constant.DefaultTag))
|
||||
+ logrus.Infof("Try to find image: %s in local storage", name)
|
||||
+ img, err = store.Image(name)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
+
|
||||
return img.ID
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,657 @@
|
||||
From 513d78a2a90e0748e4a5394c8cbeac8cd67eb159 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Mon, 10 Jan 2022 19:36:49 +0800
|
||||
Subject: [PATCH 04/20] Refactor: integration test basic framework, and adapt
|
||||
existing testcases to it
|
||||
|
||||
---
|
||||
tests/lib/common.sh | 329 ++++++++++--------
|
||||
...on_test_save_single_image_multiple_tags.sh | 86 ++---
|
||||
tests/src/integration_test_set_new_root.sh | 31 +-
|
||||
tests/test.sh | 30 +-
|
||||
4 files changed, 243 insertions(+), 233 deletions(-)
|
||||
|
||||
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
|
||||
index 4dd34aa..3c031f9 100755
|
||||
--- a/tests/lib/common.sh
|
||||
+++ b/tests/lib/common.sh
|
||||
@@ -18,7 +18,7 @@ declare -x pidofbuilder
|
||||
|
||||
# check if legacy builder exists
|
||||
function pre_check() {
|
||||
- if pgrep isula-builder > /dev/null 2>&1; then
|
||||
+ if pgrep isula-builder >/dev/null 2>&1; then
|
||||
echo "isula-builder is already running, please stop it first"
|
||||
exit 1
|
||||
fi
|
||||
@@ -26,13 +26,13 @@ function pre_check() {
|
||||
|
||||
# start isula-builder
|
||||
function start_isula_builder() {
|
||||
- nohup isula-builder > /tmp/buildlog-daemon 2>&1 &
|
||||
+ nohup isula-builder >/tmp/buildlog-daemon 2>&1 &
|
||||
pidofbuilder=$!
|
||||
|
||||
# check if isula-builder is started
|
||||
builder_started=0
|
||||
for _ in $(seq 1 30); do
|
||||
- if ! grep -i "is listening on" /tmp/buildlog-daemon > /dev/null 2>&1; then
|
||||
+ if ! grep -i "is listening on" /tmp/buildlog-daemon >/dev/null 2>&1; then
|
||||
sleep 0.1
|
||||
continue
|
||||
else
|
||||
@@ -47,198 +47,233 @@ function start_isula_builder() {
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
- isula-build ctr-img rm -p > /dev/null 2>&1
|
||||
- kill -15 "${pidofbuilder}" > /dev/null 2>&1
|
||||
+ isula-build ctr-img rm -p >/dev/null 2>&1
|
||||
+ kill -15 "${pidofbuilder}" >/dev/null 2>&1
|
||||
rm -f /tmp/buildlog-*
|
||||
}
|
||||
|
||||
# test build image without output with default docker format
|
||||
function test_build_without_output() {
|
||||
- if ! isula-build ctr-img build --format docker --tag "$1":latest "$2" > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker format without output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ commands=(
|
||||
+ "isula-build ctr-img build --format docker --tag $1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
|
||||
- if ! isula-build ctr-img rm "$1":latest > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker format without output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
}
|
||||
|
||||
# test build image without output with oci format
|
||||
function test_build_without_output_with_oci_format() {
|
||||
- if ! isula-build ctr-img build --format oci --tag "$1":latest "$2" > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with oci format without output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
-
|
||||
- if ! isula-build ctr-img rm "$1":latest > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with oci format without output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --format oci --tag $1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
}
|
||||
|
||||
# test build image with docker-archive output
|
||||
function test_build_with_docker_archive_output() {
|
||||
- if ! isula-build ctr-img build --output=docker-archive:/tmp/"$1".tar:"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-archive output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- else
|
||||
- rm -f /tmp/"$1".tar
|
||||
- fi
|
||||
-
|
||||
- if ! isula-build ctr-img rm "$1":latest > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-archive output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=docker-archive:/tmp/$1.tar:$1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ rm -f /tmp/"$1".tar
|
||||
}
|
||||
|
||||
# test build image with oci-archive output
|
||||
function test_build_with_oci_archive_output() {
|
||||
- if ! isula-build ctr-img build --output=oci-archive:/tmp/"$1".tar:"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with oci-archive output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- else
|
||||
- rm -f /tmp/"$1".tar
|
||||
- fi
|
||||
-
|
||||
- if ! isula-build ctr-img rm "$1":latest > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with oci-archive output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=oci-archive:/tmp/$1.tar:$1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ rm -f /tmp/"$1".tar
|
||||
}
|
||||
|
||||
# test build image with docker-daemon output
|
||||
function test_build_with_docker_daemon_output() {
|
||||
- if ! systemctl status docker > /dev/null 2>&1; then
|
||||
+ if ! systemctl status docker >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
- if ! isula-build ctr-img build --output=docker-daemon:isula/"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-daemon output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- else
|
||||
- docker rmi isula/"$1" > /dev/null 2>&1
|
||||
- fi
|
||||
-
|
||||
- if ! isula-build ctr-img rm isula/"$1":latest > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with docker-daemon output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=docker-daemon:isula/$1:latest $2"
|
||||
+ "isula-build ctr-img rm isula/$1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ docker rmi isula/"$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# test build image with isulad output
|
||||
-function test_build_with_isulad_output() {
|
||||
- if ! systemctl status isulad > /dev/null 2>&1; then
|
||||
+function test_build_with_isulad_output() {
|
||||
+ if ! systemctl status isulad >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
- if ! isula-build ctr-img build --output=isulad:isula/"$1":latest "$2" > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with isulad output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- else
|
||||
- isula rmi isula/"$1" > /dev/null 2>&1
|
||||
- fi
|
||||
-
|
||||
- if ! isula-build ctr-img rm isula/"$1":latest > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon (build with isulad output)"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=isulad:isula/$1:latest $2"
|
||||
+ "isula-build ctr-img rm isula/$1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ isula rmi isula/"$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# test isula build base command
|
||||
function test_isula_build_base_command() {
|
||||
- show_and_run_command "Build docker format image:" \
|
||||
- " isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:/tmp/$1-docker.tar:$1-docker:latest $2"
|
||||
+ declare -A commands=(
|
||||
+ ["Build docker format image"]="isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:/tmp/$1-docker.tar:$1-docker:latest $2"
|
||||
+ ["Build oci format image"]="isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:/tmp/$1-oci.tar:$1-oci:latest $2"
|
||||
+ ["List all images"]="isula-build ctr-img images"
|
||||
+ ["List docker format image"]="isula-build ctr-img images $1-docker:latest"
|
||||
+ ["List oci format image"]="isula-build ctr-img images $1-oci:latest"
|
||||
+ ["Save image with docker format"]="isula-build ctr-img save -f docker $1-docker:latest -o /tmp/$1-save-docker.tar"
|
||||
+ ["Save image with oci format"]="isula-build ctr-img save -f oci $1-oci:latest -o /tmp/$1-save-oci.tar"
|
||||
+ ["Load docker format images"]="isula-build ctr-img load -i /tmp/$1-docker.tar"
|
||||
+ ["Load oci format images"]="isula-build ctr-img load -i /tmp/$1-oci.tar"
|
||||
+ ["Save multipile images with docker format"]="isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o /tmp/$1-all.tar"
|
||||
+ ["Remove images"]="isula-build ctr-img rm $1-docker:latest $1-oci:latest"
|
||||
+ )
|
||||
+ declare -a orders
|
||||
+ orders+=("Build docker format image")
|
||||
+ orders+=("Build oci format image")
|
||||
+ orders+=("List all images")
|
||||
+ orders+=("List docker format image")
|
||||
+ orders+=("List oci format image")
|
||||
+ orders+=("Save image with docker format")
|
||||
+ orders+=("Save image with oci format")
|
||||
+ orders+=("Load docker format images")
|
||||
+ orders+=("Load oci format images")
|
||||
+ orders+=("Save multipile images with docker format")
|
||||
+ orders+=("Remove images")
|
||||
+ for i in "${!orders[@]}"; do
|
||||
+ show_and_run_command "${orders[$i]}" "${commands[${orders[$i]}]}"
|
||||
+ done
|
||||
|
||||
- show_and_run_command "Build oci format image:" \
|
||||
- "isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:/tmp/$1-oci.tar:$1-oci:latest $2"
|
||||
+ rm -f /tmp/*.tar
|
||||
+}
|
||||
|
||||
- show_and_run_command "List all images:" \
|
||||
- "isula-build ctr-img images"
|
||||
-
|
||||
- show_and_run_command "List docker format image:" \
|
||||
- "isula-build ctr-img images $1-docker:latest"
|
||||
+# print callstack of shell function
|
||||
+function shell_print_callstack() {
|
||||
+ echo "Shell Function Call Stack:"
|
||||
+ for ((index = 1; index < ${#FUNCNAME[@]}; index++)); do
|
||||
+ printf "\t%d - %s\n" "$((index - 1))" "${FUNCNAME[index]} (${BASH_SOURCE[index + 1]}:${BASH_LINENO[index]})"
|
||||
+ done
|
||||
+}
|
||||
|
||||
- show_and_run_command "List oci format image:" \
|
||||
- "isula-build ctr-img images $1-oci:latest"
|
||||
+# show command brief and run
|
||||
+# $1 (command brief)
|
||||
+# $2 (concrete command)
|
||||
+function show_and_run_command() {
|
||||
+ function run_command() {
|
||||
+ if ! $command >/tmp/buildlog-client 2>&1; then
|
||||
+ echo "FAIL"
|
||||
+ echo "Failed when running command: $command"
|
||||
+ echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon"
|
||||
+ kill -15 "${pidofbuilder}"
|
||||
+ shell_print_callstack
|
||||
+ exit 1
|
||||
+ fi
|
||||
+ }
|
||||
+ if [ $# -eq 1 ]; then
|
||||
+ local -r command="$1"
|
||||
+ run_command
|
||||
+ return 0
|
||||
+ fi
|
||||
+ local -r brief="$1"
|
||||
+ local -r command="$2"
|
||||
+ printf "%-45s" "$brief"":"
|
||||
+ run_command
|
||||
+ echo "PASS"
|
||||
+}
|
||||
|
||||
- rm -f /tmp/"$1"-docker.tar /tmp/"$1"-oci.tar
|
||||
+exit_flag=0
|
||||
|
||||
- show_and_run_command "Save image with docker format:" \
|
||||
- "isula-build ctr-img save -f docker $1-docker:latest -o /tmp/$1-docker.tar"
|
||||
+# run command when isula-builder running in systemd mode
|
||||
+# $1 (concrete command)
|
||||
+function systemd_run_command() {
|
||||
+ local -r command="$1"
|
||||
|
||||
- show_and_run_command "Save image with oci format:" \
|
||||
- "isula-build ctr-img save -f oci $1-oci:latest -o /tmp/$1-oci.tar"
|
||||
+ start_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
+ if ! $command >/tmp/buildlog-client 2>&1; then
|
||||
+ {
|
||||
+ echo "Error from client:"
|
||||
+ cat /tmp/buildlog-client
|
||||
+ echo "Error from daemon:"
|
||||
+ journalctl -u isula-build --since "$start_time" --no-pager
|
||||
+ shell_print_callstack
|
||||
+ } >>/tmp/buildlog-failed
|
||||
|
||||
- show_and_run_command "Load docker format images:" \
|
||||
- "isula-build ctr-img load -i /tmp/$1-docker.tar"
|
||||
+ ((exit_flag++))
|
||||
+ fi
|
||||
+}
|
||||
|
||||
- show_and_run_command "Load oci format images:" \
|
||||
- "isula-build ctr-img load -i /tmp/$1-oci.tar"
|
||||
+# run command and check its result
|
||||
+# $1 (command)
|
||||
+# $2 (expected command return value)
|
||||
+function run_check_result() {
|
||||
+ local -r command="$1"
|
||||
+ local -r expected="$2"
|
||||
+
|
||||
+ eval "$command" >/dev/null 2>&1
|
||||
+ result=$?
|
||||
+ if [ "$result" != "$expected" ]; then
|
||||
+ debug "expected $expected, get $result"
|
||||
+ testcase_path="${BASH_SOURCE[1]}"
|
||||
+ testcase="${testcase_path##/*/}"
|
||||
+ echo "$testcase:${BASH_LINENO[0]}" "$command" >>/tmp/buildlog-failed
|
||||
+ echo expected "$expected", get "$result" >>/tmp/buildlog-failed
|
||||
+ ((exit_flag++))
|
||||
+ fi
|
||||
+}
|
||||
|
||||
- show_and_run_command "Save multipile images with docker format:" \
|
||||
- "isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o /tmp/$1-all.tar"
|
||||
+# check actual result and expected value
|
||||
+# $1 (result)
|
||||
+# $2 (expected)
|
||||
+function check_value() {
|
||||
+ local -r result="$1"
|
||||
+ local -r expected="$2"
|
||||
+
|
||||
+ if [ "$result" != "$expected" ]; then
|
||||
+ debug "expected $expected, get $result"
|
||||
+ testcase_path="${BASH_SOURCE[1]}"
|
||||
+ testcase="${testcase_path##/*/}"
|
||||
+ echo "TESTCASE: $testcase:${BASH_LINENO[0]}" "${FUNCNAME[0]}" >>/tmp/buildlog-failed
|
||||
+ echo expected "$expected", get "$result" >>/tmp/buildlog-failed
|
||||
+ ((exit_flag++))
|
||||
+ fi
|
||||
+}
|
||||
|
||||
- rm -f /tmp/"$1"-docker.tar /tmp/"$1"-oci.tar /tmp/"$1"-all.tar
|
||||
+# print debug message
|
||||
+# $1 (debug message)
|
||||
+function debug() {
|
||||
+ local -r message="$1"
|
||||
|
||||
- show_and_run_command "Remove images:" \
|
||||
- "isula-build ctr-img rm $1-docker:latest $1-oci:latest"
|
||||
+ if [ "$TEST_DEBUG" == "true" ]; then
|
||||
+ printf "(%s %s) " "DEBUG:" "$message"
|
||||
+ fi
|
||||
}
|
||||
|
||||
-function show_and_run_command() {
|
||||
- printf "%-45s" "$1"
|
||||
- if ! $2 > /tmp/buildlog-client 2>&1; then
|
||||
- echo "FAIL"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon, failed when running command: $2"
|
||||
- kill -15 "${pidofbuilder}"
|
||||
- exit 1
|
||||
- fi
|
||||
- echo "PASS"
|
||||
+run_root="/var/run/integration-isula-build"
|
||||
+data_root="/var/lib/integration-isula-build"
|
||||
+config_file="/etc/isula-build/configuration.toml"
|
||||
+
|
||||
+function pre_integration() {
|
||||
+ rm -rf /tmp/buildlog-failed
|
||||
+
|
||||
+ cp $config_file "$config_file".integration
|
||||
+ sed -i "/run_root/d;/data_root/d" $config_file
|
||||
+ echo "run_root = \"${run_root}\"" >>$config_file
|
||||
+ echo "data_root = \"${data_root}\"" >>$config_file
|
||||
+
|
||||
+ systemctl restart isula-build
|
||||
}
|
||||
|
||||
-function run_with_debug() {
|
||||
- function fail_and_exit(){
|
||||
- echo "FAIL"
|
||||
- echo "Run \"journalctl -xefu isula-build\" to get the log."
|
||||
- systemctl stop isula-build
|
||||
- exit 1
|
||||
- }
|
||||
+function after_integration() {
|
||||
+ systemd_run_command "isula-build ctr-img rm -a"
|
||||
|
||||
- if [ "${DEBUG:-0}" -eq 0 ]; then
|
||||
- if ! $1 > /dev/null 2>&1; then
|
||||
- fail_and_exit
|
||||
- fi
|
||||
- return
|
||||
- fi
|
||||
- echo "$1"
|
||||
- if ! $1; then
|
||||
- fail_and_exit
|
||||
- fi
|
||||
- echo "------------command-delimiter-----------"
|
||||
- echo " "
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+ rm -f $config_file
|
||||
+ mv "$config_file".integration $config_file
|
||||
+ systemctl stop isula-build
|
||||
+ rm -rf $run_root $data_root
|
||||
+}
|
||||
diff --git a/tests/src/integration_test_save_single_image_multiple_tags.sh b/tests/src/integration_test_save_single_image_multiple_tags.sh
|
||||
index 1eaeb8d..46df444 100644
|
||||
--- a/tests/src/integration_test_save_single_image_multiple_tags.sh
|
||||
+++ b/tests/src/integration_test_save_single_image_multiple_tags.sh
|
||||
@@ -12,69 +12,49 @@
|
||||
# Author: Weizheng Xing
|
||||
# Create: 2021-08-24
|
||||
# Description: check if saving single image with multiple tags has been corrected
|
||||
+# History: 2022-01-10 Weizheng Xing <xingweizheng@huawei.com> Refactor: use systemd_run_command common function
|
||||
|
||||
top_dir=$(git rev-parse --show-toplevel)
|
||||
-# shellcheck disable=SC1091
|
||||
source "$top_dir"/tests/lib/common.sh
|
||||
|
||||
-image_name=add-chown-basic
|
||||
-context_dir="$top_dir"/tests/data/add-chown-basic
|
||||
+image_name=build-from-scratch
|
||||
+context_dir="$top_dir"/tests/data/build-from-scratch
|
||||
|
||||
-function clean()
|
||||
-{
|
||||
- isula-build ctr-img rm -p > /dev/null 2>&1
|
||||
- systemctl stop isula-build
|
||||
- rm -rf "$temp_tar"
|
||||
-}
|
||||
-
|
||||
-function pre_test()
|
||||
-{
|
||||
+function pre_test() {
|
||||
temp_tar=$(mktemp -u --suffix=.tar)
|
||||
- systemctl restart isula-build
|
||||
}
|
||||
|
||||
-function do_test()
|
||||
-{
|
||||
+function do_test() {
|
||||
# get image id
|
||||
- if ! image_id1=$(isula-build ctr-img build -t $image_name:latest "$context_dir"|grep "Build success with image id: "|cut -d ":" -f 2); then
|
||||
- echo "FAIL"
|
||||
- fi
|
||||
- if ! image_id2=$(isula-build ctr-img build -t $image_name:latest2 "$context_dir"|grep "Build success with image id: "|cut -d ":" -f 2); then
|
||||
- echo "FAIL"
|
||||
- fi
|
||||
-
|
||||
- ! run_with_debug "isula-build ctr-img tag $image_name:latest $image_name:latest-child"
|
||||
-
|
||||
- # save with id + name
|
||||
- ! run_with_debug "isula-build ctr-img save -f docker $image_id1 $image_name:latest-child -o $temp_tar"
|
||||
- rm -rf "$temp_tar"
|
||||
-
|
||||
- # save with name + id
|
||||
- ! run_with_debug "isula-build ctr-img save -f docker $image_name:latest-child $image_id1 -o $temp_tar"
|
||||
- rm -rf "$temp_tar"
|
||||
-
|
||||
- # save with name + name
|
||||
- ! run_with_debug "isula-build ctr-img save -f docker $image_name:latest $image_name:latest-child -o $temp_tar"
|
||||
- rm -rf "$temp_tar"
|
||||
-
|
||||
- # save with different images id1 + id2
|
||||
- ! run_with_debug "isula-build ctr-img save -f docker $image_id1 $image_id2 -o $temp_tar"
|
||||
- rm -rf "$temp_tar"
|
||||
-
|
||||
- # save with different images "without latest tag" + id2
|
||||
- ! run_with_debug "isula-build ctr-img save -f docker $image_name $image_id2 -o $temp_tar"
|
||||
- rm -rf "$temp_tar"
|
||||
-
|
||||
- # save with id1 + id2 + name
|
||||
- ! run_with_debug "isula-build ctr-img save -f docker $image_id1 $image_id2 $image_name:latest2 -o $temp_tar"
|
||||
- rm -rf "$temp_tar"
|
||||
-
|
||||
- ! run_with_debug "isula-build ctr-img rm $image_name:latest $image_name:latest-child"
|
||||
- ! run_with_debug "isula-build ctr-img rm $image_name:latest2"
|
||||
-
|
||||
- echo "PASS"
|
||||
+ systemd_run_command "isula-build ctr-img build -t $image_name:latest $context_dir"
|
||||
+ image_id1=$(grep </tmp/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
+
|
||||
+ systemd_run_command "isula-build ctr-img build -t $image_name:latest2 $context_dir"
|
||||
+ image_id2=$(grep </tmp/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
+
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img tag $image_name:latest $image_name:latest-child"
|
||||
+ # save with id + name
|
||||
+ "isula-build ctr-img save -f docker $image_id1 $image_name:latest-child -o $temp_tar"
|
||||
+ # save with name + id
|
||||
+ "isula-build ctr-img save -f docker $image_name:latest-child $image_id1 -o $temp_tar"
|
||||
+ # save with name + name
|
||||
+ "isula-build ctr-img save -f docker $image_name:latest $image_name:latest-child -o $temp_tar"
|
||||
+ # save with different images id1 + id2
|
||||
+ "isula-build ctr-img save -f docker $image_id1 $image_id2 -o $temp_tar"
|
||||
+ # save with different images "without latest tag" + id2
|
||||
+ "isula-build ctr-img save -f docker $image_name $image_id2 -o $temp_tar"
|
||||
+ # save with id1 + id2 + name
|
||||
+ "isula-build ctr-img save -f docker $image_id1 $image_id2 $image_name:latest2 -o $temp_tar"
|
||||
+ "isula-build ctr-img rm $image_name:latest $image_name:latest-child"
|
||||
+ "isula-build ctr-img rm $image_name:latest2"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do
|
||||
+ systemd_run_command "$command"
|
||||
+ rm -rf "$temp_tar"
|
||||
+ done
|
||||
}
|
||||
|
||||
pre_test
|
||||
do_test
|
||||
-clean
|
||||
+exit "$exit_flag"
|
||||
diff --git a/tests/src/integration_test_set_new_root.sh b/tests/src/integration_test_set_new_root.sh
|
||||
index ae8d436..d2dfcf2 100644
|
||||
--- a/tests/src/integration_test_set_new_root.sh
|
||||
+++ b/tests/src/integration_test_set_new_root.sh
|
||||
@@ -13,6 +13,7 @@
|
||||
# Create: 2021-05-29
|
||||
# Description: test set new run and data root in configuration.toml
|
||||
# History: 2021-8-18 Xiang Li <lixiang172@huawei.com> use busyobx instead of openeuler base image to speed up test
|
||||
+# History: 2022-01-10 Weizheng Xing <xingweizheng@huawei.com> Refactor: use systemd_run_command common function
|
||||
|
||||
top_dir=$(git rev-parse --show-toplevel)
|
||||
# shellcheck disable=SC1091
|
||||
@@ -21,45 +22,37 @@ source "$top_dir"/tests/lib/common.sh
|
||||
run_root="/var/run/new-isula-build"
|
||||
data_root="/var/lib/new-isula-build"
|
||||
config_file="/etc/isula-build/configuration.toml"
|
||||
-image="hub.oepkgs.net/openeuler/busybox:latest"
|
||||
+image="hub.oepkgs.net/library/busybox:latest"
|
||||
|
||||
-function clean()
|
||||
-{
|
||||
+function clean() {
|
||||
rm -f $config_file
|
||||
mv "$config_file".bak $config_file
|
||||
|
||||
- isula-build ctr-img rm -p > /dev/null 2>&1
|
||||
- systemctl stop isula-build
|
||||
+ systemctl restart isula-build
|
||||
rm -rf $run_root $data_root
|
||||
}
|
||||
|
||||
# change to new data and run root
|
||||
-function pre_test()
|
||||
-{
|
||||
+function pre_test() {
|
||||
cp $config_file "$config_file".bak
|
||||
sed -i "/run_root/d;/data_root/d" $config_file
|
||||
- echo "run_root = \"${run_root}\"" >> $config_file
|
||||
- echo "data_root = \"${data_root}\"" >> $config_file
|
||||
+ echo "run_root = \"${run_root}\"" >>$config_file
|
||||
+ echo "data_root = \"${data_root}\"" >>$config_file
|
||||
|
||||
systemctl restart isula-build
|
||||
}
|
||||
|
||||
# check if new resources are downloaded in new root
|
||||
-function do_test()
|
||||
-{
|
||||
+function do_test() {
|
||||
tree_node_befor=$(tree -L 3 $data_root | wc -l)
|
||||
- run_with_debug "isula-build ctr-img pull $image"
|
||||
+ systemd_run_command "isula-build ctr-img pull $image"
|
||||
tree_node_after=$(tree -L 3 $data_root | wc -l)
|
||||
|
||||
- if [ $((tree_node_after - tree_node_befor)) -eq 8 ] && run_with_debug "isula-build ctr-img rm $image"; then
|
||||
- echo "PASS"
|
||||
- else
|
||||
- echo "Sets of run and data root are not effective"
|
||||
- clean
|
||||
- exit 1
|
||||
- fi
|
||||
+ check_value $((tree_node_after - tree_node_befor)) 8
|
||||
+ systemd_run_command "isula-build ctr-img rm $image"
|
||||
}
|
||||
|
||||
pre_test
|
||||
do_test
|
||||
clean
|
||||
+exit "$exit_flag"
|
||||
diff --git a/tests/test.sh b/tests/test.sh
|
||||
index 01f0f31..df29c22 100755
|
||||
--- a/tests/test.sh
|
||||
+++ b/tests/test.sh
|
||||
@@ -36,36 +36,38 @@ function fuzz() {
|
||||
# integration test
|
||||
function integration() {
|
||||
source "$top_dir"/tests/lib/common.sh
|
||||
- systemctl restart isula-build
|
||||
+ pre_integration
|
||||
|
||||
while IFS= read -r testfile; do
|
||||
printf "%-65s" "test $(basename "$testfile"): "
|
||||
if ! bash "$testfile"; then
|
||||
- exit 1
|
||||
+ echo "FAIL"
|
||||
+ continue
|
||||
fi
|
||||
+ echo "PASS"
|
||||
done < <(find "$top_dir"/tests/src -maxdepth 1 -name "integration_test*" -type f -print)
|
||||
+ after_integration
|
||||
}
|
||||
|
||||
# main function to chose which kind of test
|
||||
function main() {
|
||||
case "$1" in
|
||||
- fuzz)
|
||||
- fuzz "$2"
|
||||
- ;;
|
||||
- base)
|
||||
- base
|
||||
+ fuzz)
|
||||
+ fuzz "$2"
|
||||
;;
|
||||
- integration)
|
||||
- integration
|
||||
+ base)
|
||||
+ base
|
||||
;;
|
||||
- *)
|
||||
- echo "Unknow test type."
|
||||
- exit 1
|
||||
+ integration)
|
||||
+ integration
|
||||
+ ;;
|
||||
+ *)
|
||||
+ echo "Unknow test type."
|
||||
+ exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
-export "ISULABUILD_CLI_EXPERIMENTAL"="enabled"
|
||||
-export DEBUG=0
|
||||
+export ISULABUILD_CLI_EXPERIMENTAL="enabled"
|
||||
|
||||
main "$@"
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
From df8ccb53b015d20e6a835777f4c509b53ea4ed2c Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Mon, 10 Jan 2022 19:37:41 +0800
|
||||
Subject: [PATCH 05/20] add integration_test_image_name_conflict_with_image_id
|
||||
testcase
|
||||
|
||||
---
|
||||
..._test_image_name_conflict_with_image_id.sh | 66 +++++++++++++++++++
|
||||
1 file changed, 66 insertions(+)
|
||||
create mode 100644 tests/src/integration_test_image_name_conflict_with_image_id.sh
|
||||
|
||||
diff --git a/tests/src/integration_test_image_name_conflict_with_image_id.sh b/tests/src/integration_test_image_name_conflict_with_image_id.sh
|
||||
new file mode 100644
|
||||
index 0000000..2c436a0
|
||||
--- /dev/null
|
||||
+++ b/tests/src/integration_test_image_name_conflict_with_image_id.sh
|
||||
@@ -0,0 +1,66 @@
|
||||
+#!/bin/bash
|
||||
+
|
||||
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
+# isula-build licensed under the Mulan PSL v2.
|
||||
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+# You may obtain a copy of Mulan PSL v2 at:
|
||||
+# http://license.coscl.org.cn/MulanPSL2
|
||||
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+# PURPOSE.
|
||||
+# See the Mulan PSL v2 for more details.
|
||||
+# Author: Weizheng Xing
|
||||
+# Create: 2022-01-10
|
||||
+# Description: test delete and save image well behaved when the [image]:tag of one image,
|
||||
+# image is prefix of other image id and tag is latest, such as [othershortid]:latest
|
||||
+
|
||||
+top_dir=$(git rev-parse --show-toplevel)
|
||||
+# shellcheck disable=SC1091
|
||||
+source "$top_dir"/tests/lib/common.sh
|
||||
+
|
||||
+image_name=build-from-scratch
|
||||
+context_dir="$top_dir"/tests/data/build-from-scratch
|
||||
+
|
||||
+function pre_test() {
|
||||
+ temp_tar_short=$(mktemp -u --suffix=.tar)
|
||||
+ temp_tar_double_short=$(mktemp -u --suffix=.tar)
|
||||
+}
|
||||
+
|
||||
+function clean() {
|
||||
+ systemd_run_command "isula-build ctr-img rm $image_name:latest2"
|
||||
+ rm -f "$temp_tar_short"
|
||||
+ rm -f "$temp_tar_double_short"
|
||||
+}
|
||||
+
|
||||
+function do_test() {
|
||||
+ systemd_run_command "isula-build ctr-img build -t $image_name:latest1 $context_dir"
|
||||
+ systemd_run_command "isula-build ctr-img build -t $image_name:latest2 $context_dir"
|
||||
+ image_id2=$(grep </tmp/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
+ short_id2=${image_id2:0:12}
|
||||
+ double_short_id2=${short_id2:0:6}
|
||||
+
|
||||
+ # get material
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img tag $image_name:latest1 $short_id2"
|
||||
+ "isula-build ctr-img save -f docker $short_id2 -o $temp_tar_short"
|
||||
+ "isula-build ctr-img save -f docker $double_short_id2 -o $temp_tar_double_short"
|
||||
+ "isula-build ctr-img rm $short_id2"
|
||||
+ "isula-build ctr-img images $image_name:latest2"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do systemd_run_command "$command"; done
|
||||
+
|
||||
+ # analyse it
|
||||
+ declare -a commands=(
|
||||
+ "cat /tmp/buildlog-client |grep $short_id2"
|
||||
+ "tar -xvf $temp_tar_short -C /tmp manifest.json"
|
||||
+ "cat /tmp/manifest.json | grep $short_id2:latest"
|
||||
+ "tar -xvf $temp_tar_double_short -C /tmp manifest.json"
|
||||
+ "cat /tmp/manifest.json | grep $image_id2"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do run_check_result "$command" 0; done
|
||||
+}
|
||||
+
|
||||
+pre_test
|
||||
+do_test
|
||||
+clean
|
||||
+exit "$exit_flag"
|
||||
--
|
||||
2.27.0
|
||||
|
||||
809
patch/0107-Refactor-combine-all-base-command-tests.patch
Normal file
809
patch/0107-Refactor-combine-all-base-command-tests.patch
Normal file
@ -0,0 +1,809 @@
|
||||
From c8f9834d59c8db4f150be3409c98debc1282134e Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Tue, 11 Jan 2022 10:38:09 +0800
|
||||
Subject: [PATCH 06/20] Refactor: combine all base command tests
|
||||
|
||||
---
|
||||
tests/lib/base_commonlib.sh | 177 ++++++++++++++++
|
||||
tests/lib/common.sh | 198 ++----------------
|
||||
tests/lib/integration_commonlib.sh | 42 ++++
|
||||
tests/src/isula_build_base_command.sh | 44 ++++
|
||||
tests/src/test_add_chown_basic.sh | 28 ---
|
||||
tests/src/test_build_from_scratch.sh | 28 ---
|
||||
tests/src/test_ctr_img_rm.sh | 13 +-
|
||||
...test_image_name_conflict_with_image_id.sh} | 0
|
||||
tests/src/test_isula_build_base_command.sh | 26 ---
|
||||
tests/src/test_multi_files_env.sh | 28 ---
|
||||
tests/src/test_multi_stage_builds.sh | 28 ---
|
||||
...> test_save_single_image_multiple_tags.sh} | 0
|
||||
...t_set_new_root.sh => test_set_new_root.sh} | 0
|
||||
tests/test.sh | 8 +-
|
||||
14 files changed, 293 insertions(+), 327 deletions(-)
|
||||
create mode 100644 tests/lib/base_commonlib.sh
|
||||
create mode 100644 tests/lib/integration_commonlib.sh
|
||||
create mode 100644 tests/src/isula_build_base_command.sh
|
||||
delete mode 100755 tests/src/test_add_chown_basic.sh
|
||||
delete mode 100755 tests/src/test_build_from_scratch.sh
|
||||
rename tests/src/{integration_test_image_name_conflict_with_image_id.sh => test_image_name_conflict_with_image_id.sh} (100%)
|
||||
delete mode 100644 tests/src/test_isula_build_base_command.sh
|
||||
delete mode 100755 tests/src/test_multi_files_env.sh
|
||||
delete mode 100755 tests/src/test_multi_stage_builds.sh
|
||||
rename tests/src/{integration_test_save_single_image_multiple_tags.sh => test_save_single_image_multiple_tags.sh} (100%)
|
||||
rename tests/src/{integration_test_set_new_root.sh => test_set_new_root.sh} (100%)
|
||||
|
||||
diff --git a/tests/lib/base_commonlib.sh b/tests/lib/base_commonlib.sh
|
||||
new file mode 100644
|
||||
index 0000000..996fcdd
|
||||
--- /dev/null
|
||||
+++ b/tests/lib/base_commonlib.sh
|
||||
@@ -0,0 +1,177 @@
|
||||
+#!/bin/bash
|
||||
+
|
||||
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
+# isula-build licensed under the Mulan PSL v2.
|
||||
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+# You may obtain a copy of Mulan PSL v2 at:
|
||||
+# http://license.coscl.org.cn/MulanPSL2
|
||||
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+# PURPOSE.
|
||||
+# See the Mulan PSL v2 for more details.
|
||||
+# Author: Weizheng Xing
|
||||
+# Create: 2022-01-10
|
||||
+# Description: common functions for isula-build base commands tests
|
||||
+
|
||||
+top_dir=$(git rev-parse --show-toplevel)
|
||||
+# shellcheck disable=SC1091
|
||||
+source "$top_dir"/tests/lib/common.sh
|
||||
+
|
||||
+# cross process environment for killing isula-builder
|
||||
+declare -x pidofbuilder
|
||||
+
|
||||
+# check if legacy builder exists
|
||||
+function pre_check() {
|
||||
+ if pgrep isula-builder >/dev/null 2>&1; then
|
||||
+ echo "isula-builder is already running, please stop it first"
|
||||
+ exit 1
|
||||
+ fi
|
||||
+}
|
||||
+
|
||||
+# start isula-builder
|
||||
+function start_isula_builder() {
|
||||
+ nohup isula-builder >/tmp/buildlog-daemon 2>&1 &
|
||||
+ pidofbuilder=$!
|
||||
+
|
||||
+ # check if isula-builder is started
|
||||
+ builder_started=0
|
||||
+ for _ in $(seq 1 30); do
|
||||
+ if ! grep -i "is listening on" /tmp/buildlog-daemon >/dev/null 2>&1; then
|
||||
+ sleep 0.1
|
||||
+ continue
|
||||
+ else
|
||||
+ builder_started=1
|
||||
+ break
|
||||
+ fi
|
||||
+ done
|
||||
+ if [ "${builder_started}" -eq 0 ]; then
|
||||
+ echo "isula-builder start failed, log dir /tmp/buildlog-daemon"
|
||||
+ exit 1
|
||||
+ fi
|
||||
+}
|
||||
+
|
||||
+function cleanup() {
|
||||
+ isula-build ctr-img rm -p >/dev/null 2>&1
|
||||
+ kill -15 "${pidofbuilder}" >/dev/null 2>&1
|
||||
+ rm -f /tmp/buildlog-*
|
||||
+}
|
||||
+
|
||||
+# isula-build builds with different output
|
||||
+# $1 (image name)
|
||||
+# $2 (build context dir)
|
||||
+function test_isula_build_output() {
|
||||
+ local -r image_name="$1"
|
||||
+ local -r context_dir="$2"
|
||||
+
|
||||
+ functions=(
|
||||
+ test_build_without_output_with_docker_format
|
||||
+ test_build_without_output_with_oci_format
|
||||
+ test_build_with_docker_archive_output
|
||||
+ test_build_with_oci_archive_output
|
||||
+ test_build_with_docker_daemon_output
|
||||
+ test_build_with_isulad_output
|
||||
+ )
|
||||
+
|
||||
+ for function in "${functions[@]}"; do $function "$image_name" "$context_dir"; done
|
||||
+}
|
||||
+
|
||||
+# test build image without output with default docker format
|
||||
+function test_build_without_output_with_docker_format() {
|
||||
+ commands=(
|
||||
+ "isula-build ctr-img build --format docker --tag $1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+}
|
||||
+
|
||||
+# test build image without output with oci format
|
||||
+function test_build_without_output_with_oci_format() {
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --format oci --tag $1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+}
|
||||
+
|
||||
+# test build image with docker-archive output
|
||||
+function test_build_with_docker_archive_output() {
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=docker-archive:/tmp/$1.tar:$1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ rm -f /tmp/"$1".tar
|
||||
+}
|
||||
+
|
||||
+# test build image with oci-archive output
|
||||
+function test_build_with_oci_archive_output() {
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=oci-archive:/tmp/$1.tar:$1:latest $2"
|
||||
+ "isula-build ctr-img rm $1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ rm -f /tmp/"$1".tar
|
||||
+}
|
||||
+
|
||||
+# test build image with docker-daemon output
|
||||
+function test_build_with_docker_daemon_output() {
|
||||
+ if ! systemctl status docker >/dev/null 2>&1; then
|
||||
+ return 0
|
||||
+ fi
|
||||
+
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=docker-daemon:isula/$1:latest $2"
|
||||
+ "isula-build ctr-img rm isula/$1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ docker rmi isula/"$1" >/dev/null 2>&1
|
||||
+}
|
||||
+
|
||||
+# test build image with isulad output
|
||||
+function test_build_with_isulad_output() {
|
||||
+ if ! systemctl status isulad >/dev/null 2>&1; then
|
||||
+ return 0
|
||||
+ fi
|
||||
+
|
||||
+ declare -a commands=(
|
||||
+ "isula-build ctr-img build --output=isulad:isula/$1:latest $2"
|
||||
+ "isula-build ctr-img rm isula/$1:latest"
|
||||
+ )
|
||||
+ for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
+ isula rmi isula/"$1" >/dev/null 2>&1
|
||||
+}
|
||||
+
|
||||
+# test isula build base command
|
||||
+function test_isula_build_base_command() {
|
||||
+ declare -A commands=(
|
||||
+ ["Build docker format image"]="isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:/tmp/$1-docker.tar:$1-docker:latest $2"
|
||||
+ ["Build oci format image"]="isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:/tmp/$1-oci.tar:$1-oci:latest $2"
|
||||
+ ["List all images"]="isula-build ctr-img images"
|
||||
+ ["List docker format image"]="isula-build ctr-img images $1-docker:latest"
|
||||
+ ["List oci format image"]="isula-build ctr-img images $1-oci:latest"
|
||||
+ ["Save image with docker format"]="isula-build ctr-img save -f docker $1-docker:latest -o /tmp/$1-save-docker.tar"
|
||||
+ ["Save image with oci format"]="isula-build ctr-img save -f oci $1-oci:latest -o /tmp/$1-save-oci.tar"
|
||||
+ ["Load docker format images"]="isula-build ctr-img load -i /tmp/$1-docker.tar"
|
||||
+ ["Load oci format images"]="isula-build ctr-img load -i /tmp/$1-oci.tar"
|
||||
+ ["Save multipile images with docker format"]="isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o /tmp/$1-all.tar"
|
||||
+ ["Remove images"]="isula-build ctr-img rm $1-docker:latest $1-oci:latest"
|
||||
+ )
|
||||
+ declare -a orders
|
||||
+ orders+=("Build docker format image")
|
||||
+ orders+=("Build oci format image")
|
||||
+ orders+=("List all images")
|
||||
+ orders+=("List docker format image")
|
||||
+ orders+=("List oci format image")
|
||||
+ orders+=("Save image with docker format")
|
||||
+ orders+=("Save image with oci format")
|
||||
+ orders+=("Load docker format images")
|
||||
+ orders+=("Load oci format images")
|
||||
+ orders+=("Save multipile images with docker format")
|
||||
+ orders+=("Remove images")
|
||||
+ for i in "${!orders[@]}"; do
|
||||
+ show_and_run_command "${orders[$i]}" "${commands[${orders[$i]}]}"
|
||||
+ done
|
||||
+
|
||||
+ rm -f /tmp/*.tar
|
||||
+}
|
||||
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
|
||||
index 3c031f9..3710f62 100755
|
||||
--- a/tests/lib/common.sh
|
||||
+++ b/tests/lib/common.sh
|
||||
@@ -12,154 +12,10 @@
|
||||
# Author: Danni Xia
|
||||
# Create: 2020-03-01
|
||||
# Description: common functions for tests
|
||||
+# History: 2022-01-10 Weizheng Xing <xingweizheng@huawei.com> Refactor: only maintain the most common functions here
|
||||
|
||||
-# cross process environment for killing isula-builder
|
||||
-declare -x pidofbuilder
|
||||
-
|
||||
-# check if legacy builder exists
|
||||
-function pre_check() {
|
||||
- if pgrep isula-builder >/dev/null 2>&1; then
|
||||
- echo "isula-builder is already running, please stop it first"
|
||||
- exit 1
|
||||
- fi
|
||||
-}
|
||||
-
|
||||
-# start isula-builder
|
||||
-function start_isula_builder() {
|
||||
- nohup isula-builder >/tmp/buildlog-daemon 2>&1 &
|
||||
- pidofbuilder=$!
|
||||
-
|
||||
- # check if isula-builder is started
|
||||
- builder_started=0
|
||||
- for _ in $(seq 1 30); do
|
||||
- if ! grep -i "is listening on" /tmp/buildlog-daemon >/dev/null 2>&1; then
|
||||
- sleep 0.1
|
||||
- continue
|
||||
- else
|
||||
- builder_started=1
|
||||
- break
|
||||
- fi
|
||||
- done
|
||||
- if [ "${builder_started}" -eq 0 ]; then
|
||||
- echo "isula-builder start failed, log dir /tmp/buildlog-daemon"
|
||||
- exit 1
|
||||
- fi
|
||||
-}
|
||||
-
|
||||
-function cleanup() {
|
||||
- isula-build ctr-img rm -p >/dev/null 2>&1
|
||||
- kill -15 "${pidofbuilder}" >/dev/null 2>&1
|
||||
- rm -f /tmp/buildlog-*
|
||||
-}
|
||||
-
|
||||
-# test build image without output with default docker format
|
||||
-function test_build_without_output() {
|
||||
- commands=(
|
||||
- "isula-build ctr-img build --format docker --tag $1:latest $2"
|
||||
- "isula-build ctr-img rm $1:latest"
|
||||
- )
|
||||
-
|
||||
- for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
-}
|
||||
-
|
||||
-# test build image without output with oci format
|
||||
-function test_build_without_output_with_oci_format() {
|
||||
- declare -a commands=(
|
||||
- "isula-build ctr-img build --format oci --tag $1:latest $2"
|
||||
- "isula-build ctr-img rm $1:latest"
|
||||
- )
|
||||
- for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
-}
|
||||
-
|
||||
-# test build image with docker-archive output
|
||||
-function test_build_with_docker_archive_output() {
|
||||
- declare -a commands=(
|
||||
- "isula-build ctr-img build --output=docker-archive:/tmp/$1.tar:$1:latest $2"
|
||||
- "isula-build ctr-img rm $1:latest"
|
||||
- )
|
||||
- for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
- rm -f /tmp/"$1".tar
|
||||
-}
|
||||
-
|
||||
-# test build image with oci-archive output
|
||||
-function test_build_with_oci_archive_output() {
|
||||
- declare -a commands=(
|
||||
- "isula-build ctr-img build --output=oci-archive:/tmp/$1.tar:$1:latest $2"
|
||||
- "isula-build ctr-img rm $1:latest"
|
||||
- )
|
||||
- for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
- rm -f /tmp/"$1".tar
|
||||
-}
|
||||
-
|
||||
-# test build image with docker-daemon output
|
||||
-function test_build_with_docker_daemon_output() {
|
||||
- if ! systemctl status docker >/dev/null 2>&1; then
|
||||
- return 0
|
||||
- fi
|
||||
-
|
||||
- declare -a commands=(
|
||||
- "isula-build ctr-img build --output=docker-daemon:isula/$1:latest $2"
|
||||
- "isula-build ctr-img rm isula/$1:latest"
|
||||
- )
|
||||
- for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
- docker rmi isula/"$1" >/dev/null 2>&1
|
||||
-}
|
||||
-
|
||||
-# test build image with isulad output
|
||||
-function test_build_with_isulad_output() {
|
||||
- if ! systemctl status isulad >/dev/null 2>&1; then
|
||||
- return 0
|
||||
- fi
|
||||
-
|
||||
- declare -a commands=(
|
||||
- "isula-build ctr-img build --output=isulad:isula/$1:latest $2"
|
||||
- "isula-build ctr-img rm isula/$1:latest"
|
||||
- )
|
||||
- for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
- isula rmi isula/"$1" >/dev/null 2>&1
|
||||
-}
|
||||
-
|
||||
-# test isula build base command
|
||||
-function test_isula_build_base_command() {
|
||||
- declare -A commands=(
|
||||
- ["Build docker format image"]="isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:/tmp/$1-docker.tar:$1-docker:latest $2"
|
||||
- ["Build oci format image"]="isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:/tmp/$1-oci.tar:$1-oci:latest $2"
|
||||
- ["List all images"]="isula-build ctr-img images"
|
||||
- ["List docker format image"]="isula-build ctr-img images $1-docker:latest"
|
||||
- ["List oci format image"]="isula-build ctr-img images $1-oci:latest"
|
||||
- ["Save image with docker format"]="isula-build ctr-img save -f docker $1-docker:latest -o /tmp/$1-save-docker.tar"
|
||||
- ["Save image with oci format"]="isula-build ctr-img save -f oci $1-oci:latest -o /tmp/$1-save-oci.tar"
|
||||
- ["Load docker format images"]="isula-build ctr-img load -i /tmp/$1-docker.tar"
|
||||
- ["Load oci format images"]="isula-build ctr-img load -i /tmp/$1-oci.tar"
|
||||
- ["Save multipile images with docker format"]="isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o /tmp/$1-all.tar"
|
||||
- ["Remove images"]="isula-build ctr-img rm $1-docker:latest $1-oci:latest"
|
||||
- )
|
||||
- declare -a orders
|
||||
- orders+=("Build docker format image")
|
||||
- orders+=("Build oci format image")
|
||||
- orders+=("List all images")
|
||||
- orders+=("List docker format image")
|
||||
- orders+=("List oci format image")
|
||||
- orders+=("Save image with docker format")
|
||||
- orders+=("Save image with oci format")
|
||||
- orders+=("Load docker format images")
|
||||
- orders+=("Load oci format images")
|
||||
- orders+=("Save multipile images with docker format")
|
||||
- orders+=("Remove images")
|
||||
- for i in "${!orders[@]}"; do
|
||||
- show_and_run_command "${orders[$i]}" "${commands[${orders[$i]}]}"
|
||||
- done
|
||||
-
|
||||
- rm -f /tmp/*.tar
|
||||
-}
|
||||
-
|
||||
-# print callstack of shell function
|
||||
-function shell_print_callstack() {
|
||||
- echo "Shell Function Call Stack:"
|
||||
- for ((index = 1; index < ${#FUNCNAME[@]}; index++)); do
|
||||
- printf "\t%d - %s\n" "$((index - 1))" "${FUNCNAME[index]} (${BASH_SOURCE[index + 1]}:${BASH_LINENO[index]})"
|
||||
- done
|
||||
-}
|
||||
+# exit_flag for a testcase, which will be added one when check or command goes something wrong
|
||||
+exit_flag=0
|
||||
|
||||
# show command brief and run
|
||||
# $1 (command brief)
|
||||
@@ -182,13 +38,11 @@ function show_and_run_command() {
|
||||
fi
|
||||
local -r brief="$1"
|
||||
local -r command="$2"
|
||||
- printf "%-45s" "$brief"":"
|
||||
+ printf "%-45s" "$brief:"
|
||||
run_command
|
||||
echo "PASS"
|
||||
}
|
||||
|
||||
-exit_flag=0
|
||||
-
|
||||
# run command when isula-builder running in systemd mode
|
||||
# $1 (concrete command)
|
||||
function systemd_run_command() {
|
||||
@@ -217,12 +71,14 @@ function run_check_result() {
|
||||
|
||||
eval "$command" >/dev/null 2>&1
|
||||
result=$?
|
||||
+ debug "expected $expected, get $result"
|
||||
if [ "$result" != "$expected" ]; then
|
||||
- debug "expected $expected, get $result"
|
||||
testcase_path="${BASH_SOURCE[1]}"
|
||||
testcase="${testcase_path##/*/}"
|
||||
- echo "$testcase:${BASH_LINENO[0]}" "$command" >>/tmp/buildlog-failed
|
||||
- echo expected "$expected", get "$result" >>/tmp/buildlog-failed
|
||||
+ {
|
||||
+ echo "$testcase:${BASH_LINENO[0]}" "$command"
|
||||
+ echo expected "$expected", get "$result"
|
||||
+ } >>/tmp/buildlog-failed
|
||||
((exit_flag++))
|
||||
fi
|
||||
}
|
||||
@@ -233,13 +89,15 @@ function run_check_result() {
|
||||
function check_value() {
|
||||
local -r result="$1"
|
||||
local -r expected="$2"
|
||||
+ debug "expected $expected, get $result"
|
||||
|
||||
if [ "$result" != "$expected" ]; then
|
||||
- debug "expected $expected, get $result"
|
||||
testcase_path="${BASH_SOURCE[1]}"
|
||||
testcase="${testcase_path##/*/}"
|
||||
- echo "TESTCASE: $testcase:${BASH_LINENO[0]}" "${FUNCNAME[0]}" >>/tmp/buildlog-failed
|
||||
- echo expected "$expected", get "$result" >>/tmp/buildlog-failed
|
||||
+ {
|
||||
+ echo "TESTCASE: $testcase:${BASH_LINENO[0]}" "${FUNCNAME[0]}"
|
||||
+ echo expected "$expected", get "$result"
|
||||
+ } >>/tmp/buildlog-failed
|
||||
((exit_flag++))
|
||||
fi
|
||||
}
|
||||
@@ -254,26 +112,10 @@ function debug() {
|
||||
fi
|
||||
}
|
||||
|
||||
-run_root="/var/run/integration-isula-build"
|
||||
-data_root="/var/lib/integration-isula-build"
|
||||
-config_file="/etc/isula-build/configuration.toml"
|
||||
-
|
||||
-function pre_integration() {
|
||||
- rm -rf /tmp/buildlog-failed
|
||||
-
|
||||
- cp $config_file "$config_file".integration
|
||||
- sed -i "/run_root/d;/data_root/d" $config_file
|
||||
- echo "run_root = \"${run_root}\"" >>$config_file
|
||||
- echo "data_root = \"${data_root}\"" >>$config_file
|
||||
-
|
||||
- systemctl restart isula-build
|
||||
-}
|
||||
-
|
||||
-function after_integration() {
|
||||
- systemd_run_command "isula-build ctr-img rm -a"
|
||||
-
|
||||
- rm -f $config_file
|
||||
- mv "$config_file".integration $config_file
|
||||
- systemctl stop isula-build
|
||||
- rm -rf $run_root $data_root
|
||||
+# print callstack of shell function
|
||||
+function shell_print_callstack() {
|
||||
+ echo "Shell Function Call Stack:"
|
||||
+ for ((index = 1; index < ${#FUNCNAME[@]}; index++)); do
|
||||
+ printf "\t%d - %s\n" "$((index - 1))" "${FUNCNAME[index]} (${BASH_SOURCE[index + 1]}:${BASH_LINENO[index]})"
|
||||
+ done
|
||||
}
|
||||
diff --git a/tests/lib/integration_commonlib.sh b/tests/lib/integration_commonlib.sh
|
||||
new file mode 100644
|
||||
index 0000000..9dcc415
|
||||
--- /dev/null
|
||||
+++ b/tests/lib/integration_commonlib.sh
|
||||
@@ -0,0 +1,42 @@
|
||||
+#!/bin/bash
|
||||
+
|
||||
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
+# isula-build licensed under the Mulan PSL v2.
|
||||
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+# You may obtain a copy of Mulan PSL v2 at:
|
||||
+# http://license.coscl.org.cn/MulanPSL2
|
||||
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+# PURPOSE.
|
||||
+# See the Mulan PSL v2 for more details.
|
||||
+# Author: Weizheng Xing
|
||||
+# Create: 2022-01-10
|
||||
+# Description: common functions for isula-build integration tests
|
||||
+
|
||||
+top_dir=$(git rev-parse --show-toplevel)
|
||||
+# shellcheck disable=SC1091
|
||||
+source "$top_dir"/tests/lib/common.sh
|
||||
+
|
||||
+run_root="/var/run/integration-isula-build"
|
||||
+data_root="/var/lib/integration-isula-build"
|
||||
+config_file="/etc/isula-build/configuration.toml"
|
||||
+
|
||||
+function pre_integration() {
|
||||
+ rm -f /tmp/buildlog-failed
|
||||
+
|
||||
+ cp $config_file "$config_file".integration
|
||||
+ sed -i "/run_root/d;/data_root/d" $config_file
|
||||
+ echo "run_root = \"${run_root}\"" >>$config_file
|
||||
+ echo "data_root = \"${data_root}\"" >>$config_file
|
||||
+
|
||||
+ systemctl restart isula-build
|
||||
+}
|
||||
+
|
||||
+function after_integration() {
|
||||
+ systemd_run_command "isula-build ctr-img rm -a"
|
||||
+
|
||||
+ rm -f $config_file
|
||||
+ mv "$config_file".integration $config_file
|
||||
+ systemctl stop isula-build
|
||||
+ rm -rf $run_root $data_root
|
||||
+}
|
||||
diff --git a/tests/src/isula_build_base_command.sh b/tests/src/isula_build_base_command.sh
|
||||
new file mode 100644
|
||||
index 0000000..157a747
|
||||
--- /dev/null
|
||||
+++ b/tests/src/isula_build_base_command.sh
|
||||
@@ -0,0 +1,44 @@
|
||||
+#!/bin/bash
|
||||
+
|
||||
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
+# isula-build licensed under the Mulan PSL v2.
|
||||
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+# You may obtain a copy of Mulan PSL v2 at:
|
||||
+# http://license.coscl.org.cn/MulanPSL2
|
||||
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+# PURPOSE.
|
||||
+# See the Mulan PSL v2 for more details.
|
||||
+# Author: Weizheng Xing
|
||||
+# Create: 2021-01-12
|
||||
+# Description: test isula-build base commands
|
||||
+
|
||||
+top_dir=$(git rev-parse --show-toplevel)
|
||||
+source "$top_dir"/tests/lib/base_commonlib.sh
|
||||
+
|
||||
+function test_isula_build_output_with_different_dockerfiles() {
|
||||
+ declare -A dockerfiles=(
|
||||
+ ["build-from-scratch"]="$top_dir"/tests/data/build-from-scratch
|
||||
+ ["add-chown-basic"]="$top_dir"/tests/data/add-chown-basic
|
||||
+ ["multi-files-env"]="$top_dir"/tests/data/multi-files-env
|
||||
+ ["multi-stage-builds"]="$top_dir"/tests/data/multi-stage-builds
|
||||
+ )
|
||||
+
|
||||
+ for image_name in "${!dockerfiles[@]}"; do
|
||||
+ printf "%-45s" "Outputs with dockerfile $image_name:"
|
||||
+ test_isula_build_output "$image_name" "${dockerfiles[$image_name]}"
|
||||
+ echo "PASS"
|
||||
+ done
|
||||
+}
|
||||
+
|
||||
+function test_isula_build_all_base_command() {
|
||||
+ image_name=build-from-scratch
|
||||
+ context_dir="$top_dir"/tests/data/build-from-scratch
|
||||
+
|
||||
+ test_isula_build_base_command "$image_name" "$context_dir"
|
||||
+ echo "PASS"
|
||||
+}
|
||||
+
|
||||
+echo ""
|
||||
+test_isula_build_output_with_different_dockerfiles
|
||||
+test_isula_build_all_base_command
|
||||
diff --git a/tests/src/test_add_chown_basic.sh b/tests/src/test_add_chown_basic.sh
|
||||
deleted file mode 100755
|
||||
index 1ae55cc..0000000
|
||||
--- a/tests/src/test_add_chown_basic.sh
|
||||
+++ /dev/null
|
||||
@@ -1,28 +0,0 @@
|
||||
-#!/bin/bash
|
||||
-
|
||||
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
-# isula-build licensed under the Mulan PSL v2.
|
||||
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
-# You may obtain a copy of Mulan PSL v2 at:
|
||||
-# http://license.coscl.org.cn/MulanPSL2
|
||||
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
-# PURPOSE.
|
||||
-# See the Mulan PSL v2 for more details.
|
||||
-# Author: Danni Xia
|
||||
-# Create: 2020-08-27
|
||||
-# Description: dockerfile test add-chown-basic
|
||||
-
|
||||
-top_dir=$(git rev-parse --show-toplevel)
|
||||
-source "$top_dir"/tests/lib/common.sh
|
||||
-
|
||||
-image_name=add-chown-basic
|
||||
-context_dir="$top_dir"/tests/data/add-chown-basic
|
||||
-test_build_without_output "$image_name" "$context_dir"
|
||||
-test_build_without_output_with_oci_format "$image_name" "$context_dir"
|
||||
-test_build_with_docker_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_oci_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_docker_daemon_output "$image_name" "$context_dir"
|
||||
-test_build_with_isulad_output "$image_name" "$context_dir"
|
||||
-
|
||||
-echo "PASS"
|
||||
diff --git a/tests/src/test_build_from_scratch.sh b/tests/src/test_build_from_scratch.sh
|
||||
deleted file mode 100755
|
||||
index 6279d4a..0000000
|
||||
--- a/tests/src/test_build_from_scratch.sh
|
||||
+++ /dev/null
|
||||
@@ -1,28 +0,0 @@
|
||||
-#!/bin/bash
|
||||
-
|
||||
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
-# isula-build licensed under the Mulan PSL v2.
|
||||
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
-# You may obtain a copy of Mulan PSL v2 at:
|
||||
-# http://license.coscl.org.cn/MulanPSL2
|
||||
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
-# PURPOSE.
|
||||
-# See the Mulan PSL v2 for more details.
|
||||
-# Author: Danni Xia
|
||||
-# Create: 2020-08-27
|
||||
-# Description: dockerfile test test-build-from-scratch
|
||||
-
|
||||
-top_dir=$(git rev-parse --show-toplevel)
|
||||
-source "$top_dir"/tests/lib/common.sh
|
||||
-
|
||||
-image_name=build-from-scratch
|
||||
-context_dir="$top_dir"/tests/data/build-from-scratch
|
||||
-test_build_without_output "$image_name" "$context_dir"
|
||||
-test_build_without_output_with_oci_format "$image_name" "$context_dir"
|
||||
-test_build_with_docker_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_oci_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_docker_daemon_output "$image_name" "$context_dir"
|
||||
-test_build_with_isulad_output "$image_name" "$context_dir"
|
||||
-
|
||||
-echo "PASS"
|
||||
diff --git a/tests/src/test_ctr_img_rm.sh b/tests/src/test_ctr_img_rm.sh
|
||||
index 480e074..4f40544 100755
|
||||
--- a/tests/src/test_ctr_img_rm.sh
|
||||
+++ b/tests/src/test_ctr_img_rm.sh
|
||||
@@ -12,13 +12,12 @@
|
||||
# Author: Jingxiao Lu
|
||||
# Create: 2020-09-07
|
||||
# Description: dockerfile test multi-stage-builds
|
||||
+# History: 2022-01-10 Weizheng Xing <xingweizheng@huawei.com> change to integration test and use run_check_result
|
||||
+
|
||||
+top_dir=$(git rev-parse --show-toplevel)
|
||||
+# shellcheck disable=SC1091
|
||||
+source "$top_dir"/tests/lib/common.sh
|
||||
|
||||
nonexistent_image="foo:bar"
|
||||
# rm an nonexistent image
|
||||
-isula-build ctr-img rm ${nonexistent_image} > /dev/null 2>&1
|
||||
-if [ $? -eq 0 ]; then
|
||||
- echo "FAIL"
|
||||
- exit 1
|
||||
-fi
|
||||
-
|
||||
-echo "PASS"
|
||||
+run_check_result "isula-build ctr-img rm ${nonexistent_image}" "1"
|
||||
diff --git a/tests/src/integration_test_image_name_conflict_with_image_id.sh b/tests/src/test_image_name_conflict_with_image_id.sh
|
||||
similarity index 100%
|
||||
rename from tests/src/integration_test_image_name_conflict_with_image_id.sh
|
||||
rename to tests/src/test_image_name_conflict_with_image_id.sh
|
||||
diff --git a/tests/src/test_isula_build_base_command.sh b/tests/src/test_isula_build_base_command.sh
|
||||
deleted file mode 100644
|
||||
index 35b9e91..0000000
|
||||
--- a/tests/src/test_isula_build_base_command.sh
|
||||
+++ /dev/null
|
||||
@@ -1,26 +0,0 @@
|
||||
-#!/bin/bash
|
||||
-
|
||||
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
-# isula-build licensed under the Mulan PSL v2.
|
||||
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
-# You may obtain a copy of Mulan PSL v2 at:
|
||||
-# http://license.coscl.org.cn/MulanPSL2
|
||||
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
-# PURPOSE.
|
||||
-# See the Mulan PSL v2 for more details.
|
||||
-# Author: Weizheng Xing
|
||||
-# Create: 2021-01-12
|
||||
-# Description: test isula-build base commands
|
||||
-
|
||||
-top_dir=$(git rev-parse --show-toplevel)
|
||||
-source "$top_dir"/tests/lib/common.sh
|
||||
-
|
||||
-image_name=build-from-scratch
|
||||
-context_dir="$top_dir"/tests/data/build-from-scratch
|
||||
-
|
||||
-echo ""
|
||||
-
|
||||
-test_isula_build_base_command "$image_name" "$context_dir"
|
||||
-
|
||||
-echo "PASS"
|
||||
\ No newline at end of file
|
||||
diff --git a/tests/src/test_multi_files_env.sh b/tests/src/test_multi_files_env.sh
|
||||
deleted file mode 100755
|
||||
index 437e6f5..0000000
|
||||
--- a/tests/src/test_multi_files_env.sh
|
||||
+++ /dev/null
|
||||
@@ -1,28 +0,0 @@
|
||||
-#!/bin/bash
|
||||
-
|
||||
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
-# isula-build licensed under the Mulan PSL v2.
|
||||
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
-# You may obtain a copy of Mulan PSL v2 at:
|
||||
-# http://license.coscl.org.cn/MulanPSL2
|
||||
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
-# PURPOSE.
|
||||
-# See the Mulan PSL v2 for more details.
|
||||
-# Author: Danni Xia
|
||||
-# Create: 2020-08-27
|
||||
-# Description: dockerfile test multi-files-env
|
||||
-
|
||||
-top_dir=$(git rev-parse --show-toplevel)
|
||||
-source "$top_dir"/tests/lib/common.sh
|
||||
-
|
||||
-image_name=multi-files-env
|
||||
-context_dir="$top_dir"/tests/data/multi-files-env
|
||||
-test_build_without_output "$image_name" "$context_dir"
|
||||
-test_build_without_output_with_oci_format "$image_name" "$context_dir"
|
||||
-test_build_with_docker_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_oci_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_docker_daemon_output "$image_name" "$context_dir"
|
||||
-test_build_with_isulad_output "$image_name" "$context_dir"
|
||||
-
|
||||
-echo "PASS"
|
||||
diff --git a/tests/src/test_multi_stage_builds.sh b/tests/src/test_multi_stage_builds.sh
|
||||
deleted file mode 100755
|
||||
index 5fcd351..0000000
|
||||
--- a/tests/src/test_multi_stage_builds.sh
|
||||
+++ /dev/null
|
||||
@@ -1,28 +0,0 @@
|
||||
-#!/bin/bash
|
||||
-
|
||||
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
-# isula-build licensed under the Mulan PSL v2.
|
||||
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
-# You may obtain a copy of Mulan PSL v2 at:
|
||||
-# http://license.coscl.org.cn/MulanPSL2
|
||||
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
-# PURPOSE.
|
||||
-# See the Mulan PSL v2 for more details.
|
||||
-# Author: Danni Xia
|
||||
-# Create: 2020-08-27
|
||||
-# Description: dockerfile test multi-stage-builds
|
||||
-
|
||||
-top_dir=$(git rev-parse --show-toplevel)
|
||||
-source "$top_dir"/tests/lib/common.sh
|
||||
-
|
||||
-image_name=multi-stage-builds
|
||||
-context_dir="$top_dir"/tests/data/multi-stage-builds
|
||||
-test_build_without_output "$image_name" "$context_dir"
|
||||
-test_build_without_output_with_oci_format "$image_name" "$context_dir"
|
||||
-test_build_with_docker_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_oci_archive_output "$image_name" "$context_dir"
|
||||
-test_build_with_docker_daemon_output "$image_name" "$context_dir"
|
||||
-test_build_with_isulad_output "$image_name" "$context_dir"
|
||||
-
|
||||
-echo "PASS"
|
||||
diff --git a/tests/src/integration_test_save_single_image_multiple_tags.sh b/tests/src/test_save_single_image_multiple_tags.sh
|
||||
similarity index 100%
|
||||
rename from tests/src/integration_test_save_single_image_multiple_tags.sh
|
||||
rename to tests/src/test_save_single_image_multiple_tags.sh
|
||||
diff --git a/tests/src/integration_test_set_new_root.sh b/tests/src/test_set_new_root.sh
|
||||
similarity index 100%
|
||||
rename from tests/src/integration_test_set_new_root.sh
|
||||
rename to tests/src/test_set_new_root.sh
|
||||
diff --git a/tests/test.sh b/tests/test.sh
|
||||
index df29c22..6cf78c9 100755
|
||||
--- a/tests/test.sh
|
||||
+++ b/tests/test.sh
|
||||
@@ -4,7 +4,7 @@ top_dir=$(git rev-parse --show-toplevel)
|
||||
|
||||
# base test
|
||||
function base() {
|
||||
- source "$top_dir"/tests/lib/common.sh
|
||||
+ source "$top_dir"/tests/lib/base_commonlib.sh
|
||||
pre_check
|
||||
start_isula_builder
|
||||
|
||||
@@ -13,7 +13,7 @@ function base() {
|
||||
if ! bash "$testfile"; then
|
||||
exit 1
|
||||
fi
|
||||
- done < <(find "$top_dir"/tests/src -maxdepth 1 -name "test_*" -type f -print)
|
||||
+ done < <(find "$top_dir"/tests/src -maxdepth 1 -name "isula_build_base_command.sh" -type f -print)
|
||||
|
||||
cleanup
|
||||
}
|
||||
@@ -35,7 +35,7 @@ function fuzz() {
|
||||
|
||||
# integration test
|
||||
function integration() {
|
||||
- source "$top_dir"/tests/lib/common.sh
|
||||
+ source "$top_dir"/tests/lib/integration_commonlib.sh
|
||||
pre_integration
|
||||
|
||||
while IFS= read -r testfile; do
|
||||
@@ -45,7 +45,7 @@ function integration() {
|
||||
continue
|
||||
fi
|
||||
echo "PASS"
|
||||
- done < <(find "$top_dir"/tests/src -maxdepth 1 -name "integration_test*" -type f -print)
|
||||
+ done < <(find "$top_dir"/tests/src -maxdepth 1 -name "test_*" -type f -print)
|
||||
after_integration
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
300
patch/0108-integration-test-use-TMPDIR.patch
Normal file
300
patch/0108-integration-test-use-TMPDIR.patch
Normal file
@ -0,0 +1,300 @@
|
||||
From fbe5b10f83fa060ca2c2e2c3a6dc943dc9a878a2 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Tue, 11 Jan 2022 15:59:18 +0800
|
||||
Subject: [PATCH 07/20] integration test use TMPDIR
|
||||
|
||||
---
|
||||
tests/lib/base_commonlib.sh | 33 ++++++++++---------
|
||||
tests/lib/common.sh | 21 ++++++++----
|
||||
tests/lib/integration_commonlib.sh | 2 +-
|
||||
tests/src/isula_build_base_command.sh | 0
|
||||
.../test_image_name_conflict_with_image_id.sh | 12 +++----
|
||||
.../test_save_single_image_multiple_tags.sh | 5 +--
|
||||
tests/src/test_set_new_root.sh | 0
|
||||
tests/test.sh | 8 +++--
|
||||
8 files changed, 46 insertions(+), 35 deletions(-)
|
||||
mode change 100644 => 100755 tests/src/isula_build_base_command.sh
|
||||
mode change 100644 => 100755 tests/src/test_image_name_conflict_with_image_id.sh
|
||||
mode change 100644 => 100755 tests/src/test_save_single_image_multiple_tags.sh
|
||||
mode change 100644 => 100755 tests/src/test_set_new_root.sh
|
||||
|
||||
diff --git a/tests/lib/base_commonlib.sh b/tests/lib/base_commonlib.sh
|
||||
index 996fcdd..8893894 100644
|
||||
--- a/tests/lib/base_commonlib.sh
|
||||
+++ b/tests/lib/base_commonlib.sh
|
||||
@@ -30,13 +30,13 @@ function pre_check() {
|
||||
|
||||
# start isula-builder
|
||||
function start_isula_builder() {
|
||||
- nohup isula-builder >/tmp/buildlog-daemon 2>&1 &
|
||||
+ nohup isula-builder >"$TMPDIR"/buildlog-daemon 2>&1 &
|
||||
pidofbuilder=$!
|
||||
|
||||
# check if isula-builder is started
|
||||
builder_started=0
|
||||
for _ in $(seq 1 30); do
|
||||
- if ! grep -i "is listening on" /tmp/buildlog-daemon >/dev/null 2>&1; then
|
||||
+ if ! grep -i "is listening on" "$TMPDIR"/buildlog-daemon >/dev/null 2>&1; then
|
||||
sleep 0.1
|
||||
continue
|
||||
else
|
||||
@@ -45,7 +45,8 @@ function start_isula_builder() {
|
||||
fi
|
||||
done
|
||||
if [ "${builder_started}" -eq 0 ]; then
|
||||
- echo "isula-builder start failed, log dir /tmp/buildlog-daemon"
|
||||
+ echo "isula-builder start failed, log dir $TMPDIR/buildlog-daemon"
|
||||
+ cat "$TMPDIR"/buildlog-daemon
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -53,7 +54,7 @@ function start_isula_builder() {
|
||||
function cleanup() {
|
||||
isula-build ctr-img rm -p >/dev/null 2>&1
|
||||
kill -15 "${pidofbuilder}" >/dev/null 2>&1
|
||||
- rm -f /tmp/buildlog-*
|
||||
+ rm -rf "$TMPDIR"
|
||||
}
|
||||
|
||||
# isula-build builds with different output
|
||||
@@ -97,21 +98,21 @@ function test_build_without_output_with_oci_format() {
|
||||
# test build image with docker-archive output
|
||||
function test_build_with_docker_archive_output() {
|
||||
declare -a commands=(
|
||||
- "isula-build ctr-img build --output=docker-archive:/tmp/$1.tar:$1:latest $2"
|
||||
+ "isula-build ctr-img build --output=docker-archive:$TMPDIR/$1.tar:$1:latest $2"
|
||||
"isula-build ctr-img rm $1:latest"
|
||||
)
|
||||
for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
- rm -f /tmp/"$1".tar
|
||||
+ rm -f "$TMPDIR"/"$1".tar
|
||||
}
|
||||
|
||||
# test build image with oci-archive output
|
||||
function test_build_with_oci_archive_output() {
|
||||
declare -a commands=(
|
||||
- "isula-build ctr-img build --output=oci-archive:/tmp/$1.tar:$1:latest $2"
|
||||
+ "isula-build ctr-img build --output=oci-archive:$TMPDIR/$1.tar:$1:latest $2"
|
||||
"isula-build ctr-img rm $1:latest"
|
||||
)
|
||||
for command in "${commands[@]}"; do show_and_run_command "$command"; done
|
||||
- rm -f /tmp/"$1".tar
|
||||
+ rm -f "$TMPDIR"/"$1".tar
|
||||
}
|
||||
|
||||
# test build image with docker-daemon output
|
||||
@@ -145,16 +146,16 @@ function test_build_with_isulad_output() {
|
||||
# test isula build base command
|
||||
function test_isula_build_base_command() {
|
||||
declare -A commands=(
|
||||
- ["Build docker format image"]="isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:/tmp/$1-docker.tar:$1-docker:latest $2"
|
||||
- ["Build oci format image"]="isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:/tmp/$1-oci.tar:$1-oci:latest $2"
|
||||
+ ["Build docker format image"]="isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:$TMPDIR/$1-docker.tar:$1-docker:latest $2"
|
||||
+ ["Build oci format image"]="isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:$TMPDIR/$1-oci.tar:$1-oci:latest $2"
|
||||
["List all images"]="isula-build ctr-img images"
|
||||
["List docker format image"]="isula-build ctr-img images $1-docker:latest"
|
||||
["List oci format image"]="isula-build ctr-img images $1-oci:latest"
|
||||
- ["Save image with docker format"]="isula-build ctr-img save -f docker $1-docker:latest -o /tmp/$1-save-docker.tar"
|
||||
- ["Save image with oci format"]="isula-build ctr-img save -f oci $1-oci:latest -o /tmp/$1-save-oci.tar"
|
||||
- ["Load docker format images"]="isula-build ctr-img load -i /tmp/$1-docker.tar"
|
||||
- ["Load oci format images"]="isula-build ctr-img load -i /tmp/$1-oci.tar"
|
||||
- ["Save multipile images with docker format"]="isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o /tmp/$1-all.tar"
|
||||
+ ["Save image with docker format"]="isula-build ctr-img save -f docker $1-docker:latest -o $TMPDIR/$1-save-docker.tar"
|
||||
+ ["Save image with oci format"]="isula-build ctr-img save -f oci $1-oci:latest -o $TMPDIR/$1-save-oci.tar"
|
||||
+ ["Load docker format images"]="isula-build ctr-img load -i $TMPDIR/$1-docker.tar"
|
||||
+ ["Load oci format images"]="isula-build ctr-img load -i $TMPDIR/$1-oci.tar"
|
||||
+ ["Save multipile images with docker format"]="isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o $TMPDIR/$1-all.tar"
|
||||
["Remove images"]="isula-build ctr-img rm $1-docker:latest $1-oci:latest"
|
||||
)
|
||||
declare -a orders
|
||||
@@ -173,5 +174,5 @@ function test_isula_build_base_command() {
|
||||
show_and_run_command "${orders[$i]}" "${commands[${orders[$i]}]}"
|
||||
done
|
||||
|
||||
- rm -f /tmp/*.tar
|
||||
+ rm -f "$TMPDIR"/*.tar
|
||||
}
|
||||
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
|
||||
index 3710f62..c600616 100755
|
||||
--- a/tests/lib/common.sh
|
||||
+++ b/tests/lib/common.sh
|
||||
@@ -16,16 +16,23 @@
|
||||
|
||||
# exit_flag for a testcase, which will be added one when check or command goes something wrong
|
||||
exit_flag=0
|
||||
+# TMPDIR use in all base or integration test process
|
||||
+declare -x TMPDIR
|
||||
+
|
||||
+# only run once for create a temp dir
|
||||
+function create_tmp_dir() {
|
||||
+ TMPDIR=$(mktemp -d)
|
||||
+}
|
||||
|
||||
# show command brief and run
|
||||
# $1 (command brief)
|
||||
# $2 (concrete command)
|
||||
function show_and_run_command() {
|
||||
function run_command() {
|
||||
- if ! $command >/tmp/buildlog-client 2>&1; then
|
||||
+ if ! $command >"$TMPDIR"/buildlog-client 2>&1; then
|
||||
echo "FAIL"
|
||||
echo "Failed when running command: $command"
|
||||
- echo "LOG DIR:/tmp/buildlog-client and /tmp/buildlog-daemon"
|
||||
+ echo "LOG DIR:$TMPDIR/buildlog-client and $TMPDIR/buildlog-daemon"
|
||||
kill -15 "${pidofbuilder}"
|
||||
shell_print_callstack
|
||||
exit 1
|
||||
@@ -49,14 +56,14 @@ function systemd_run_command() {
|
||||
local -r command="$1"
|
||||
|
||||
start_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
- if ! $command >/tmp/buildlog-client 2>&1; then
|
||||
+ if ! $command >"$TMPDIR"/buildlog-client 2>&1; then
|
||||
{
|
||||
echo "Error from client:"
|
||||
- cat /tmp/buildlog-client
|
||||
+ cat "$TMPDIR"/buildlog-client
|
||||
echo "Error from daemon:"
|
||||
journalctl -u isula-build --since "$start_time" --no-pager
|
||||
shell_print_callstack
|
||||
- } >>/tmp/buildlog-failed
|
||||
+ } >>"$TMPDIR"/buildlog-failed
|
||||
|
||||
((exit_flag++))
|
||||
fi
|
||||
@@ -78,7 +85,7 @@ function run_check_result() {
|
||||
{
|
||||
echo "$testcase:${BASH_LINENO[0]}" "$command"
|
||||
echo expected "$expected", get "$result"
|
||||
- } >>/tmp/buildlog-failed
|
||||
+ } >>"$TMPDIR"/buildlog-failed
|
||||
((exit_flag++))
|
||||
fi
|
||||
}
|
||||
@@ -97,7 +104,7 @@ function check_value() {
|
||||
{
|
||||
echo "TESTCASE: $testcase:${BASH_LINENO[0]}" "${FUNCNAME[0]}"
|
||||
echo expected "$expected", get "$result"
|
||||
- } >>/tmp/buildlog-failed
|
||||
+ } >>"$TMPDIR"/buildlog-failed
|
||||
((exit_flag++))
|
||||
fi
|
||||
}
|
||||
diff --git a/tests/lib/integration_commonlib.sh b/tests/lib/integration_commonlib.sh
|
||||
index 9dcc415..44f186f 100644
|
||||
--- a/tests/lib/integration_commonlib.sh
|
||||
+++ b/tests/lib/integration_commonlib.sh
|
||||
@@ -22,7 +22,7 @@ data_root="/var/lib/integration-isula-build"
|
||||
config_file="/etc/isula-build/configuration.toml"
|
||||
|
||||
function pre_integration() {
|
||||
- rm -f /tmp/buildlog-failed
|
||||
+ rm -f "$TMPDIR"/buildlog-failed
|
||||
|
||||
cp $config_file "$config_file".integration
|
||||
sed -i "/run_root/d;/data_root/d" $config_file
|
||||
diff --git a/tests/src/isula_build_base_command.sh b/tests/src/isula_build_base_command.sh
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
diff --git a/tests/src/test_image_name_conflict_with_image_id.sh b/tests/src/test_image_name_conflict_with_image_id.sh
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
index 2c436a0..cbcc353
|
||||
--- a/tests/src/test_image_name_conflict_with_image_id.sh
|
||||
+++ b/tests/src/test_image_name_conflict_with_image_id.sh
|
||||
@@ -35,7 +35,7 @@ function clean() {
|
||||
function do_test() {
|
||||
systemd_run_command "isula-build ctr-img build -t $image_name:latest1 $context_dir"
|
||||
systemd_run_command "isula-build ctr-img build -t $image_name:latest2 $context_dir"
|
||||
- image_id2=$(grep </tmp/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
+ image_id2=$(grep <"$TMPDIR"/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
short_id2=${image_id2:0:12}
|
||||
double_short_id2=${short_id2:0:6}
|
||||
|
||||
@@ -51,11 +51,11 @@ function do_test() {
|
||||
|
||||
# analyse it
|
||||
declare -a commands=(
|
||||
- "cat /tmp/buildlog-client |grep $short_id2"
|
||||
- "tar -xvf $temp_tar_short -C /tmp manifest.json"
|
||||
- "cat /tmp/manifest.json | grep $short_id2:latest"
|
||||
- "tar -xvf $temp_tar_double_short -C /tmp manifest.json"
|
||||
- "cat /tmp/manifest.json | grep $image_id2"
|
||||
+ "cat $TMPDIR/buildlog-client |grep $short_id2"
|
||||
+ "tar -xvf $temp_tar_short -C $TMPDIR manifest.json"
|
||||
+ "cat $TMPDIR/manifest.json | grep $short_id2:latest"
|
||||
+ "tar -xvf $temp_tar_double_short -C $TMPDIR manifest.json"
|
||||
+ "cat $TMPDIR/manifest.json | grep $image_id2"
|
||||
)
|
||||
for command in "${commands[@]}"; do run_check_result "$command" 0; done
|
||||
}
|
||||
diff --git a/tests/src/test_save_single_image_multiple_tags.sh b/tests/src/test_save_single_image_multiple_tags.sh
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
index 46df444..7e8491e
|
||||
--- a/tests/src/test_save_single_image_multiple_tags.sh
|
||||
+++ b/tests/src/test_save_single_image_multiple_tags.sh
|
||||
@@ -15,6 +15,7 @@
|
||||
# History: 2022-01-10 Weizheng Xing <xingweizheng@huawei.com> Refactor: use systemd_run_command common function
|
||||
|
||||
top_dir=$(git rev-parse --show-toplevel)
|
||||
+# shellcheck disable=SC1091
|
||||
source "$top_dir"/tests/lib/common.sh
|
||||
|
||||
image_name=build-from-scratch
|
||||
@@ -27,10 +28,10 @@ function pre_test() {
|
||||
function do_test() {
|
||||
# get image id
|
||||
systemd_run_command "isula-build ctr-img build -t $image_name:latest $context_dir"
|
||||
- image_id1=$(grep </tmp/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
+ image_id1=$(grep <"$TMPDIR"/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
|
||||
systemd_run_command "isula-build ctr-img build -t $image_name:latest2 $context_dir"
|
||||
- image_id2=$(grep </tmp/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
+ image_id2=$(grep <"$TMPDIR"/buildlog-client "Build success with image id: " | cut -d ":" -f 2)
|
||||
|
||||
declare -a commands=(
|
||||
"isula-build ctr-img tag $image_name:latest $image_name:latest-child"
|
||||
diff --git a/tests/src/test_set_new_root.sh b/tests/src/test_set_new_root.sh
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
diff --git a/tests/test.sh b/tests/test.sh
|
||||
index 6cf78c9..3f2785b 100755
|
||||
--- a/tests/test.sh
|
||||
+++ b/tests/test.sh
|
||||
@@ -1,11 +1,12 @@
|
||||
#!/bin/bash
|
||||
-
|
||||
+# shellcheck disable=SC1091
|
||||
top_dir=$(git rev-parse --show-toplevel)
|
||||
|
||||
# base test
|
||||
function base() {
|
||||
source "$top_dir"/tests/lib/base_commonlib.sh
|
||||
pre_check
|
||||
+ create_tmp_dir
|
||||
start_isula_builder
|
||||
|
||||
while IFS= read -r testfile; do
|
||||
@@ -22,8 +23,8 @@ function base() {
|
||||
function fuzz() {
|
||||
failed=0
|
||||
while IFS= read -r testfile; do
|
||||
- printf "%-45s" "test $(basename "$testfile"): " | tee -a ${top_dir}/tests/fuzz.log
|
||||
- bash "$testfile" "$1" | tee -a ${top_dir}/tests/fuzz.log
|
||||
+ printf "%-45s" "test $(basename "$testfile"): " | tee -a "$top_dir"/tests/fuzz.log
|
||||
+ bash "$testfile" "$1" | tee -a "$top_dir"/tests/fuzz.log
|
||||
if [ $PIPESTATUS -ne 0 ]; then
|
||||
failed=1
|
||||
fi
|
||||
@@ -36,6 +37,7 @@ function fuzz() {
|
||||
# integration test
|
||||
function integration() {
|
||||
source "$top_dir"/tests/lib/integration_commonlib.sh
|
||||
+ create_tmp_dir
|
||||
pre_integration
|
||||
|
||||
while IFS= read -r testfile; do
|
||||
--
|
||||
2.27.0
|
||||
|
||||
113
patch/0109-better-display-of-integration-test.patch
Normal file
113
patch/0109-better-display-of-integration-test.patch
Normal file
@ -0,0 +1,113 @@
|
||||
From 4b8086307bf4ef4951bf9377338578d1908e41cc Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Tue, 11 Jan 2022 15:59:50 +0800
|
||||
Subject: [PATCH 08/20] better display of integration test
|
||||
|
||||
---
|
||||
tests/lib/common.sh | 6 +++---
|
||||
tests/lib/integration_commonlib.sh | 12 ++++++++++--
|
||||
tests/test.sh | 15 +++++++++++++--
|
||||
3 files changed, 26 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
|
||||
index c600616..b67361e 100755
|
||||
--- a/tests/lib/common.sh
|
||||
+++ b/tests/lib/common.sh
|
||||
@@ -78,7 +78,7 @@ function run_check_result() {
|
||||
|
||||
eval "$command" >/dev/null 2>&1
|
||||
result=$?
|
||||
- debug "expected $expected, get $result"
|
||||
+ debug "run command: $command, expected $expected, get $result"
|
||||
if [ "$result" != "$expected" ]; then
|
||||
testcase_path="${BASH_SOURCE[1]}"
|
||||
testcase="${testcase_path##/*/}"
|
||||
@@ -96,7 +96,7 @@ function run_check_result() {
|
||||
function check_value() {
|
||||
local -r result="$1"
|
||||
local -r expected="$2"
|
||||
- debug "expected $expected, get $result"
|
||||
+ debug "check value: expected $expected, get $result"
|
||||
|
||||
if [ "$result" != "$expected" ]; then
|
||||
testcase_path="${BASH_SOURCE[1]}"
|
||||
@@ -115,7 +115,7 @@ function debug() {
|
||||
local -r message="$1"
|
||||
|
||||
if [ "$TEST_DEBUG" == "true" ]; then
|
||||
- printf "(%s %s) " "DEBUG:" "$message"
|
||||
+ echo -e " \tDEBUG:" "$message"
|
||||
fi
|
||||
}
|
||||
|
||||
diff --git a/tests/lib/integration_commonlib.sh b/tests/lib/integration_commonlib.sh
|
||||
index 44f186f..de8dde5 100644
|
||||
--- a/tests/lib/integration_commonlib.sh
|
||||
+++ b/tests/lib/integration_commonlib.sh
|
||||
@@ -22,8 +22,6 @@ data_root="/var/lib/integration-isula-build"
|
||||
config_file="/etc/isula-build/configuration.toml"
|
||||
|
||||
function pre_integration() {
|
||||
- rm -f "$TMPDIR"/buildlog-failed
|
||||
-
|
||||
cp $config_file "$config_file".integration
|
||||
sed -i "/run_root/d;/data_root/d" $config_file
|
||||
echo "run_root = \"${run_root}\"" >>$config_file
|
||||
@@ -32,11 +30,21 @@ function pre_integration() {
|
||||
systemctl restart isula-build
|
||||
}
|
||||
|
||||
+# clean test dir
|
||||
+# $1 (failed testcases)
|
||||
function after_integration() {
|
||||
+ local -r failed="$1"
|
||||
+
|
||||
systemd_run_command "isula-build ctr-img rm -a"
|
||||
|
||||
rm -f $config_file
|
||||
mv "$config_file".integration $config_file
|
||||
systemctl stop isula-build
|
||||
rm -rf $run_root $data_root
|
||||
+
|
||||
+ if [ $((failed)) -eq 0 ]; then
|
||||
+ rm -rf "$TMPDIR"
|
||||
+ else
|
||||
+ echo "Please check $TMPDIR/buildlog-failed for more information."
|
||||
+ fi
|
||||
}
|
||||
diff --git a/tests/test.sh b/tests/test.sh
|
||||
index 3f2785b..c949a4e 100755
|
||||
--- a/tests/test.sh
|
||||
+++ b/tests/test.sh
|
||||
@@ -40,15 +40,26 @@ function integration() {
|
||||
create_tmp_dir
|
||||
pre_integration
|
||||
|
||||
+ all=0
|
||||
+ failed=0
|
||||
while IFS= read -r testfile; do
|
||||
+ ((all++))
|
||||
printf "%-65s" "test $(basename "$testfile"): "
|
||||
+ if [ "$TEST_DEBUG" == true ]; then
|
||||
+ echo ""
|
||||
+ fi
|
||||
+
|
||||
if ! bash "$testfile"; then
|
||||
+ ((failed++))
|
||||
echo "FAIL"
|
||||
continue
|
||||
fi
|
||||
- echo "PASS"
|
||||
+ echo -e "\033[32mPASS\033[0m"
|
||||
done < <(find "$top_dir"/tests/src -maxdepth 1 -name "test_*" -type f -print)
|
||||
- after_integration
|
||||
+ after_integration "$failed"
|
||||
+
|
||||
+ rate=$(echo "scale=2; $((all - failed)) * 100 / $all" | bc)
|
||||
+ echo -e "\033[32m| $(date "+%Y-%m-%d-%H-%M-%S") | Total Testcases: $all | FAIL: $failed | PASS: $((all - failed)) | PASS RATE: $rate %|\033[0m"
|
||||
}
|
||||
|
||||
# main function to chose which kind of test
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,394 @@
|
||||
From 864a0aec0d089d774a9ef1bf796815d740e9162d Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Wed, 12 Jan 2022 16:17:02 +0800
|
||||
Subject: [PATCH 09/20] fix some mistakes and update doc with version 0.9.6-4
|
||||
|
||||
---
|
||||
doc/manual_en.md | 102 ++++++++++++++++++++++++-----------------------
|
||||
doc/manual_zh.md | 70 +++++++++++++++++---------------
|
||||
2 files changed, 90 insertions(+), 82 deletions(-)
|
||||
|
||||
diff --git a/doc/manual_en.md b/doc/manual_en.md
|
||||
index 8fcb333..ab65aec 100644
|
||||
--- a/doc/manual_en.md
|
||||
+++ b/doc/manual_en.md
|
||||
@@ -26,11 +26,11 @@
|
||||
* [login: Logging In to the Remote Image Repository](#login-logging-in-to-the-remote-image-repository)
|
||||
* [logout: Logging Out of the Remote Image Repository](#logout-logging-out-of-the-remote-image-repository)
|
||||
* [version: Querying the isula-build Version](#version-querying-the-isula-build-version)
|
||||
- * [manifest: Manage manifest list(experimental feature)](#manifest-Manage-manifest-list)
|
||||
- * [create: Create a manifest list](#create-Create-a-manifest-list)
|
||||
- * [annotate: Update a manifest list](#annotate-Update-a-manifest-list)
|
||||
- * [inspect: Inspect a manifest list](#inspect-Inspect-a-manifest-list)
|
||||
- * [push: Push manifest list to repository](#push-Push-manifest-list-to-repository)
|
||||
+ * [manifest: Manage manifest list(experimental feature)](#manifest-Manifest-List-Management)
|
||||
+ * [create: Create a manifest list](#create-Manifest-List-Creation)
|
||||
+ * [annotate: Update a manifest list](#annotate-Manifest-List-Update)
|
||||
+ * [inspect: Inspect a manifest list](#inspect-Manifest-List-Inspect)
|
||||
+ * [push: Push manifest list to repository](#push-Manifest-List-Push-to-the-Remote-Repository)
|
||||
* [Directly Integrating a Container Engine](#directly-integrating-a-container-engine)
|
||||
* [Integration with iSulad](#integration-with-isulad)
|
||||
* [Integration with Docker](#integration-with-docker)
|
||||
@@ -48,7 +48,7 @@ isula-build is a container image build tool developed by the iSula container tea
|
||||
|
||||
The isula-build uses the server/client mode. The isula-build functions as a client and provides a group of command line tools for image build and management. The isula-builder functions as the server, processes client management requests, and functions as the daemon process in the background.
|
||||
|
||||
-
|
||||
+
|
||||
|
||||
> **Note:**
|
||||
>
|
||||
@@ -80,7 +80,7 @@ Before using isula-build to build a container image, you need to install the fol
|
||||
|
||||
**Method 2: Using the RPM Package**
|
||||
|
||||
-1. Obtain the isula-build-\*.rpm installation package from the openEuler yum source, for example, isula-build-0.9.3-1.oe1.x86_64.rpm.
|
||||
+1. Obtain the isula-build-*.rpm installation package from the openEuler yum source, for example, isula-build-0.9.6-4.oe1.x86_64.rpm.
|
||||
|
||||
2. Upload the obtained RPM software package to any directory on the target server, for example, /home/.
|
||||
|
||||
@@ -107,7 +107,7 @@ Currently, the isula-build server contains the following configuration file:
|
||||
| Configuration Item | Mandatory or Optional | Description | Value |
|
||||
| --------- | -------- | --------------------------------- | ----------------------------------------------- |
|
||||
| debug | Optional | Indicates whether to enable the debug log function. | true: Enable the debug log function. false: Disable the debug log function. |
|
||||
-| loglevel | Optional | Sets the log level. | debug, info, warn, error |
|
||||
+| loglevel | Optional | Sets the log level. | debug<br/>info<br/>warn<br/>error |
|
||||
| run_root | Mandatory | Sets the root directory of runtime data. | For example, /var/run/isula-build/ |
|
||||
| data_root | Mandatory | Sets the local persistency directory. | For example, /var/lib/isula-build/ |
|
||||
| runtime | Optional | Sets the runtime type. Currently, only runc is supported. | runc |
|
||||
@@ -197,7 +197,7 @@ You can also run the isula-builder command on the server to start the service. T
|
||||
Start the isula-build service. For example, to specify the local persistency directory /var/lib/isula-build and disable debugging, run the following command:
|
||||
|
||||
```sh
|
||||
-sudo isula-builder --dataroot "/var/lib/isula-build"
|
||||
+sudo isula-builder --dataroot "/var/lib/isula-build" --debug=false
|
||||
```
|
||||
|
||||
## Usage Guidelines
|
||||
@@ -369,7 +369,7 @@ $ cat testfile
|
||||
|
||||
**\-o, --output**
|
||||
|
||||
-Currently, -o and –output support the following formats:
|
||||
+Currently, -o and --output support the following formats:
|
||||
|
||||
- `isulad:image:tag`: directly pushes the image that is successfully built to iSulad, for example, `-o isulad:busybox:latest`. Pay attention to the following restrictions:
|
||||
|
||||
@@ -460,7 +460,7 @@ localhost:5000/library/alpine latest a24bb4013296
|
||||
|
||||
#### import: Importing a Basic Container Image
|
||||
|
||||
-openEuler releases a basic container image, for example, openEuler-docker.x86_64.tar.xz, with the version. You can run the `ctr-img import` command to import the image to isula-build.
|
||||
+A tar file in rootfs form can be imported into isula-build via the `ctr-img import` command.
|
||||
|
||||
The command is as follows:
|
||||
|
||||
@@ -471,13 +471,18 @@ isula-build ctr-img import [flags]
|
||||
Example:
|
||||
|
||||
```sh
|
||||
-$ sudo isula-build ctr-img import ./openEuler-docker.x86_64.tar.xz openeuler:20.09
|
||||
-Import success with image id: 7317851cd2ab33263eb293f68efee9d724780251e4e92c0fb76bf5d3c5585e37
|
||||
+$ sudo isula-build ctr-img import busybox.tar mybusybox:latest
|
||||
+Getting image source signatures
|
||||
+Copying blob sha256:7b8667757578df68ec57bfc9fb7754801ec87df7de389a24a26a7bf2ebc04d8d
|
||||
+Copying config sha256:173b3cf612f8e1dc34e78772fcf190559533a3b04743287a32d549e3c7d1c1d1
|
||||
+Writing manifest to image destination
|
||||
+Storing signatures
|
||||
+Import success with image id: "173b3cf612f8e1dc34e78772fcf190559533a3b04743287a32d549e3c7d1c1d1"
|
||||
$ sudo isula-build ctr-img images
|
||||
---------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
---------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
-openeuler 20.09 7317851cd2ab 2020-08-01 06:25:34 500 MB
|
||||
+mybusybox latest 173b3cf612f8 2022-01-12 16:02:31 1.47 MB
|
||||
---------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
@@ -566,8 +571,8 @@ isula-build ctr-img rm IMAGE [IMAGE...] [FLAGS]
|
||||
|
||||
Currently, the following flags are supported:
|
||||
|
||||
-- -a, –all: deletes all images stored locally.
|
||||
-- -p, –prune: deletes all images that are stored locally and do not have tags.
|
||||
+- -a, --all: deletes all images stored locally.
|
||||
+- -p, --prune: deletes all images that are stored locally and do not have tags.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -774,7 +779,7 @@ You can run the isula-build info command to view the running environment and sys
|
||||
|
||||
The following flags are supported:
|
||||
|
||||
-- -H, –human-readable: Boolean. The memory information is printed in the common memory format. The value is 1000 power.
|
||||
+- -H, --human-readable: Boolean. The memory information is printed in the common memory format. The value is 1000 power.
|
||||
- -V, --verbose: Boolean. The memory usage is displayed during system running.
|
||||
|
||||
Example:
|
||||
@@ -867,39 +872,39 @@ Example:
|
||||
You can run the version command to view the current version information.
|
||||
|
||||
```sh
|
||||
- $ sudo isula-build version
|
||||
- Client:
|
||||
- Version: 0.9.4
|
||||
- Go Version: go1.13.3
|
||||
- Git Commit: 0038365c
|
||||
- Built: Tue Nov 24 16:32:05 2020
|
||||
- OS/Arch: linux/amd64
|
||||
+$ sudo isula-build version
|
||||
+Client:
|
||||
+ Version: 0.9.6-4
|
||||
+ Go Version: go1.15.7
|
||||
+ Git Commit: 83274e0
|
||||
+ Built: Wed Jan 12 15:32:55 2022
|
||||
+ OS/Arch: linux/amd64
|
||||
|
||||
- Server:
|
||||
- Version: 0.9.4
|
||||
- Go Version: go1.13.3
|
||||
- Git Commit: 0038365c
|
||||
- Built: Tue Nov 24 16:32:05 2020
|
||||
- OS/Arch: linux/amd64
|
||||
+Server:
|
||||
+ Version: 0.9.6-4
|
||||
+ Go Version: go1.15.7
|
||||
+ Git Commit: 83274e0
|
||||
+ Built: Wed Jan 12 15:32:55 2022
|
||||
+ OS/Arch: linux/amd64
|
||||
```
|
||||
|
||||
-### manifest: Manage manifest list
|
||||
+### manifest: Manifest List Management
|
||||
|
||||
-manifest list includes images refer to different architectures. By using manifest list, users could use the same manifest name(for example: openeuler:latest) in different architectures to get the corresponding image. Manifest includes subcommands create/annotate/inspcet/push.
|
||||
+The manifest list contains the image information corresponding to different system architectures. You can use the same manifest (for example, openeuler:latest) in different architectures to obtain the image of the corresponding architecture. The manifest contains the create, annotate, inspect, and push subcommands.
|
||||
|
||||
> **NOTE:**
|
||||
>
|
||||
-> - manifest is experimental feature, users need to enable experimental features both on client and server, see client overview and configuring the isula-build service sections for details.
|
||||
+> - manifest is an experiment feature. When using this feature, you need to enable the experiment options on the client and server. For details, see Client Overview and Configuring Services.
|
||||
|
||||
-#### create: Create a manifest list
|
||||
+#### create: Manifest List Creation
|
||||
|
||||
-manifest create subcommand is used to create manifest list. The command is as follows:
|
||||
+The create subcommand of the manifest command is used to create a manifest list. The command prototype is as follows:
|
||||
|
||||
```
|
||||
isula-build manifest create MANIFEST_LIST MANIFEST [MANIFEST...]
|
||||
```
|
||||
|
||||
-Users could specify manifest list name and images added to list, if no image is specified, an empty list will be created.
|
||||
+You can specify the name of the manifest list and the remote images to be added to the list. If no remote image is specified, an empty manifest list is created.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -907,25 +912,22 @@ Example:
|
||||
$ sudo isula-build manifest create openeuler localhost:5000/openeuler_x86:latest localhost:5000/openeuler_aarch64:latest
|
||||
```
|
||||
|
||||
-#### annotate: Update a manifest list
|
||||
+#### annotate: Manifest List Update
|
||||
|
||||
-manifest annotate subcommand is used to update manifest list. The command is as follows:
|
||||
+The annotate subcommand of the manifest command is used to update the manifest list. The command prototype is as follows:
|
||||
|
||||
```
|
||||
isula-build manifest annotate MANIFEST_LIST MANIFEST [flags]
|
||||
```
|
||||
|
||||
-Users could specify the manifest list and the image needed to update, with options by flags. This command could also be used to add new image to the list.
|
||||
+You can specify the manifest list to be updated and the images in the manifest list, and use flags to specify the options to be updated. This command can also be used to add new images to the manifest list.
|
||||
|
||||
Currently, the following flags are supported:
|
||||
|
||||
-```
|
||||
-Flags:
|
||||
- --arch string Set architecture
|
||||
- --os string Set operating system
|
||||
- --os-features strings Set operating system feature
|
||||
- --variant string Set architecture variant
|
||||
-```
|
||||
+- --arch: Applicable architecture of the rewritten image. The value is a string.
|
||||
+- --os: Indicates the applicable system of the image. The value is a string.
|
||||
+- --os-features: Specifies the OS features required by the image. This parameter is a string and rarely used.
|
||||
+- --variant: Variable of the image recorded in the list. The value is a string.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -933,9 +935,9 @@ Example:
|
||||
$ sudo isula-build manifest annotate --os linux --arch arm64 openeuler:latest localhost:5000/openeuler_aarch64:latest
|
||||
```
|
||||
|
||||
-#### inspect: Inspect a manifest list
|
||||
+#### inspect: Manifest List Inspect
|
||||
|
||||
-manifest inspect subcommand is used to inspect manifest list. The command is as follows:
|
||||
+The inspect subcommand of the manifest command is used to query the manifest list. The command prototype is as follows:
|
||||
|
||||
```
|
||||
isula-build manifest inspect MANIFEST_LIST
|
||||
@@ -971,9 +973,9 @@ $ sudo isula-build manifest inspect openeuler:latest
|
||||
}
|
||||
```
|
||||
|
||||
-#### push: Push manifest list to repository
|
||||
+#### push: Manifest List Push to the Remote Repository.
|
||||
|
||||
-manifest push subcommand is used to push manifest list to remote repository. The command is as follows:
|
||||
+The manifest subcommand push is used to push the manifest list to the remote repository. The command prototype is as follows:
|
||||
|
||||
```
|
||||
isula-build manifest push MANIFEST_LIST DESTINATION
|
||||
diff --git a/doc/manual_zh.md b/doc/manual_zh.md
|
||||
index c5303f8..d3d63b0 100644
|
||||
--- a/doc/manual_zh.md
|
||||
+++ b/doc/manual_zh.md
|
||||
@@ -48,7 +48,7 @@ isula-build是iSula容器团队推出的容器镜像构建工具,支持通过D
|
||||
|
||||
isula-build采用服务端/客户端模式,其中,isula-build为客户端,提供了一组命令行工具,用于镜像构建及管理等;isula-builder为服务端,用于处理客户端管理请求,作为守护进程常驻后台。
|
||||
|
||||
-
|
||||
+
|
||||
|
||||
> **说明**:
|
||||
>
|
||||
@@ -80,7 +80,7 @@ isula-build采用服务端/客户端模式,其中,isula-build为客户端,
|
||||
|
||||
**方法二:使用rpm包安装**
|
||||
|
||||
-1. 从openEuler yum源中获取isula-build对应安装包isula-build-\*.rpm。例如isula-build-0.9.3-4.oe1.x86_64.rpm。
|
||||
+1. 从openEuler yum源中获取isula-build对应安装包isula-build-*.rpm。例如isula-build-0.9.6-4.oe1.x86_64.rpm。
|
||||
|
||||
2. 将获取的rpm软件包上传至目标服务器的任一目录,例如 /home/。
|
||||
|
||||
@@ -104,14 +104,14 @@ isula-build采用服务端/客户端模式,其中,isula-build为客户端,
|
||||
|
||||
- /etc/isula-build/configuration.toml:isula-builder 总体配置文件,用于设置 isula-builder 日志级别、持久化目录和运行时目录、OCI runtime等。其中各参数含义如下:
|
||||
|
||||
-| 配置项 | 是否可选 | 配置项含义 | 配置项取值 |
|
||||
-| ------------ | -------- | ------------------------------------------------------------ | ----------------------------------------------- |
|
||||
-| debug | 可选 | 设置是否打开debug日志 | true:打开debug日志;false:关闭debug日志 |
|
||||
-| loglevel | 可选 | 设置日志级别 | debug, info,warn,error |
|
||||
-| run_root | 必选 | 设置运行时数据根目录 | 运行时数据根目录路径,例如/var/run/isula-build/ |
|
||||
-| data_root | 必选 | 设置本地持久化目录 | 本地持久化目录路径,例如/var/lib/isula-build/ |
|
||||
-| runtime | 可选 | 设置runtime种类,目前仅支持runc | runc |
|
||||
-| group | 可选 | 设置本地套接字isula_build.sock文件属组使得加入该组的非特权用户可以操作isula-build | isula |
|
||||
+| 配置项 | 是否可选 | 配置项含义 | 配置项取值 |
|
||||
+| --------- | -------- | --------------------------------- | ----------------------------------------------- |
|
||||
+| debug | 可选 | 设置是否打开debug日志 | true:打开debug日志<br/>false:关闭debug日志 |
|
||||
+| loglevel | 可选 | 设置日志级别 | debug<br/>info<br/>warn<br/>error |
|
||||
+| run_root | 必选 | 设置运行时数据根目录 | 运行时数据根目录路径,例如/var/run/isula-build/ |
|
||||
+| data_root | 必选 | 设置本地持久化目录 | 本地持久化目录路径,例如/var/lib/isula-build/ |
|
||||
+| runtime | 可选 | 设置runtime种类,目前仅支持runc | runc |
|
||||
+| group | 可选 | 设置本地套接字isula_build.sock文件属组使得加入该组的非特权用户可以操作isula-build | isula |
|
||||
| experimental | 可选 | 设置是否开启实验特性 | true:开启实验特性;false:关闭实验特性 |
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ sudo systemctl daemon-reload
|
||||
启动 isula-build 服务。例如指定本地持久化路径/var/lib/isula-build,且不开启调试的参考命令如下:
|
||||
|
||||
```sh
|
||||
-sudo isula-builder --dataroot "/var/lib/isula-build"
|
||||
+sudo isula-builder --dataroot "/var/lib/isula-build" --debug=false
|
||||
```
|
||||
|
||||
## 使用指南
|
||||
@@ -370,7 +370,7 @@ $ cat testfile
|
||||
|
||||
**\-o, --output**
|
||||
|
||||
-目前 -o, –output 支持如下形式:
|
||||
+目前 -o, --output 支持如下形式:
|
||||
|
||||
- `isulad:image:tag`:将构建成功的镜像直接推送到 iSulad。比如:`-o isulad:busybox:latest`。同时需要注意如下约束:
|
||||
|
||||
@@ -457,7 +457,7 @@ localhost:5000/library/alpine latest a24bb4013296
|
||||
|
||||
#### import: 导入容器基础镜像
|
||||
|
||||
-openEuler会随版本发布一个容器基础镜像,比如openEuler-docker.x86_64.tar.xz。可以通过`ctr-img import`指令将它导入到 isula-build。
|
||||
+可以通过`ctr-img import`指令将rootfs形式的tar文件导入到isula-build中。
|
||||
|
||||
命令原型如下:
|
||||
|
||||
@@ -468,13 +468,18 @@ isula-build ctr-img import [flags]
|
||||
使用举例:
|
||||
|
||||
```sh
|
||||
-$ sudo isula-build ctr-img import ./openEuler-docker.x86_64.tar.xz openeuler:20.09
|
||||
-Import success with image id: 7317851cd2ab33263eb293f68efee9d724780251e4e92c0fb76bf5d3c5585e37
|
||||
+$ sudo isula-build ctr-img import busybox.tar mybusybox:latest
|
||||
+Getting image source signatures
|
||||
+Copying blob sha256:7b8667757578df68ec57bfc9fb7754801ec87df7de389a24a26a7bf2ebc04d8d
|
||||
+Copying config sha256:173b3cf612f8e1dc34e78772fcf190559533a3b04743287a32d549e3c7d1c1d1
|
||||
+Writing manifest to image destination
|
||||
+Storing signatures
|
||||
+Import success with image id: "173b3cf612f8e1dc34e78772fcf190559533a3b04743287a32d549e3c7d1c1d1"
|
||||
$ sudo isula-build ctr-img images
|
||||
---------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
---------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
-openeuler 20.09 7317851cd2ab 2020-08-01 06:25:34 500 MB
|
||||
+mybusybox latest 173b3cf612f8 2022-01-12 16:02:31 1.47 MB
|
||||
---------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
@@ -561,8 +566,8 @@ isula-build ctr-img rm IMAGE [IMAGE...] [FLAGS]
|
||||
|
||||
目前支持的 flags 为:
|
||||
|
||||
-- -a, –all:删除所有本地持久化存储的镜像。
|
||||
-- -p, –prune:删除所有没有tag的本地持久化存储的镜像。
|
||||
+- -a, --all:删除所有本地持久化存储的镜像。
|
||||
+- -p, --prune:删除所有没有tag的本地持久化存储的镜像。
|
||||
|
||||
使用示例如下:
|
||||
|
||||
@@ -863,20 +868,20 @@ $ sudo isula-build info -HV
|
||||
可通过version命令查看当前版本信息:
|
||||
|
||||
```sh
|
||||
- $ sudo isula-build version
|
||||
- Client:
|
||||
- Version: 0.9.4
|
||||
- Go Version: go1.13.3
|
||||
- Git Commit: 0038365c
|
||||
- Built: Tue Nov 24 16:32:05 2020
|
||||
- OS/Arch: linux/amd64
|
||||
-
|
||||
- Server:
|
||||
- Version: 0.9.4
|
||||
- Go Version: go1.13.3
|
||||
- Git Commit: 0038365c
|
||||
- Built: Tue Nov 24 16:32:05 2020
|
||||
- OS/Arch: linux/amd64
|
||||
+$ sudo isula-build version
|
||||
+Client:
|
||||
+ Version: 0.9.6-4
|
||||
+ Go Version: go1.15.7
|
||||
+ Git Commit: 83274e0
|
||||
+ Built: Wed Jan 12 15:32:55 2022
|
||||
+ OS/Arch: linux/amd64
|
||||
+
|
||||
+Server:
|
||||
+ Version: 0.9.6-4
|
||||
+ Go Version: go1.15.7
|
||||
+ Git Commit: 83274e0
|
||||
+ Built: Wed Jan 12 15:32:55 2022
|
||||
+ OS/Arch: linux/amd64
|
||||
```
|
||||
|
||||
### manifest: manifest列表管理
|
||||
@@ -1098,6 +1103,7 @@ busybox 2.0 2d414a5c
|
||||
| ------------ | ------------ | ---------------------------------- |
|
||||
| ctr-img save | -o, --output | string,镜像导出后在本地的存储路径 |
|
||||
| | -f, --format | string,导出层叠镜像的镜像格式:oci|docker(需开启实验特性选项)|
|
||||
+
|
||||
**表6** login 命令参数列表
|
||||
|
||||
| **命令** | **参数** | **说明** |
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,173 @@
|
||||
From 7af1077eb0d9d354f60448148dc4379247e0b8b6 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Mon, 17 Jan 2022 10:24:25 +0800
|
||||
Subject: [PATCH 10/20] fix: correct table of contents of english doc, and
|
||||
simplify images table by current list format
|
||||
|
||||
---
|
||||
doc/manual_en.md | 54 ++++++++++++++++++++++++------------------------
|
||||
doc/manual_zh.md | 44 +++++++++++++++++++--------------------
|
||||
2 files changed, 49 insertions(+), 49 deletions(-)
|
||||
|
||||
diff --git a/doc/manual_en.md b/doc/manual_en.md
|
||||
index ab65aec..e591e4f 100644
|
||||
--- a/doc/manual_en.md
|
||||
+++ b/doc/manual_en.md
|
||||
@@ -26,11 +26,11 @@
|
||||
* [login: Logging In to the Remote Image Repository](#login-logging-in-to-the-remote-image-repository)
|
||||
* [logout: Logging Out of the Remote Image Repository](#logout-logging-out-of-the-remote-image-repository)
|
||||
* [version: Querying the isula-build Version](#version-querying-the-isula-build-version)
|
||||
- * [manifest: Manage manifest list(experimental feature)](#manifest-Manifest-List-Management)
|
||||
- * [create: Create a manifest list](#create-Manifest-List-Creation)
|
||||
- * [annotate: Update a manifest list](#annotate-Manifest-List-Update)
|
||||
- * [inspect: Inspect a manifest list](#inspect-Manifest-List-Inspect)
|
||||
- * [push: Push manifest list to repository](#push-Manifest-List-Push-to-the-Remote-Repository)
|
||||
+ * [manifest: Manage manifest list(experimental feature)](#manifest-manifest-list-management)
|
||||
+ * [create: Create a manifest list](#create-manifest-list-creation)
|
||||
+ * [annotate: Update a manifest list](#annotate-manifest-list-update)
|
||||
+ * [inspect: Inspect a manifest list](#inspect-manifest-list-inspect)
|
||||
+ * [push: Push manifest list to repository](#push-manifest-list-push-to-the-remote-repository)
|
||||
* [Directly Integrating a Container Engine](#directly-integrating-a-container-engine)
|
||||
* [Integration with iSulad](#integration-with-isulad)
|
||||
* [Integration with Docker](#integration-with-docker)
|
||||
@@ -446,12 +446,12 @@ You can run the images command to view the images in the local persistent storag
|
||||
|
||||
```sh
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-localhost:5000/library/alpine latest a24bb4013296 2020-20-19 19:59:197 5.85 MB
|
||||
-<none> <none> 39b62a3342ee 2020-20-38 38:66:387 1.45 MB
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+localhost:5000/library/alpine latest a24bb4013296 2022-01-17 10:02:19 5.85 MB
|
||||
+<none> <none> 39b62a3342ee 2022-01-17 10:01:12 1.45 MB
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
> **Note:**
|
||||
@@ -479,11 +479,11 @@ Writing manifest to image destination
|
||||
Storing signatures
|
||||
Import success with image id: "173b3cf612f8e1dc34e78772fcf190559533a3b04743287a32d549e3c7d1c1d1"
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
-mybusybox latest 173b3cf612f8 2022-01-12 16:02:31 1.47 MB
|
||||
----------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+mybusybox latest 173b3cf612f8 2022-01-12 16:02:31 1.47 MB
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
> **Note:**
|
||||
@@ -705,19 +705,19 @@ Example:
|
||||
|
||||
```sh
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+--------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
+--------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
$ sudo isula-build ctr-img tag a24bb4013296 alpine:v1
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
-alpine v1 a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
+alpine v1 a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
#### pull: Pulling an Image To a Local Host
|
||||
diff --git a/doc/manual_zh.md b/doc/manual_zh.md
|
||||
index d3d63b0..41cdf43 100644
|
||||
--- a/doc/manual_zh.md
|
||||
+++ b/doc/manual_zh.md
|
||||
@@ -443,12 +443,12 @@ $ sudo isula-build ctr-img build --cap-add CAP_SYS_ADMIN --cap-add CAP_SYS_PTRAC
|
||||
|
||||
```sh
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-localhost:5000/library/alpine latest a24bb4013296 2020-20-19 19:59:197 5.85 MB
|
||||
-<none> <none> 39b62a3342ee 2020-20-38 38:66:387 1.45 MB
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+localhost:5000/library/alpine latest a24bb4013296 2022-01-17 10:02:19 5.85 MB
|
||||
+<none> <none> 39b62a3342ee 2022-01-17 10:01:12 1.45 MB
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
> **说明:**
|
||||
@@ -476,11 +476,11 @@ Writing manifest to image destination
|
||||
Storing signatures
|
||||
Import success with image id: "173b3cf612f8e1dc34e78772fcf190559533a3b04743287a32d549e3c7d1c1d1"
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
-mybusybox latest 173b3cf612f8 2022-01-12 16:02:31 1.47 MB
|
||||
----------------------------------------------- -------------------- ----------------- ------------------------ ------------
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+mybusybox latest 173b3cf612f8 2022-01-12 16:02:31 1.47 MB
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
> **说明:**
|
||||
@@ -701,19 +701,19 @@ isula-build ctr-img tag <imageID>/<imageName> busybox:latest
|
||||
|
||||
```sh
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+--------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
+--------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
$ sudo isula-build ctr-img tag a24bb4013296 alpine:v1
|
||||
$ sudo isula-build ctr-img images
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
-alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
-alpine v1 a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
----------------------------------------------- ----------- ----------------- -------------------------- ------------
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
+alpine latest a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
+alpine v1 a24bb4013296 2020-05-29 21:19:46 5.85 MB
|
||||
+--------------------------------------- ----------- ----------------- ------------------------ ------------
|
||||
```
|
||||
|
||||
#### pull: 拉取镜像到本地
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,169 @@
|
||||
From 5cc0f72ea23e6999266e4f0144298a584f6c4d90 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Tue, 25 Jan 2022 14:19:49 +0800
|
||||
Subject: [PATCH 11/20] golangcilint: fix goimports and deprecated warnings
|
||||
|
||||
---
|
||||
cmd/cli/login.go | 4 +-
|
||||
go.mod | 3 +-
|
||||
util/cipher.go | 1 +
|
||||
.../x/crypto/ssh/terminal/terminal.go | 76 -------------------
|
||||
vendor/modules.txt | 2 +-
|
||||
5 files changed, 6 insertions(+), 80 deletions(-)
|
||||
delete mode 100644 vendor/golang.org/x/crypto/ssh/terminal/terminal.go
|
||||
|
||||
diff --git a/cmd/cli/login.go b/cmd/cli/login.go
|
||||
index 06724b7..1ac74cf 100644
|
||||
--- a/cmd/cli/login.go
|
||||
+++ b/cmd/cli/login.go
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
- "golang.org/x/crypto/ssh/terminal"
|
||||
+ "golang.org/x/term"
|
||||
|
||||
pb "isula.org/isula-build/api/services"
|
||||
"isula.org/isula-build/util"
|
||||
@@ -233,7 +233,7 @@ func getPassword(c *cobra.Command) error {
|
||||
}
|
||||
} else {
|
||||
r := func() ([]byte, error) {
|
||||
- return terminal.ReadPassword(0)
|
||||
+ return term.ReadPassword(0)
|
||||
}
|
||||
if err := getPassFromInput(r); err != nil {
|
||||
return err
|
||||
diff --git a/go.mod b/go.mod
|
||||
index dbf9426..03f8f06 100644
|
||||
--- a/go.mod
|
||||
+++ b/go.mod
|
||||
@@ -30,9 +30,10 @@ require (
|
||||
github.com/spf13/cobra v1.2.1
|
||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
- golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
|
||||
+ golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881
|
||||
+ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
|
||||
google.golang.org/grpc v1.42.0
|
||||
gotest.tools/v3 v3.0.3
|
||||
)
|
||||
diff --git a/util/cipher.go b/util/cipher.go
|
||||
index fa0559a..c6fa555 100644
|
||||
--- a/util/cipher.go
|
||||
+++ b/util/cipher.go
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
+
|
||||
constant "isula.org/isula-build"
|
||||
)
|
||||
|
||||
diff --git a/vendor/golang.org/x/crypto/ssh/terminal/terminal.go b/vendor/golang.org/x/crypto/ssh/terminal/terminal.go
|
||||
deleted file mode 100644
|
||||
index a4d1919..0000000
|
||||
--- a/vendor/golang.org/x/crypto/ssh/terminal/terminal.go
|
||||
+++ /dev/null
|
||||
@@ -1,76 +0,0 @@
|
||||
-// Copyright 2011 The Go Authors. All rights reserved.
|
||||
-// Use of this source code is governed by a BSD-style
|
||||
-// license that can be found in the LICENSE file.
|
||||
-
|
||||
-// Package terminal provides support functions for dealing with terminals, as
|
||||
-// commonly found on UNIX systems.
|
||||
-//
|
||||
-// Deprecated: this package moved to golang.org/x/term.
|
||||
-package terminal
|
||||
-
|
||||
-import (
|
||||
- "io"
|
||||
-
|
||||
- "golang.org/x/term"
|
||||
-)
|
||||
-
|
||||
-// EscapeCodes contains escape sequences that can be written to the terminal in
|
||||
-// order to achieve different styles of text.
|
||||
-type EscapeCodes = term.EscapeCodes
|
||||
-
|
||||
-// Terminal contains the state for running a VT100 terminal that is capable of
|
||||
-// reading lines of input.
|
||||
-type Terminal = term.Terminal
|
||||
-
|
||||
-// NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is
|
||||
-// a local terminal, that terminal must first have been put into raw mode.
|
||||
-// prompt is a string that is written at the start of each input line (i.e.
|
||||
-// "> ").
|
||||
-func NewTerminal(c io.ReadWriter, prompt string) *Terminal {
|
||||
- return term.NewTerminal(c, prompt)
|
||||
-}
|
||||
-
|
||||
-// ErrPasteIndicator may be returned from ReadLine as the error, in addition
|
||||
-// to valid line data. It indicates that bracketed paste mode is enabled and
|
||||
-// that the returned line consists only of pasted data. Programs may wish to
|
||||
-// interpret pasted data more literally than typed data.
|
||||
-var ErrPasteIndicator = term.ErrPasteIndicator
|
||||
-
|
||||
-// State contains the state of a terminal.
|
||||
-type State = term.State
|
||||
-
|
||||
-// IsTerminal returns whether the given file descriptor is a terminal.
|
||||
-func IsTerminal(fd int) bool {
|
||||
- return term.IsTerminal(fd)
|
||||
-}
|
||||
-
|
||||
-// ReadPassword reads a line of input from a terminal without local echo. This
|
||||
-// is commonly used for inputting passwords and other sensitive data. The slice
|
||||
-// returned does not include the \n.
|
||||
-func ReadPassword(fd int) ([]byte, error) {
|
||||
- return term.ReadPassword(fd)
|
||||
-}
|
||||
-
|
||||
-// MakeRaw puts the terminal connected to the given file descriptor into raw
|
||||
-// mode and returns the previous state of the terminal so that it can be
|
||||
-// restored.
|
||||
-func MakeRaw(fd int) (*State, error) {
|
||||
- return term.MakeRaw(fd)
|
||||
-}
|
||||
-
|
||||
-// Restore restores the terminal connected to the given file descriptor to a
|
||||
-// previous state.
|
||||
-func Restore(fd int, oldState *State) error {
|
||||
- return term.Restore(fd, oldState)
|
||||
-}
|
||||
-
|
||||
-// GetState returns the current state of a terminal which may be useful to
|
||||
-// restore the terminal after a signal.
|
||||
-func GetState(fd int) (*State, error) {
|
||||
- return term.GetState(fd)
|
||||
-}
|
||||
-
|
||||
-// GetSize returns the dimensions of the given terminal.
|
||||
-func GetSize(fd int) (width, height int, err error) {
|
||||
- return term.GetSize(fd)
|
||||
-}
|
||||
diff --git a/vendor/modules.txt b/vendor/modules.txt
|
||||
index ec0b737..66a20fc 100644
|
||||
--- a/vendor/modules.txt
|
||||
+++ b/vendor/modules.txt
|
||||
@@ -413,7 +413,6 @@ golang.org/x/crypto/openpgp/errors
|
||||
golang.org/x/crypto/openpgp/packet
|
||||
golang.org/x/crypto/openpgp/s2k
|
||||
golang.org/x/crypto/pbkdf2
|
||||
-golang.org/x/crypto/ssh/terminal
|
||||
# golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
|
||||
golang.org/x/net/context
|
||||
golang.org/x/net/http/httpguts
|
||||
@@ -436,6 +435,7 @@ golang.org/x/sys/plan9
|
||||
golang.org/x/sys/unix
|
||||
golang.org/x/sys/windows
|
||||
# golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
|
||||
+## explicit
|
||||
golang.org/x/term
|
||||
# golang.org/x/text v0.3.7
|
||||
golang.org/x/text/secure/bidirule
|
||||
--
|
||||
2.27.0
|
||||
|
||||
25
patch/0113-an-ignorable-memory-copy.patch
Normal file
25
patch/0113-an-ignorable-memory-copy.patch
Normal file
@ -0,0 +1,25 @@
|
||||
From 57d0b6ea848d770edecee9c4bb3b0d055f368199 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Wed, 26 Jan 2022 20:22:42 +0800
|
||||
Subject: [PATCH 12/20] an ignorable memory copy
|
||||
|
||||
---
|
||||
builder/dockerfile/cmd_builder_commit.go | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/builder/dockerfile/cmd_builder_commit.go b/builder/dockerfile/cmd_builder_commit.go
|
||||
index da2ee4f..5480a76 100644
|
||||
--- a/builder/dockerfile/cmd_builder_commit.go
|
||||
+++ b/builder/dockerfile/cmd_builder_commit.go
|
||||
@@ -66,7 +66,7 @@ func (c *cmdBuilder) newContainerReference(exporting bool) (transc.Reference, er
|
||||
return transc.Reference{}, errors.Wrapf(err, "error encoding docker-format image configuration %#v", c.stage.docker)
|
||||
}
|
||||
|
||||
- createdBy := strings.Join(util.CopyStrings(c.stage.docker.Config.Shell), " ")
|
||||
+ createdBy := strings.Join(c.stage.docker.Config.Shell, " ")
|
||||
if createdBy == "" {
|
||||
createdBy = defaultShell
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
42
patch/0114-move-unused-func-args-to-caller.patch
Normal file
42
patch/0114-move-unused-func-args-to-caller.patch
Normal file
@ -0,0 +1,42 @@
|
||||
From be2a7daec421d1ef3873e8f293608b19ef7c5347 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Thu, 27 Jan 2022 14:17:39 +0800
|
||||
Subject: [PATCH 13/20] move unused func args to caller
|
||||
|
||||
---
|
||||
daemon/save.go | 3 ++-
|
||||
daemon/separator/save.go | 4 +---
|
||||
2 files changed, 3 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/daemon/save.go b/daemon/save.go
|
||||
index 708fab3..7206a5d 100644
|
||||
--- a/daemon/save.go
|
||||
+++ b/daemon/save.go
|
||||
@@ -111,7 +111,8 @@ func (b *Backend) Save(req *pb.SaveRequest, stream pb.Control_SaveServer) (err e
|
||||
}
|
||||
|
||||
if opts.sep.Enabled() {
|
||||
- return opts.sep.SeparateImage(opts.localStore, opts.oriImgList, opts.outputPath)
|
||||
+ opts.logEntry.Infof("Start saving separated images %v", opts.oriImgList)
|
||||
+ return opts.sep.SeparateImage(opts.localStore, opts.outputPath)
|
||||
}
|
||||
|
||||
return nil
|
||||
diff --git a/daemon/separator/save.go b/daemon/separator/save.go
|
||||
index a455335..16c9446 100644
|
||||
--- a/daemon/separator/save.go
|
||||
+++ b/daemon/separator/save.go
|
||||
@@ -84,9 +84,7 @@ func GetSepSaveOptions(req *pb.SaveRequest, logEntry *logrus.Entry, dataRoot str
|
||||
}
|
||||
|
||||
// SeparateImage the main method of Saver, tries to separated the listed images to pieces
|
||||
-func (s *Saver) SeparateImage(localStore *store.Store, oriImgList []string, outputPath string) (err error) {
|
||||
- s.log.Infof("Start saving separated images %v", oriImgList)
|
||||
-
|
||||
+func (s *Saver) SeparateImage(localStore *store.Store, outputPath string) (err error) {
|
||||
if err = os.MkdirAll(s.dest, constant.DefaultRootDirMode); err != nil {
|
||||
return err
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
816
patch/0115-refactor-tidy-file-check-in-package-util.patch
Normal file
816
patch/0115-refactor-tidy-file-check-in-package-util.patch
Normal file
@ -0,0 +1,816 @@
|
||||
From 563580c128e0c49df89bc317b7c45a6b00c2da06 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Mon, 24 Jan 2022 20:25:28 +0800
|
||||
Subject: [PATCH 14/20] refactor: tidy file check in package util
|
||||
|
||||
---
|
||||
builder/dockerfile/parser/parser.go | 2 +-
|
||||
builder/dockerfile/parser/parser_test.go | 2 +-
|
||||
builder/dockerfile/run.go | 4 +-
|
||||
cmd/cli/build.go | 47 +++++---------
|
||||
cmd/cli/import.go | 7 +--
|
||||
cmd/cli/load.go | 2 +-
|
||||
cmd/cli/load_test.go | 11 +++-
|
||||
cmd/daemon/main.go | 33 +---------
|
||||
constant.go | 8 ++-
|
||||
daemon/load.go | 2 +-
|
||||
image/context.go | 30 ++-------
|
||||
image/context_test.go | 59 -----------------
|
||||
runner/runner.go | 2 +-
|
||||
util/common.go | 46 +++-----------
|
||||
util/common_test.go | 80 +++---------------------
|
||||
util/file.go | 31 +++------
|
||||
util/file_test.go | 68 --------------------
|
||||
util/user.go | 2 +-
|
||||
18 files changed, 75 insertions(+), 361 deletions(-)
|
||||
|
||||
diff --git a/builder/dockerfile/parser/parser.go b/builder/dockerfile/parser/parser.go
|
||||
index 650c5e5..1968fc1 100644
|
||||
--- a/builder/dockerfile/parser/parser.go
|
||||
+++ b/builder/dockerfile/parser/parser.go
|
||||
@@ -304,7 +304,7 @@ func (df *dockerfile) ParseIgnore(dir string) ([]string, error) {
|
||||
}
|
||||
return ignores, errors.Wrap(err, "state dockerignore file failed")
|
||||
}
|
||||
- if err := util.CheckFileSize(fullPath, constant.MaxFileSize); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(fullPath, constant.MaxFileSize); err != nil {
|
||||
return ignores, err
|
||||
}
|
||||
|
||||
diff --git a/builder/dockerfile/parser/parser_test.go b/builder/dockerfile/parser/parser_test.go
|
||||
index 870132f..ba7fce5 100644
|
||||
--- a/builder/dockerfile/parser/parser_test.go
|
||||
+++ b/builder/dockerfile/parser/parser_test.go
|
||||
@@ -328,7 +328,7 @@ func TestParseIgnoreWithDir(t *testing.T) {
|
||||
|
||||
df := dockerfile{}
|
||||
_, err := df.ParseIgnore(ctxDir.Path())
|
||||
- assert.ErrorContains(t, err, "a directory")
|
||||
+ assert.ErrorContains(t, err, "should be a regular file")
|
||||
}
|
||||
|
||||
func TestParseWithHeadingArgs(t *testing.T) {
|
||||
diff --git a/builder/dockerfile/run.go b/builder/dockerfile/run.go
|
||||
index d33573f..5b066fb 100644
|
||||
--- a/builder/dockerfile/run.go
|
||||
+++ b/builder/dockerfile/run.go
|
||||
@@ -171,7 +171,7 @@ func setupBindFiles(bundlePath string) (map[string]string, error) {
|
||||
}
|
||||
|
||||
func generateHosts(bundlePath string) (string, error) {
|
||||
- if err := util.CheckFileSize(constant.HostsFilePath, constant.MaxFileSize); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(constant.HostsFilePath, constant.MaxFileSize); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ func generateHosts(bundlePath string) (string, error) {
|
||||
}
|
||||
|
||||
func generateResolv(bundlePath string) (string, error) {
|
||||
- if err := util.CheckFileSize(constant.ResolvFilePath, constant.MaxFileSize); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(constant.ResolvFilePath, constant.MaxFileSize); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
diff --git a/cmd/cli/build.go b/cmd/cli/build.go
|
||||
index 4b4e6f5..c9efd4e 100644
|
||||
--- a/cmd/cli/build.go
|
||||
+++ b/cmd/cli/build.go
|
||||
@@ -460,51 +460,34 @@ func readDockerfile() (string, string, error) {
|
||||
return string(buf), parts[1], nil
|
||||
}
|
||||
|
||||
-func checkDockerfile(filePath string) error {
|
||||
- fileInfo, err := os.Stat(filePath)
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- if !fileInfo.Mode().IsRegular() {
|
||||
- return errors.Errorf("file %s should be a regular file", filePath)
|
||||
- }
|
||||
- if fileInfo.Size() == 0 {
|
||||
- return errors.New("file is empty, is it a normal dockerfile?")
|
||||
- }
|
||||
- if fileInfo.Size() > constant.MaxFileSize {
|
||||
- return errors.Errorf("file is too big with size %v, is it a normal dockerfile?", fileInfo.Size())
|
||||
- }
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
func resolveDockerfilePath() (string, error) {
|
||||
var resolvedPath = buildOpts.file
|
||||
var err error
|
||||
if buildOpts.file == "" {
|
||||
// filepath is empty, try to resolve with contextDir+Dockerfile
|
||||
resolvedPath = path.Join(buildOpts.contextDir, "Dockerfile")
|
||||
- err = checkDockerfile(resolvedPath)
|
||||
- if err != nil {
|
||||
+ if err = util.CheckFileInfoAndSize(resolvedPath, constant.MaxFileSize); err != nil {
|
||||
logrus.Debugf("Stat dockerfile failed with path %s", resolvedPath)
|
||||
- return "", err
|
||||
+ return "", errors.Wrap(err, "check dockerfile failed")
|
||||
}
|
||||
+
|
||||
return resolvedPath, nil
|
||||
}
|
||||
|
||||
- err = checkDockerfile(resolvedPath)
|
||||
- if err != nil {
|
||||
- logrus.Debugf("Stat dockerfile failed with path %s", resolvedPath)
|
||||
- // not found with filepath, try to resolve with contextDir+filepath
|
||||
- resolvedPath = path.Join(buildOpts.contextDir, buildOpts.file)
|
||||
- err = checkDockerfile(resolvedPath)
|
||||
- if err != nil {
|
||||
- logrus.Debugf("Stat dockerfile failed again with path %s", resolvedPath)
|
||||
- return "", err
|
||||
- }
|
||||
+ if err = util.CheckFileInfoAndSize(resolvedPath, constant.MaxFileSize); err == nil {
|
||||
+ return resolvedPath, nil
|
||||
+ }
|
||||
+ logrus.Debugf("Stat dockerfile failed with path %s", resolvedPath)
|
||||
+
|
||||
+ // not found with filepath, try to resolve with contextDir+filepath
|
||||
+ resolvedPath = path.Join(buildOpts.contextDir, buildOpts.file)
|
||||
+ if err = util.CheckFileInfoAndSize(resolvedPath, constant.MaxFileSize); err == nil {
|
||||
+ return resolvedPath, nil
|
||||
+
|
||||
}
|
||||
+ logrus.Debugf("Stat dockerfile failed again with path %s", resolvedPath)
|
||||
|
||||
- return resolvedPath, nil
|
||||
+ return "", errors.Wrap(err, "check dockerfile failed")
|
||||
}
|
||||
|
||||
func getAbsPath(path string) (string, error) {
|
||||
diff --git a/cmd/cli/import.go b/cmd/cli/import.go
|
||||
index 96263db..40f933a 100644
|
||||
--- a/cmd/cli/import.go
|
||||
+++ b/cmd/cli/import.go
|
||||
@@ -29,9 +29,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
- maxTarballSize = 1024 * 1024 * 1024 // support tarball max size at most 1G
|
||||
- importExample = `isula-build ctr-img import busybox.tar busybox:isula`
|
||||
- importArgsLen = 1
|
||||
+ importExample = `isula-build ctr-img import busybox.tar busybox:isula`
|
||||
+ importArgsLen = 1
|
||||
)
|
||||
|
||||
type importOptions struct {
|
||||
@@ -57,7 +56,7 @@ func importCommand(c *cobra.Command, args []string) error {
|
||||
if len(args) < importArgsLen {
|
||||
return errors.New("requires at least one argument")
|
||||
}
|
||||
- if err := util.CheckFileSize(args[0], maxTarballSize); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(args[0], constant.MaxImportFileSize); err != nil {
|
||||
return err
|
||||
}
|
||||
importOpts.source = args[0]
|
||||
diff --git a/cmd/cli/load.go b/cmd/cli/load.go
|
||||
index 90d189a..363c54e 100644
|
||||
--- a/cmd/cli/load.go
|
||||
+++ b/cmd/cli/load.go
|
||||
@@ -128,7 +128,7 @@ func resolveLoadPath(path, pwd string) (string, error) {
|
||||
}
|
||||
|
||||
path = util.MakeAbsolute(path, pwd)
|
||||
- if err := util.CheckLoadFile(path); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(path, constant.MaxLoadFileSize); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
diff --git a/cmd/cli/load_test.go b/cmd/cli/load_test.go
|
||||
index cb8217c..a5b3c30 100644
|
||||
--- a/cmd/cli/load_test.go
|
||||
+++ b/cmd/cli/load_test.go
|
||||
@@ -189,14 +189,19 @@ func TestCheckLoadOpts(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
root := fs.NewDir(t, t.Name())
|
||||
defer root.Remove()
|
||||
+
|
||||
+ emptyTar := "empty.tar"
|
||||
emptyFile, err := os.Create(filepath.Join(root.Path(), "empty.tar"))
|
||||
assert.NilError(t, err)
|
||||
+
|
||||
fileWithContent, err := os.Create(filepath.Join(root.Path(), "test.tar"))
|
||||
assert.NilError(t, err)
|
||||
ioutil.WriteFile(fileWithContent.Name(), []byte("This is test file"), constant.DefaultRootFileMode)
|
||||
+
|
||||
baseFile, err := os.Create(filepath.Join(root.Path(), "base.tar"))
|
||||
assert.NilError(t, err)
|
||||
ioutil.WriteFile(baseFile.Name(), []byte("This is base file"), constant.DefaultRootFileMode)
|
||||
+
|
||||
libFile, err := os.Create(filepath.Join(root.Path(), "lib.tar"))
|
||||
ioutil.WriteFile(libFile.Name(), []byte("This is lib file"), constant.DefaultRootFileMode)
|
||||
|
||||
@@ -228,7 +233,7 @@ func TestCheckLoadOpts(t *testing.T) {
|
||||
path: emptyFile.Name(),
|
||||
},
|
||||
wantErr: true,
|
||||
- errMessage: "loading file is empty",
|
||||
+ errMessage: "file " + emptyTar + " is empty",
|
||||
},
|
||||
{
|
||||
name: "TC-separated load",
|
||||
@@ -290,7 +295,7 @@ func TestCheckLoadOpts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
- errMessage: "resolve base tarball path failed: loading file is empty",
|
||||
+ errMessage: "resolve base tarball path failed: file " + emptyTar + " is empty",
|
||||
},
|
||||
{
|
||||
name: "TC-separated load with empty lib tarball",
|
||||
@@ -303,7 +308,7 @@ func TestCheckLoadOpts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
- errMessage: "resolve lib tarball path failed: loading file is empty",
|
||||
+ errMessage: "resolve lib tarball path failed: file " + emptyTar + " is empty",
|
||||
},
|
||||
{
|
||||
name: "TC-separated load with same base and lib tarball",
|
||||
diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go
|
||||
index 3cecbf9..06a53fa 100644
|
||||
--- a/cmd/daemon/main.go
|
||||
+++ b/cmd/daemon/main.go
|
||||
@@ -189,18 +189,10 @@ func before(cmd *cobra.Command) error {
|
||||
|
||||
func loadConfig(path string) (config.TomlConfig, error) {
|
||||
var conf config.TomlConfig
|
||||
- fi, err := os.Stat(path)
|
||||
- if err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
return conf, err
|
||||
}
|
||||
|
||||
- if !fi.Mode().IsRegular() {
|
||||
- return conf, errors.New("config file must be a regular file")
|
||||
- }
|
||||
-
|
||||
- if err = util.CheckFileSize(path, constant.MaxFileSize); err != nil {
|
||||
- return conf, err
|
||||
- }
|
||||
configData, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
if err != nil {
|
||||
return conf, err
|
||||
@@ -211,17 +203,7 @@ func loadConfig(path string) (config.TomlConfig, error) {
|
||||
}
|
||||
|
||||
func checkRootSetInConfig(path string) (setRunRoot, setGraphRoot bool, err error) {
|
||||
- fi, err := os.Stat(path)
|
||||
- if err != nil {
|
||||
- return false, false, err
|
||||
- }
|
||||
-
|
||||
- if !fi.Mode().IsRegular() {
|
||||
- err = errors.New("config file must be a regular file")
|
||||
- return false, false, err
|
||||
- }
|
||||
-
|
||||
- if err = util.CheckFileSize(path, constant.MaxFileSize); err != nil {
|
||||
+ if err = util.CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
@@ -391,16 +373,7 @@ func checkAndValidateConfig(cmd *cobra.Command) error {
|
||||
if exist, err := util.IsExist(file); err != nil {
|
||||
return err
|
||||
} else if exist {
|
||||
- fi, err := os.Stat(file)
|
||||
- if err != nil {
|
||||
- return errors.Wrapf(err, "stat file %q failed", file)
|
||||
- }
|
||||
-
|
||||
- if !fi.Mode().IsRegular() {
|
||||
- return errors.Errorf("file %s should be a regular file", fi.Name())
|
||||
- }
|
||||
-
|
||||
- if err := util.CheckFileSize(file, constant.MaxFileSize); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(file, constant.MaxFileSize); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
diff --git a/constant.go b/constant.go
|
||||
index 5af4fe2..47b7c2b 100644
|
||||
--- a/constant.go
|
||||
+++ b/constant.go
|
||||
@@ -67,8 +67,14 @@ const (
|
||||
|
||||
// CliLogBufferLen is log channel buffer size
|
||||
CliLogBufferLen = 8
|
||||
- // MaxFileSize is the maximum file size allowed, set 1M
|
||||
+ // MaxFileSize is the max size of normal config file at most 1M
|
||||
MaxFileSize = 1024 * 1024
|
||||
+ // JSONMaxFileSize is the max size of json file at most 10M
|
||||
+ JSONMaxFileSize = 10 * 1024 * 1024
|
||||
+ // MaxImportFileSize is the max size of import image file at most 1G
|
||||
+ MaxImportFileSize = 1024 * 1024 * 1024
|
||||
+ // MaxLoadFileSize is the max size of load image file at most 50G
|
||||
+ MaxLoadFileSize = 50 * 1024 * 1024 * 1024
|
||||
// DefaultHTTPTimeout includes the total time of dial, TLS handshake, request, resp headers and body
|
||||
DefaultHTTPTimeout = 3600 * time.Second
|
||||
// DefaultFailedCode is the exit code for most scenes
|
||||
diff --git a/daemon/load.go b/daemon/load.go
|
||||
index 1ee025b..2d0c154 100644
|
||||
--- a/daemon/load.go
|
||||
+++ b/daemon/load.go
|
||||
@@ -62,7 +62,7 @@ func (b *Backend) getLoadOptions(req *pb.LoadRequest) (LoadOptions, error) {
|
||||
|
||||
// normal image loading
|
||||
if !req.GetSep().GetEnabled() {
|
||||
- if err = util.CheckLoadFile(opt.path); err != nil {
|
||||
+ if err = util.CheckFileInfoAndSize(opt.path, constant.MaxLoadFileSize); err != nil {
|
||||
return LoadOptions{}, err
|
||||
}
|
||||
return opt, nil
|
||||
diff --git a/image/context.go b/image/context.go
|
||||
index ea826c6..c2d4150 100644
|
||||
--- a/image/context.go
|
||||
+++ b/image/context.go
|
||||
@@ -15,12 +15,10 @@ package image
|
||||
|
||||
import (
|
||||
"io"
|
||||
- "os"
|
||||
"sync"
|
||||
|
||||
cp "github.com/containers/image/v5/copy"
|
||||
"github.com/containers/image/v5/types"
|
||||
- "github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
constant "isula.org/isula-build"
|
||||
@@ -40,31 +38,13 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
-func validateConfigFiles(configs []string) error {
|
||||
- var (
|
||||
- cfgInfo os.FileInfo
|
||||
- err error
|
||||
- )
|
||||
- for _, cfg := range configs {
|
||||
- if err = util.CheckFileSize(cfg, constant.MaxFileSize); err != nil {
|
||||
- return err
|
||||
- }
|
||||
- if cfgInfo, err = os.Stat(cfg); err != nil {
|
||||
- return err
|
||||
- }
|
||||
- if cfgInfo.Size() == 0 {
|
||||
- return errors.Errorf("config %q cannot be an empty file", cfg)
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
// SetSystemContext set the values of globalSystemContext
|
||||
func SetSystemContext(dataRoot string) {
|
||||
- err := validateConfigFiles([]string{constant.SignaturePolicyPath, constant.RegistryConfigPath})
|
||||
- if err != nil {
|
||||
- logrus.Fatal(err)
|
||||
+ configFiles := []string{constant.SignaturePolicyPath, constant.RegistryConfigPath}
|
||||
+ for _, cfg := range configFiles {
|
||||
+ if err := util.CheckFileInfoAndSize(cfg, constant.MaxFileSize); err != nil {
|
||||
+ logrus.Fatalf("check config file %q failed: %v", cfg, err)
|
||||
+ }
|
||||
}
|
||||
|
||||
once.Do(func() {
|
||||
diff --git a/image/context_test.go b/image/context_test.go
|
||||
index 131c3a2..08d34e9 100644
|
||||
--- a/image/context_test.go
|
||||
+++ b/image/context_test.go
|
||||
@@ -29,65 +29,6 @@ func doCmd(cmd string) {
|
||||
}
|
||||
}
|
||||
|
||||
-func TestValidateConfigFiles(t *testing.T) {
|
||||
- type args struct {
|
||||
- configs []string
|
||||
- }
|
||||
- tests := []struct {
|
||||
- name string
|
||||
- args args
|
||||
- wantErr bool
|
||||
- prepareCmd string
|
||||
- cleanCmd string
|
||||
- }{
|
||||
- {
|
||||
- name: "none file",
|
||||
- args: args{configs: []string{"/tmp/validate-config/policy.json"}},
|
||||
- prepareCmd: "mkdir -p /tmp/validate-config/ && touch /tmp/validate-config/policy.json",
|
||||
- cleanCmd: "rm -rf /tmp/validate-config",
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "size zero",
|
||||
- args: args{configs: []string{"/tmp/validate-config/policy.json"}},
|
||||
- prepareCmd: "mkdir -p /tmp/validate-config/ && touch /tmp/validate-config/policy.json",
|
||||
- cleanCmd: "rm -rf /tmp/validate-config",
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "big file",
|
||||
- args: args{configs: []string{"/tmp/validate-config/policy.json"}},
|
||||
- prepareCmd: "mkdir -p /tmp/validate-config/ && dd if=/dev/zero of=/tmp/validate-config/policy.json bs=16k count=1024",
|
||||
- cleanCmd: "rm -rf /tmp/validate-config",
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "normal",
|
||||
- args: args{configs: []string{"/tmp/validate-config/policy.json"}},
|
||||
- prepareCmd: "mkdir -p /tmp/validate-config/ && echo hello > /tmp/validate-config/policy.json",
|
||||
- cleanCmd: "rm -rf /tmp/validate-config",
|
||||
- wantErr: false,
|
||||
- },
|
||||
- {
|
||||
- name: "normal",
|
||||
- args: args{configs: []string{"/tmp/validate-config/policy.json"}},
|
||||
- prepareCmd: "mkdir -p /tmp/validate-config/ && echo hello > /tmp/validate-config/policy.json.bak &&" +
|
||||
- "ln -sf /tmp/validate-config/policy.json.bak /tmp/validate-config/policy.json",
|
||||
- cleanCmd: "rm -rf /tmp/validate-config",
|
||||
- wantErr: false,
|
||||
- },
|
||||
- }
|
||||
- for _, tt := range tests {
|
||||
- t.Run(tt.name, func(t *testing.T) {
|
||||
- doCmd(tt.prepareCmd)
|
||||
- if err := validateConfigFiles(tt.args.configs); (err != nil) != tt.wantErr {
|
||||
- t.Errorf("validateConfigFiles() error = %v, wantErr %v", err, tt.wantErr)
|
||||
- }
|
||||
- doCmd(tt.cleanCmd)
|
||||
- })
|
||||
- }
|
||||
-}
|
||||
-
|
||||
func TestSetSystemContext(t *testing.T) {
|
||||
prepareFunc := func(path string) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
diff --git a/runner/runner.go b/runner/runner.go
|
||||
index e813024..dd43901 100644
|
||||
--- a/runner/runner.go
|
||||
+++ b/runner/runner.go
|
||||
@@ -215,7 +215,7 @@ func (r *OCIRunner) runContainer() (unix.WaitStatus, error) { // nolint:gocyclo
|
||||
}
|
||||
|
||||
func readPid(pidFilePath string) (int, error) {
|
||||
- if err := util.CheckFileSize(pidFilePath, constant.MaxFileSize); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(pidFilePath, constant.MaxFileSize); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
pidValue, err := ioutil.ReadFile(filepath.Clean(pidFilePath))
|
||||
diff --git a/util/common.go b/util/common.go
|
||||
index ff85da9..42d81b8 100644
|
||||
--- a/util/common.go
|
||||
+++ b/util/common.go
|
||||
@@ -29,10 +29,7 @@ import (
|
||||
constant "isula.org/isula-build"
|
||||
)
|
||||
|
||||
-const (
|
||||
- maxServerNameLength = 255
|
||||
- maxLoadFileSize = 50 * 1024 * 1024 * 1024
|
||||
-)
|
||||
+const maxServerNameLength = 255
|
||||
|
||||
// CopyMapStringString copies all KVs in a map[string]string to a new map
|
||||
func CopyMapStringString(m map[string]string) map[string]string {
|
||||
@@ -94,44 +91,21 @@ func SetUmask() bool {
|
||||
return unix.Umask(wanted) == wanted
|
||||
}
|
||||
|
||||
-// CheckFileSize check whether the file size exceeds limit
|
||||
-func CheckFileSize(path string, sizeLimit int64) error {
|
||||
- filename := filepath.Base(path)
|
||||
+// CheckFileInfoAndSize check whether the file exists, is regular file, and if its size exceeds limit
|
||||
+func CheckFileInfoAndSize(path string, sizeLimit int64) error {
|
||||
f, err := os.Stat(filepath.Clean(path))
|
||||
- // file not exist, file size check ok
|
||||
- if os.IsNotExist(err) {
|
||||
- return nil
|
||||
- }
|
||||
if err != nil {
|
||||
- return errors.Errorf("stat file %v err: %v", filename, err)
|
||||
- }
|
||||
- if f.IsDir() {
|
||||
- return errors.Errorf("file %s is a directory", filename)
|
||||
+ return err
|
||||
}
|
||||
- if f.Size() > sizeLimit {
|
||||
- return errors.Errorf("file %v size is: %v, exceeds limit %v", filename, f.Size(), sizeLimit)
|
||||
+ if !f.Mode().IsRegular() {
|
||||
+ return errors.Errorf("file %s should be a regular file", f.Name())
|
||||
}
|
||||
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-// CheckLoadFile checks the file which will be loaded
|
||||
-func CheckLoadFile(path string) error {
|
||||
- fi, err := os.Stat(path)
|
||||
- if err != nil {
|
||||
- return errors.Wrapf(err, "stat %q failed", path)
|
||||
- }
|
||||
-
|
||||
- if !fi.Mode().IsRegular() {
|
||||
- return errors.Errorf("loading file %s should be a regular file", fi.Name())
|
||||
+ if f.Size() == 0 {
|
||||
+ return errors.Errorf("file %s is empty", f.Name())
|
||||
}
|
||||
-
|
||||
- if fi.Size() == 0 {
|
||||
- return errors.New("loading file is empty")
|
||||
- }
|
||||
-
|
||||
- if fi.Size() > maxLoadFileSize {
|
||||
- return errors.Errorf("file %s size is: %v, exceeds limit %v", fi.Name(), fi.Size(), maxLoadFileSize)
|
||||
+ if f.Size() > sizeLimit {
|
||||
+ return errors.Errorf("file %s size is: %d, exceeds limit %d", f.Name(), f.Size(), sizeLimit)
|
||||
}
|
||||
|
||||
return nil
|
||||
diff --git a/util/common_test.go b/util/common_test.go
|
||||
index 9831971..7d2444a 100644
|
||||
--- a/util/common_test.go
|
||||
+++ b/util/common_test.go
|
||||
@@ -14,17 +14,14 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
- "io/ioutil"
|
||||
- "os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/fs"
|
||||
- constant "isula.org/isula-build"
|
||||
)
|
||||
|
||||
-func TestCheckFileSize(t *testing.T) {
|
||||
+func TestCheckFileInfoAndSize(t *testing.T) {
|
||||
content := `
|
||||
ARG testArg
|
||||
ARG testArg2
|
||||
@@ -48,6 +45,12 @@ func TestCheckFileSize(t *testing.T) {
|
||||
ctxDir: fs.NewDir(t, t.Name(), fs.WithFile("Dockerfile", content)),
|
||||
sizeLimit: 200,
|
||||
},
|
||||
+ {
|
||||
+ name: "empty file",
|
||||
+ ctxDir: fs.NewDir(t, t.Name(), fs.WithFile("Dockerfile", "")),
|
||||
+ isErr: true,
|
||||
+ errStr: "is empty",
|
||||
+ },
|
||||
{
|
||||
name: "exceeds limit file",
|
||||
ctxDir: fs.NewDir(t, t.Name(), fs.WithFile("Dockerfile", content)),
|
||||
@@ -60,12 +63,7 @@ func TestCheckFileSize(t *testing.T) {
|
||||
ctxDir: fs.NewDir(t, t.Name(), fs.WithFile("Dockerfile", content)),
|
||||
isDir: true,
|
||||
isErr: true,
|
||||
- errStr: "is a directory",
|
||||
- },
|
||||
- {
|
||||
- name: "not exist file",
|
||||
- ctxDir: fs.NewDir(t, t.Name()),
|
||||
- sizeLimit: 5,
|
||||
+ errStr: "should be a regular file",
|
||||
},
|
||||
{
|
||||
name: "exceeds limit directory",
|
||||
@@ -83,7 +81,7 @@ func TestCheckFileSize(t *testing.T) {
|
||||
if !c.isDir {
|
||||
path = filepath.Join(path, "Dockerfile")
|
||||
}
|
||||
- err := CheckFileSize(path, c.sizeLimit)
|
||||
+ err := CheckFileInfoAndSize(path, c.sizeLimit)
|
||||
assert.Equal(t, err != nil, c.isErr)
|
||||
if c.isErr {
|
||||
assert.ErrorContains(t, err, c.errStr)
|
||||
@@ -250,63 +248,3 @@ func TestAnyFlagSet(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
-
|
||||
-func TestCheckLoadFile(t *testing.T) {
|
||||
- loadFile := fs.NewFile(t, t.Name())
|
||||
- defer loadFile.Remove()
|
||||
- err := ioutil.WriteFile(loadFile.Path(), []byte("hello"), constant.DefaultRootFileMode)
|
||||
- assert.NilError(t, err)
|
||||
-
|
||||
- emptyFile := fs.NewFile(t, t.Name())
|
||||
- defer emptyFile.Remove()
|
||||
-
|
||||
- root := fs.NewDir(t, t.Name())
|
||||
- defer root.Remove()
|
||||
-
|
||||
- bigFile := filepath.Join(root.Path(), "bigFile")
|
||||
- f, err := os.Create(bigFile)
|
||||
- assert.NilError(t, err)
|
||||
- defer os.Remove(f.Name())
|
||||
- err = f.Truncate(maxLoadFileSize + 1)
|
||||
- assert.NilError(t, err)
|
||||
-
|
||||
- type args struct {
|
||||
- path string
|
||||
- }
|
||||
- tests := []struct {
|
||||
- name string
|
||||
- args args
|
||||
- wantErr bool
|
||||
- }{
|
||||
- {
|
||||
- name: "TC-normal load file",
|
||||
- args: args{path: loadFile.Path()},
|
||||
- },
|
||||
- {
|
||||
- name: "TC-load file not exist",
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "TC-empty load file",
|
||||
- args: args{path: emptyFile.Path()},
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "TC-invalid load file",
|
||||
- args: args{path: "/dev/cdrom"},
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "TC-load file too big",
|
||||
- args: args{path: bigFile},
|
||||
- wantErr: true,
|
||||
- },
|
||||
- }
|
||||
- for _, tt := range tests {
|
||||
- t.Run(tt.name, func(t *testing.T) {
|
||||
- if err := CheckLoadFile(tt.args.path); (err != nil) != tt.wantErr {
|
||||
- t.Errorf("CheckLoadFile() error = %v, wantErr %v", err, tt.wantErr)
|
||||
- }
|
||||
- })
|
||||
- }
|
||||
-}
|
||||
diff --git a/util/file.go b/util/file.go
|
||||
index e035389..07123ce 100644
|
||||
--- a/util/file.go
|
||||
+++ b/util/file.go
|
||||
@@ -23,10 +23,8 @@ import (
|
||||
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/pkg/errors"
|
||||
-)
|
||||
|
||||
-const (
|
||||
- fileMaxSize = 10 * 1024 * 1024 // 10MB
|
||||
+ constant "isula.org/isula-build"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -34,33 +32,18 @@ var (
|
||||
accessTime = time.Date(2017, time.January, 0, 0, 0, 0, 0, time.UTC)
|
||||
)
|
||||
|
||||
-// ReadSmallFile read small file less than 10MB
|
||||
-func ReadSmallFile(path string) ([]byte, error) {
|
||||
- st, err := os.Lstat(path)
|
||||
+// LoadJSONFile load json files and store it into v
|
||||
+func LoadJSONFile(file string, v interface{}) error {
|
||||
+ err := CheckFileInfoAndSize(file, constant.JSONMaxFileSize)
|
||||
if err != nil {
|
||||
- return nil, err
|
||||
- }
|
||||
-
|
||||
- if !st.Mode().IsRegular() {
|
||||
- return nil, errors.Errorf("loading file %s should be a regular file", st.Name())
|
||||
- }
|
||||
-
|
||||
- if st.Size() == 0 {
|
||||
- return nil, errors.New("loading file is empty")
|
||||
- }
|
||||
-
|
||||
- if st.Size() > fileMaxSize {
|
||||
- return nil, errors.Errorf("file %q too big", path)
|
||||
+ return err
|
||||
}
|
||||
- return ioutil.ReadFile(path) // nolint: gosec
|
||||
-}
|
||||
|
||||
-// LoadJSONFile load json files and store it into v
|
||||
-func LoadJSONFile(file string, v interface{}) error {
|
||||
- f, err := ReadSmallFile(file)
|
||||
+ f, err := ioutil.ReadFile(file) // nolint: gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
+
|
||||
return json.Unmarshal(f, v)
|
||||
}
|
||||
|
||||
diff --git a/util/file_test.go b/util/file_test.go
|
||||
index 09aed41..b23b474 100644
|
||||
--- a/util/file_test.go
|
||||
+++ b/util/file_test.go
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
- "reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -28,73 +27,6 @@ import (
|
||||
constant "isula.org/isula-build"
|
||||
)
|
||||
|
||||
-func TestReadSmallFile(t *testing.T) {
|
||||
- smallFile := fs.NewFile(t, t.Name())
|
||||
- defer smallFile.Remove()
|
||||
- err := ioutil.WriteFile(smallFile.Path(), []byte("small file"), constant.DefaultRootFileMode)
|
||||
- assert.NilError(t, err)
|
||||
-
|
||||
- root := fs.NewDir(t, t.Name())
|
||||
- defer root.Remove()
|
||||
-
|
||||
- bigFile := filepath.Join(root.Path(), "bigFile")
|
||||
- f, err := os.Create(bigFile)
|
||||
- assert.NilError(t, err)
|
||||
- defer os.Remove(f.Name())
|
||||
- err = f.Truncate(fileMaxSize + 1)
|
||||
- assert.NilError(t, err)
|
||||
-
|
||||
- emptyFile := fs.NewFile(t, t.Name())
|
||||
- defer emptyFile.Remove()
|
||||
-
|
||||
- type args struct {
|
||||
- path string
|
||||
- }
|
||||
- tests := []struct {
|
||||
- name string
|
||||
- args args
|
||||
- want []byte
|
||||
- wantErr bool
|
||||
- }{
|
||||
- {
|
||||
- name: "TC-normal read",
|
||||
- args: args{path: smallFile.Path()},
|
||||
- want: []byte("small file"),
|
||||
- },
|
||||
- {
|
||||
- name: "TC-not exist path",
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "TC-file too big",
|
||||
- args: args{path: bigFile},
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "TC-empty file",
|
||||
- args: args{path: emptyFile.Path()},
|
||||
- wantErr: true,
|
||||
- },
|
||||
- {
|
||||
- name: "TC-invalid file",
|
||||
- args: args{path: "/dev/cdrom"},
|
||||
- wantErr: true,
|
||||
- },
|
||||
- }
|
||||
- for _, tt := range tests {
|
||||
- t.Run(tt.name, func(t *testing.T) {
|
||||
- got, err := ReadSmallFile(tt.args.path)
|
||||
- if (err != nil) != tt.wantErr {
|
||||
- t.Errorf("ReadSmallFile() error = %v, wantErr %v", err, tt.wantErr)
|
||||
- return
|
||||
- }
|
||||
- if !reflect.DeepEqual(got, tt.want) {
|
||||
- t.Errorf("ReadSmallFile() = %v, want %v", got, tt.want)
|
||||
- }
|
||||
- })
|
||||
- }
|
||||
-}
|
||||
-
|
||||
func TestLoadJSONFile(t *testing.T) {
|
||||
type rename struct {
|
||||
Name string `json:"name"`
|
||||
diff --git a/util/user.go b/util/user.go
|
||||
index ce398ff..5bf12ef 100644
|
||||
--- a/util/user.go
|
||||
+++ b/util/user.go
|
||||
@@ -76,7 +76,7 @@ func GetChownOptions(chown, mountpoint string) (idtools.IDPair, error) {
|
||||
// searchUserGroup searches user in etc/passwd and group in etc/group
|
||||
// function caller should make sure the path is clean
|
||||
func searchUserGroup(name, path string, userFlag bool) (int, error) {
|
||||
- if err := CheckFileSize(path, constant.MaxFileSize); err != nil {
|
||||
+ if err := CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
f, err := os.Open(path) // nolint:gosec
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,554 @@
|
||||
From e1e1ff42c720153b67375d84e3c56262e41d2fa9 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Wed, 26 Jan 2022 16:21:58 +0800
|
||||
Subject: [PATCH 15/20] bugfix: run and data root when cmd not set, main
|
||||
configuration.toml first
|
||||
|
||||
---
|
||||
cmd/daemon/main.go | 178 +++++++-----------
|
||||
cmd/daemon/main_test.go | 113 ++++++++---
|
||||
image/context.go | 9 -
|
||||
..._storage_root_priority_of_configuration.sh | 92 +++++++++
|
||||
4 files changed, 244 insertions(+), 148 deletions(-)
|
||||
create mode 100644 tests/src/test_storage_root_priority_of_configuration.sh
|
||||
|
||||
diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go
|
||||
index 06a53fa..6deb9cb 100644
|
||||
--- a/cmd/daemon/main.go
|
||||
+++ b/cmd/daemon/main.go
|
||||
@@ -155,22 +155,10 @@ func before(cmd *cobra.Command) error {
|
||||
logrus.SetOutput(os.Stdout)
|
||||
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
|
||||
|
||||
- runRoot, err := securejoin.SecureJoin(daemonOpts.RunRoot, "storage")
|
||||
- if err != nil {
|
||||
+ if err := validateConfigFileAndMerge(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
- dataRoot, err := securejoin.SecureJoin(daemonOpts.DataRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
- store.SetDefaultStoreOptions(store.DaemonStoreOptions{
|
||||
- RunRoot: runRoot,
|
||||
- DataRoot: dataRoot,
|
||||
- Driver: daemonOpts.StorageDriver,
|
||||
- DriverOption: util.CopyStrings(daemonOpts.StorageOpts),
|
||||
- })
|
||||
-
|
||||
- if err := checkAndValidateConfig(cmd); err != nil {
|
||||
+ if err := setStoreAccordingToDaemonOpts(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -187,6 +175,26 @@ func before(cmd *cobra.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
+func setStoreAccordingToDaemonOpts() error {
|
||||
+ runRoot, err := securejoin.SecureJoin(daemonOpts.RunRoot, "storage")
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ dataRoot, err := securejoin.SecureJoin(daemonOpts.DataRoot, "storage")
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ store.SetDefaultStoreOptions(store.DaemonStoreOptions{
|
||||
+ RunRoot: runRoot,
|
||||
+ DataRoot: dataRoot,
|
||||
+ Driver: daemonOpts.StorageDriver,
|
||||
+ DriverOption: util.CopyStrings(daemonOpts.StorageOpts),
|
||||
+ })
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
func loadConfig(path string) (config.TomlConfig, error) {
|
||||
var conf config.TomlConfig
|
||||
if err := util.CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
@@ -202,65 +210,25 @@ func loadConfig(path string) (config.TomlConfig, error) {
|
||||
return conf, err
|
||||
}
|
||||
|
||||
-func checkRootSetInConfig(path string) (setRunRoot, setGraphRoot bool, err error) {
|
||||
- if err = util.CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
- return false, false, err
|
||||
- }
|
||||
-
|
||||
- configData, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
- if err != nil {
|
||||
- return false, false, err
|
||||
- }
|
||||
- conf := struct {
|
||||
- Storage struct {
|
||||
- RunRoot string `toml:"runroot"`
|
||||
- DataRoot string `toml:"graphroot"`
|
||||
- } `toml:"storage"`
|
||||
- }{}
|
||||
- _, err = toml.Decode(string(configData), &conf)
|
||||
- return conf.Storage.RunRoot != "", conf.Storage.DataRoot != "", err
|
||||
-}
|
||||
-
|
||||
func mergeStorageConfig(cmd *cobra.Command) error {
|
||||
store.SetDefaultConfigFilePath(constant.StorageConfigPath)
|
||||
option, err := store.GetDefaultStoreOptions(true)
|
||||
- if err == nil {
|
||||
- if option.GraphDriverName != "" && !cmd.Flag("storage-driver").Changed {
|
||||
- daemonOpts.StorageDriver = option.GraphDriverName
|
||||
- }
|
||||
- if len(option.GraphDriverOptions) > 0 && !cmd.Flag("storage-opt").Changed {
|
||||
- daemonOpts.StorageOpts = option.GraphDriverOptions
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- var storeOpt store.DaemonStoreOptions
|
||||
- storeOpt.RunRoot = option.RunRoot
|
||||
- storeOpt.DataRoot = option.GraphRoot
|
||||
-
|
||||
- setRunRoot, setDataRoot, err := checkRootSetInConfig(constant.StorageConfigPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
- if !setRunRoot {
|
||||
- storeOpt.RunRoot, err = securejoin.SecureJoin(daemonOpts.RunRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
+ if !cmd.Flag("runroot").Changed && option.RunRoot != "" {
|
||||
+ daemonOpts.RunRoot = option.RunRoot
|
||||
}
|
||||
- if !setDataRoot {
|
||||
- storeOpt.DataRoot, err = securejoin.SecureJoin(daemonOpts.DataRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
+ if !cmd.Flag("dataroot").Changed && option.GraphRoot != "" {
|
||||
+ daemonOpts.DataRoot = option.GraphRoot
|
||||
}
|
||||
- if daemonOpts.StorageDriver != "" {
|
||||
- storeOpt.Driver = daemonOpts.StorageDriver
|
||||
+ if !cmd.Flag("storage-driver").Changed && option.GraphDriverName != "" {
|
||||
+ daemonOpts.StorageDriver = option.GraphDriverName
|
||||
}
|
||||
- if len(daemonOpts.StorageOpts) > 0 {
|
||||
- storeOpt.DriverOption = util.CopyStrings(daemonOpts.StorageOpts)
|
||||
+ if !cmd.Flag("storage-opt").Changed && len(option.GraphDriverOptions) > 0 {
|
||||
+ daemonOpts.StorageOpts = option.GraphDriverOptions
|
||||
}
|
||||
- store.SetDefaultStoreOptions(storeOpt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -288,20 +256,6 @@ func mergeConfig(conf config.TomlConfig, cmd *cobra.Command) error {
|
||||
daemonOpts.DataRoot = conf.DataRoot
|
||||
}
|
||||
|
||||
- runRoot, err := securejoin.SecureJoin(daemonOpts.RunRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- dataRoot, err := securejoin.SecureJoin(daemonOpts.DataRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
- store.SetDefaultStoreOptions(store.DaemonStoreOptions{
|
||||
- DataRoot: dataRoot,
|
||||
- RunRoot: runRoot,
|
||||
- })
|
||||
-
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -342,48 +296,56 @@ func setupWorkingDirectories() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
-func checkAndValidateConfig(cmd *cobra.Command) error {
|
||||
- // check if configuration.toml file exists, merge config if exists
|
||||
- if exist, err := util.IsExist(constant.ConfigurationPath); err != nil {
|
||||
- return err
|
||||
- } else if !exist {
|
||||
- logrus.Warnf("Main config file missing, the default configuration is used")
|
||||
- } else {
|
||||
- conf, err := loadConfig(constant.ConfigurationPath)
|
||||
- if err != nil {
|
||||
- logrus.Errorf("Load and parse main config file failed: %v", err)
|
||||
- os.Exit(constant.DefaultFailedCode)
|
||||
+func validateConfigFileAndMerge(cmd *cobra.Command) error {
|
||||
+ confFiles := []struct {
|
||||
+ path string
|
||||
+ needed bool
|
||||
+ mergeConfig func(cmd *cobra.Command) error
|
||||
+ }{
|
||||
+ {path: constant.StorageConfigPath, needed: false, mergeConfig: mergeStorageConfig},
|
||||
+ {path: constant.RegistryConfigPath, needed: false, mergeConfig: nil},
|
||||
+ // policy.json file must exists
|
||||
+ {path: constant.SignaturePolicyPath, needed: true, mergeConfig: nil},
|
||||
+ // main configuration comes last for the final merge operation
|
||||
+ {path: constant.ConfigurationPath, needed: false, mergeConfig: loadMainConfiguration},
|
||||
+ }
|
||||
+
|
||||
+ for _, file := range confFiles {
|
||||
+ if exist, err := util.IsExist(file.path); !exist {
|
||||
+ if !file.needed {
|
||||
+ logrus.Warnf("Config file %q missing, the default configuration is used", file.path)
|
||||
+ continue
|
||||
+ }
|
||||
+
|
||||
+ if err != nil {
|
||||
+ return errors.Wrapf(err, "check config file %q failed", file.path)
|
||||
+ }
|
||||
+ return errors.Errorf("config file %q is not exist", file.path)
|
||||
}
|
||||
|
||||
- if err = mergeConfig(conf, cmd); err != nil {
|
||||
+ if err := util.CheckFileInfoAndSize(file.path, constant.MaxFileSize); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ if file.mergeConfig == nil {
|
||||
+ continue
|
||||
+ }
|
||||
+ if err := file.mergeConfig(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
- // file policy.json must be exist
|
||||
- if exist, err := util.IsExist(constant.SignaturePolicyPath); err != nil {
|
||||
- return err
|
||||
- } else if !exist {
|
||||
- return errors.Errorf("policy config file %v is not exist", constant.SignaturePolicyPath)
|
||||
- }
|
||||
+ return nil
|
||||
+}
|
||||
|
||||
- // check all config files
|
||||
- confFiles := []string{constant.RegistryConfigPath, constant.SignaturePolicyPath, constant.StorageConfigPath}
|
||||
- for _, file := range confFiles {
|
||||
- if exist, err := util.IsExist(file); err != nil {
|
||||
- return err
|
||||
- } else if exist {
|
||||
- if err := util.CheckFileInfoAndSize(file, constant.MaxFileSize); err != nil {
|
||||
- return err
|
||||
- }
|
||||
- }
|
||||
+func loadMainConfiguration(cmd *cobra.Command) error {
|
||||
+ conf, err := loadConfig(constant.ConfigurationPath)
|
||||
+ if err != nil {
|
||||
+ logrus.Errorf("Load and parse main config file failed: %v", err)
|
||||
+ os.Exit(constant.DefaultFailedCode)
|
||||
}
|
||||
|
||||
- // if storage config file exists, merge storage config
|
||||
- if exist, err := util.IsExist(constant.StorageConfigPath); err != nil {
|
||||
+ if err = mergeConfig(conf, cmd); err != nil {
|
||||
return err
|
||||
- } else if exist {
|
||||
- return mergeStorageConfig(cmd)
|
||||
}
|
||||
|
||||
return nil
|
||||
diff --git a/cmd/daemon/main_test.go b/cmd/daemon/main_test.go
|
||||
index 3947f7a..b1b8859 100644
|
||||
--- a/cmd/daemon/main_test.go
|
||||
+++ b/cmd/daemon/main_test.go
|
||||
@@ -112,6 +112,10 @@ func TestSetupWorkingDirectories(t *testing.T) {
|
||||
func TestRunAndDataRootSet(t *testing.T) {
|
||||
dataRoot := fs.NewDir(t, t.Name())
|
||||
runRoot := fs.NewDir(t, t.Name())
|
||||
+ result := store.DaemonStoreOptions{
|
||||
+ DataRoot: dataRoot.Join("storage"),
|
||||
+ RunRoot: runRoot.Join("storage"),
|
||||
+ }
|
||||
|
||||
conf := config.TomlConfig{
|
||||
Debug: true,
|
||||
@@ -123,34 +127,41 @@ func TestRunAndDataRootSet(t *testing.T) {
|
||||
}
|
||||
cmd := newDaemonCommand()
|
||||
|
||||
- result := store.DaemonStoreOptions{
|
||||
- DataRoot: dataRoot.Join("storage"),
|
||||
- RunRoot: runRoot.Join("storage"),
|
||||
- }
|
||||
-
|
||||
- setStorage := func(content string) func() {
|
||||
- return func() {
|
||||
- if err := mergeConfig(conf, cmd); err != nil {
|
||||
- t.Fatalf("mrege config failed with error: %v", err)
|
||||
- }
|
||||
+ setStorage := func(content string) {
|
||||
+ // merge main config
|
||||
+ if err := mergeConfig(conf, cmd); err != nil {
|
||||
+ t.Fatalf("merge config failed with error: %v", err)
|
||||
+ }
|
||||
|
||||
- fileName := "storage.toml"
|
||||
- tmpDir := fs.NewDir(t, t.Name(), fs.WithFile(fileName, content))
|
||||
- defer tmpDir.Remove()
|
||||
+ // simulate storage.toml and merge
|
||||
+ fileName := "storage.toml"
|
||||
+ tmpDir := fs.NewDir(t, t.Name(), fs.WithFile(fileName, content))
|
||||
+ defer tmpDir.Remove()
|
||||
+ filePath := tmpDir.Join(fileName)
|
||||
|
||||
- filePath := tmpDir.Join(fileName)
|
||||
- store.SetDefaultConfigFilePath(filePath)
|
||||
- option, err := store.GetDefaultStoreOptions(true)
|
||||
- if err != nil {
|
||||
- t.Fatalf("get default store options failed with error: %v", err)
|
||||
- }
|
||||
+ store.SetDefaultConfigFilePath(filePath)
|
||||
+ option, err := store.GetDefaultStoreOptions(true)
|
||||
+ if err != nil {
|
||||
+ t.Fatalf("get default store options failed with error: %v", err)
|
||||
+ }
|
||||
|
||||
- var storeOpt store.DaemonStoreOptions
|
||||
- storeOpt.RunRoot = option.RunRoot
|
||||
- storeOpt.DataRoot = option.GraphRoot
|
||||
- store.SetDefaultStoreOptions(storeOpt)
|
||||
+ if !cmd.Flag("runroot").Changed && option.RunRoot != "" {
|
||||
+ daemonOpts.RunRoot = option.RunRoot
|
||||
+ }
|
||||
+ if !cmd.Flag("dataroot").Changed && option.GraphRoot != "" {
|
||||
+ daemonOpts.DataRoot = option.GraphRoot
|
||||
+ }
|
||||
+ if !cmd.Flag("storage-driver").Changed && option.GraphDriverName != "" {
|
||||
+ daemonOpts.StorageDriver = option.GraphDriverName
|
||||
+ }
|
||||
+ if !cmd.Flag("storage-opt").Changed && len(option.GraphDriverOptions) > 0 {
|
||||
+ daemonOpts.StorageOpts = option.GraphDriverOptions
|
||||
}
|
||||
|
||||
+ // final set
|
||||
+ if err := setStoreAccordingToDaemonOpts(); err != nil {
|
||||
+ t.Fatalf("set store options failed with error: %v", err)
|
||||
+ }
|
||||
}
|
||||
|
||||
testcases := []struct {
|
||||
@@ -160,28 +171,28 @@ func TestRunAndDataRootSet(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
// first run so can not be affected by other testcase
|
||||
- name: "TC3 - all not set",
|
||||
- setF: setStorage("[storage]\ndriver = \"overlay\""),
|
||||
+ name: "TC1 - all not set",
|
||||
+ setF: func() { setStorage("[storage]\ndriver = \"overlay\"") },
|
||||
expectation: store.DaemonStoreOptions{
|
||||
DataRoot: "/var/lib/isula-build/storage",
|
||||
RunRoot: "/var/run/isula-build/storage",
|
||||
},
|
||||
},
|
||||
{
|
||||
- name: "TC1 - cmd set, configuration and storage not set",
|
||||
+ name: "TC2 - cmd set, configuration and storage not set",
|
||||
setF: func() {
|
||||
cmd.PersistentFlags().Set("runroot", runRoot.Path())
|
||||
cmd.PersistentFlags().Set("dataroot", dataRoot.Path())
|
||||
- checkAndValidateConfig(cmd)
|
||||
+ setStorage("[storage]\ndriver = \"overlay\"")
|
||||
},
|
||||
expectation: result,
|
||||
},
|
||||
{
|
||||
- name: "TC2 - cmd and storage not set, configuration set",
|
||||
+ name: "TC3 - cmd and storage not set, configuration set",
|
||||
setF: func() {
|
||||
conf.DataRoot = dataRoot.Path()
|
||||
conf.RunRoot = runRoot.Path()
|
||||
- checkAndValidateConfig(cmd)
|
||||
+ setStorage("[storage]\ndriver = \"overlay\"")
|
||||
},
|
||||
expectation: result,
|
||||
},
|
||||
@@ -190,8 +201,22 @@ func TestRunAndDataRootSet(t *testing.T) {
|
||||
setF: func() {
|
||||
config := fmt.Sprintf("[storage]\ndriver = \"%s\"\nrunroot = \"%s\"\ngraphroot = \"%s\"\n",
|
||||
"overlay", runRoot.Join("storage"), dataRoot.Join("storage"))
|
||||
- sT := setStorage(config)
|
||||
- sT()
|
||||
+ setStorage(config)
|
||||
+ },
|
||||
+ expectation: result,
|
||||
+ },
|
||||
+ {
|
||||
+ name: "TC5 - cmd not set, configuration and storage set, configuration first",
|
||||
+ setF: func() {
|
||||
+ conf.DataRoot = dataRoot.Path()
|
||||
+ conf.RunRoot = runRoot.Path()
|
||||
+
|
||||
+ dataRootStorage := fs.NewDir(t, t.Name())
|
||||
+ runRootStorage := fs.NewDir(t, t.Name())
|
||||
+ config := fmt.Sprintf("[storage]\ndriver = \"%s\"\nrunroot = \"%s\"\ngraphroot = \"%s\"\n",
|
||||
+ "overlay", runRootStorage.Join("storage"), dataRootStorage.Join("storage"))
|
||||
+
|
||||
+ setStorage(config)
|
||||
},
|
||||
expectation: result,
|
||||
},
|
||||
@@ -210,3 +235,29 @@ func TestRunAndDataRootSet(t *testing.T) {
|
||||
|
||||
}
|
||||
}
|
||||
+
|
||||
+func TestValidateConfigFileAndMerge(t *testing.T) {
|
||||
+ // cmd line args keep default.
|
||||
+ cmd := newDaemonCommand()
|
||||
+ err := validateConfigFileAndMerge(cmd)
|
||||
+ assert.NilError(t, err)
|
||||
+
|
||||
+ // cmd line runroot and dataroot args are set.
|
||||
+ dataRoot := fs.NewDir(t, t.Name())
|
||||
+ runRoot := fs.NewDir(t, t.Name())
|
||||
+ cmd.PersistentFlags().Set("runroot", runRoot.Path())
|
||||
+ cmd.PersistentFlags().Set("dataroot", dataRoot.Path())
|
||||
+ err = validateConfigFileAndMerge(cmd)
|
||||
+ assert.NilError(t, err)
|
||||
+
|
||||
+ if err := setStoreAccordingToDaemonOpts(); err != nil {
|
||||
+ t.Fatalf("set store options failed with error: %v", err)
|
||||
+ }
|
||||
+ storeOptions, err := store.GetDefaultStoreOptions(false)
|
||||
+ if err != nil {
|
||||
+ t.Fatalf("get default store options failed with error: %v", err)
|
||||
+ }
|
||||
+
|
||||
+ assert.Equal(t, storeOptions.GraphRoot, dataRoot.Join("storage"))
|
||||
+ assert.Equal(t, storeOptions.RunRoot, runRoot.Join("storage"))
|
||||
+}
|
||||
diff --git a/image/context.go b/image/context.go
|
||||
index c2d4150..6fd7725 100644
|
||||
--- a/image/context.go
|
||||
+++ b/image/context.go
|
||||
@@ -19,10 +19,8 @@ import (
|
||||
|
||||
cp "github.com/containers/image/v5/copy"
|
||||
"github.com/containers/image/v5/types"
|
||||
- "github.com/sirupsen/logrus"
|
||||
|
||||
constant "isula.org/isula-build"
|
||||
- "isula.org/isula-build/util"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -40,13 +38,6 @@ func init() {
|
||||
|
||||
// SetSystemContext set the values of globalSystemContext
|
||||
func SetSystemContext(dataRoot string) {
|
||||
- configFiles := []string{constant.SignaturePolicyPath, constant.RegistryConfigPath}
|
||||
- for _, cfg := range configFiles {
|
||||
- if err := util.CheckFileInfoAndSize(cfg, constant.MaxFileSize); err != nil {
|
||||
- logrus.Fatalf("check config file %q failed: %v", cfg, err)
|
||||
- }
|
||||
- }
|
||||
-
|
||||
once.Do(func() {
|
||||
globalSystemContext.SignaturePolicyPath = constant.SignaturePolicyPath
|
||||
globalSystemContext.SystemRegistriesConfPath = constant.RegistryConfigPath
|
||||
diff --git a/tests/src/test_storage_root_priority_of_configuration.sh b/tests/src/test_storage_root_priority_of_configuration.sh
|
||||
new file mode 100644
|
||||
index 0000000..e585d0c
|
||||
--- /dev/null
|
||||
+++ b/tests/src/test_storage_root_priority_of_configuration.sh
|
||||
@@ -0,0 +1,92 @@
|
||||
+#!/bin/bash
|
||||
+
|
||||
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
+# isula-build licensed under the Mulan PSL v2.
|
||||
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+# You may obtain a copy of Mulan PSL v2 at:
|
||||
+# http://license.coscl.org.cn/MulanPSL2
|
||||
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+# PURPOSE.
|
||||
+# See the Mulan PSL v2 for more details.
|
||||
+# Author: Weizheng Xing
|
||||
+# Create: 2022-01-25
|
||||
+# Description: test priority of data and run root with different configuration locations( binary > configuration.toml > storage.toml)
|
||||
+
|
||||
+top_dir=$(git rev-parse --show-toplevel)
|
||||
+# shellcheck disable=SC1091
|
||||
+source "$top_dir"/tests/lib/common.sh
|
||||
+
|
||||
+config_file="/etc/isula-build/configuration.toml"
|
||||
+storage_file="/etc/isula-build/storage.toml"
|
||||
+main_run_root="/tmp/run/main-isula-build"
|
||||
+main_data_root="/tmp/lib/main-isula-build"
|
||||
+storage_run_root="/tmp/run/storage-isula-build"
|
||||
+storage_data_root="/tmp/lib/storage-isula-build"
|
||||
+
|
||||
+# change to new data and run root
|
||||
+function pre_test() {
|
||||
+ cp $config_file "$config_file".bak
|
||||
+ cp $config_file "$config_file".bak
|
||||
+
|
||||
+ cp $storage_file "$storage_file".bak
|
||||
+ cp $storage_file "$storage_file".bak
|
||||
+}
|
||||
+
|
||||
+function clean() {
|
||||
+ rm -f "$config_file"
|
||||
+ rm -f "$storage_file"
|
||||
+
|
||||
+ mv $config_file.bak "$config_file"
|
||||
+ mv $storage_file.bak "$storage_file"
|
||||
+}
|
||||
+
|
||||
+function main_set_storage_not_set() {
|
||||
+ sed -i "/run_root/d;/data_root/d" $config_file
|
||||
+ sed -i "/runroot/d;/graphroot/d" $storage_file
|
||||
+ echo "run_root=\"$main_run_root\"" >>$config_file
|
||||
+ echo "data_root=\"$main_data_root\"" >>$config_file
|
||||
+
|
||||
+ check_root "$main_run_root" "$main_data_root"
|
||||
+}
|
||||
+
|
||||
+function main_not_set_storage_set() {
|
||||
+ sed -i "/run_root/d;/data_root/d" $config_file
|
||||
+ sed -i "/runroot/d;/graphroot/d" $storage_file
|
||||
+ eval "sed -i '/\[storage\]/a\runroot=\"$storage_run_root\"' $storage_file"
|
||||
+ eval "sed -i '/\[storage\]/a\graphroot=\"$storage_data_root\"' $storage_file"
|
||||
+
|
||||
+ check_root "$main_run_root" "$main_data_root"
|
||||
+}
|
||||
+
|
||||
+function main_set_storage_set() {
|
||||
+ sed -i "/run_root/d;/data_root/d" $config_file
|
||||
+ sed -i "/runroot/d;/graphroot/d" $storage_file
|
||||
+ echo "run_root = \"$main_run_root}\"" >>$config_file
|
||||
+ echo "data_root = \"$main_data_root\"" >>$config_file
|
||||
+ eval "sed -i '/\[storage\]/a\runroot=\"$storage_run_root\"' $storage_file"
|
||||
+ eval "sed -i '/\[storage\]/a\graphroot=\"$storage_data_root\"' $storage_file"
|
||||
+
|
||||
+ check_root "$main_run_root" "$main_data_root"
|
||||
+}
|
||||
+
|
||||
+# run command and check its result
|
||||
+# $1 (run root)
|
||||
+# $1 (data root)
|
||||
+function check_root() {
|
||||
+ local -r run_root="$1"
|
||||
+ local -r data_root="$2"
|
||||
+
|
||||
+ start_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
+ systemctl restart isula-build
|
||||
+
|
||||
+ run_check_result "journalctl -u isula-build --since \"$start_time\" --no-pager | grep $run_root" 0
|
||||
+ run_check_result "journalctl -u isula-build --since \"$start_time\" --no-pager | grep $data_root" 0
|
||||
+}
|
||||
+
|
||||
+pre_test
|
||||
+main_set_storage_not_set
|
||||
+main_not_set_storage_set
|
||||
+main_set_storage_set
|
||||
+clean
|
||||
+exit "$exit_flag"
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,526 @@
|
||||
From ef952b0443bdad7b149b6011fdf149bcfab0065a Mon Sep 17 00:00:00 2001
|
||||
From: meilier <xingweizheng@huawei.com>
|
||||
Date: Sat, 29 Jan 2022 14:33:43 +0800
|
||||
Subject: [PATCH 16/20] refactor: move befor related func of daemon main to a
|
||||
single file
|
||||
|
||||
---
|
||||
cmd/daemon/before.go | 250 ++++++++++++++++++++
|
||||
cmd/daemon/{main_test.go => before_test.go} | 0
|
||||
cmd/daemon/main.go | 225 ------------------
|
||||
3 files changed, 250 insertions(+), 225 deletions(-)
|
||||
create mode 100644 cmd/daemon/before.go
|
||||
rename cmd/daemon/{main_test.go => before_test.go} (100%)
|
||||
|
||||
diff --git a/cmd/daemon/before.go b/cmd/daemon/before.go
|
||||
new file mode 100644
|
||||
index 0000000..ac13303
|
||||
--- /dev/null
|
||||
+++ b/cmd/daemon/before.go
|
||||
@@ -0,0 +1,250 @@
|
||||
+// Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
+// isula-build licensed under the Mulan PSL v2.
|
||||
+// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+// You may obtain a copy of Mulan PSL v2 at:
|
||||
+// http://license.coscl.org.cn/MulanPSL2
|
||||
+// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+// PURPOSE.
|
||||
+// See the Mulan PSL v2 for more details.
|
||||
+// Author: Xiang Li
|
||||
+// Create: 2022-01-30
|
||||
+// Description: This file is used for isula-build daemon
|
||||
+
|
||||
+package main
|
||||
+
|
||||
+import (
|
||||
+ "io/ioutil"
|
||||
+ "os"
|
||||
+ "path/filepath"
|
||||
+
|
||||
+ "github.com/BurntSushi/toml"
|
||||
+ securejoin "github.com/cyphar/filepath-securejoin"
|
||||
+ "github.com/pkg/errors"
|
||||
+ "github.com/sirupsen/logrus"
|
||||
+ "github.com/spf13/cobra"
|
||||
+
|
||||
+ constant "isula.org/isula-build"
|
||||
+ "isula.org/isula-build/cmd/daemon/config"
|
||||
+ "isula.org/isula-build/image"
|
||||
+ "isula.org/isula-build/store"
|
||||
+ "isula.org/isula-build/util"
|
||||
+)
|
||||
+
|
||||
+// before parses input params for runDaemon()
|
||||
+func before(cmd *cobra.Command) error {
|
||||
+ if !util.SetUmask() {
|
||||
+ return errors.New("setting umask failed")
|
||||
+ }
|
||||
+
|
||||
+ logrus.SetOutput(os.Stdout)
|
||||
+ logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
|
||||
+
|
||||
+ if err := validateConfigFileAndMerge(cmd); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ if err := setStoreAccordingToDaemonOpts(); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ if err := initLogging(); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ if err := setupWorkingDirectories(); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ image.SetSystemContext(daemonOpts.DataRoot)
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func validateConfigFileAndMerge(cmd *cobra.Command) error {
|
||||
+ confFiles := []struct {
|
||||
+ path string
|
||||
+ needed bool
|
||||
+ mergeConfig func(cmd *cobra.Command) error
|
||||
+ }{
|
||||
+ {path: constant.StorageConfigPath, needed: false, mergeConfig: mergeStorageConfig},
|
||||
+ {path: constant.RegistryConfigPath, needed: false, mergeConfig: nil},
|
||||
+ // policy.json file must exists
|
||||
+ {path: constant.SignaturePolicyPath, needed: true, mergeConfig: nil},
|
||||
+ // main configuration comes last for the final merge operation
|
||||
+ {path: constant.ConfigurationPath, needed: false, mergeConfig: loadMainConfiguration},
|
||||
+ }
|
||||
+
|
||||
+ for _, file := range confFiles {
|
||||
+ if exist, err := util.IsExist(file.path); !exist {
|
||||
+ if !file.needed {
|
||||
+ logrus.Warnf("Config file %q missing, the default configuration is used", file.path)
|
||||
+ continue
|
||||
+ }
|
||||
+
|
||||
+ if err != nil {
|
||||
+ return errors.Wrapf(err, "check config file %q failed", file.path)
|
||||
+ }
|
||||
+ return errors.Errorf("config file %q is not exist", file.path)
|
||||
+ }
|
||||
+
|
||||
+ if err := util.CheckFileInfoAndSize(file.path, constant.MaxFileSize); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ if file.mergeConfig == nil {
|
||||
+ continue
|
||||
+ }
|
||||
+ if err := file.mergeConfig(cmd); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func mergeStorageConfig(cmd *cobra.Command) error {
|
||||
+ store.SetDefaultConfigFilePath(constant.StorageConfigPath)
|
||||
+ option, err := store.GetDefaultStoreOptions(true)
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ if !cmd.Flag("runroot").Changed && option.RunRoot != "" {
|
||||
+ daemonOpts.RunRoot = option.RunRoot
|
||||
+ }
|
||||
+ if !cmd.Flag("dataroot").Changed && option.GraphRoot != "" {
|
||||
+ daemonOpts.DataRoot = option.GraphRoot
|
||||
+ }
|
||||
+ if !cmd.Flag("storage-driver").Changed && option.GraphDriverName != "" {
|
||||
+ daemonOpts.StorageDriver = option.GraphDriverName
|
||||
+ }
|
||||
+ if !cmd.Flag("storage-opt").Changed && len(option.GraphDriverOptions) > 0 {
|
||||
+ daemonOpts.StorageOpts = option.GraphDriverOptions
|
||||
+ }
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func loadMainConfiguration(cmd *cobra.Command) error {
|
||||
+ conf, err := loadConfig(constant.ConfigurationPath)
|
||||
+ if err != nil {
|
||||
+ logrus.Errorf("Load and parse main config file failed: %v", err)
|
||||
+ os.Exit(constant.DefaultFailedCode)
|
||||
+ }
|
||||
+
|
||||
+ if err = mergeConfig(conf, cmd); err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func loadConfig(path string) (config.TomlConfig, error) {
|
||||
+ var conf config.TomlConfig
|
||||
+ if err := util.CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
+ return conf, err
|
||||
+ }
|
||||
+
|
||||
+ configData, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
+ if err != nil {
|
||||
+ return conf, err
|
||||
+ }
|
||||
+ _, err = toml.Decode(string(configData), &conf)
|
||||
+
|
||||
+ return conf, err
|
||||
+}
|
||||
+
|
||||
+func mergeConfig(conf config.TomlConfig, cmd *cobra.Command) error {
|
||||
+ if conf.Debug && !cmd.Flag("debug").Changed {
|
||||
+ daemonOpts.Debug = true
|
||||
+ }
|
||||
+ if conf.Experimental && !cmd.Flag("experimental").Changed {
|
||||
+ daemonOpts.Experimental = true
|
||||
+ }
|
||||
+ if conf.LogLevel != "" && !cmd.Flag("log-level").Changed {
|
||||
+ daemonOpts.LogLevel = conf.LogLevel
|
||||
+ }
|
||||
+ if conf.Group != "" && !cmd.Flag("group").Changed {
|
||||
+ daemonOpts.Group = conf.Group
|
||||
+ }
|
||||
+ if conf.Runtime != "" {
|
||||
+ daemonOpts.RuntimePath = conf.Runtime
|
||||
+ }
|
||||
+ if conf.RunRoot != "" && !cmd.Flag("runroot").Changed {
|
||||
+ daemonOpts.RunRoot = conf.RunRoot
|
||||
+ }
|
||||
+ if conf.DataRoot != "" && !cmd.Flag("dataroot").Changed {
|
||||
+ daemonOpts.DataRoot = conf.DataRoot
|
||||
+ }
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func setStoreAccordingToDaemonOpts() error {
|
||||
+ runRoot, err := securejoin.SecureJoin(daemonOpts.RunRoot, "storage")
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ dataRoot, err := securejoin.SecureJoin(daemonOpts.DataRoot, "storage")
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ store.SetDefaultStoreOptions(store.DaemonStoreOptions{
|
||||
+ RunRoot: runRoot,
|
||||
+ DataRoot: dataRoot,
|
||||
+ Driver: daemonOpts.StorageDriver,
|
||||
+ DriverOption: util.CopyStrings(daemonOpts.StorageOpts),
|
||||
+ })
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func initLogging() error {
|
||||
+ logrusLvl, err := logrus.ParseLevel(daemonOpts.LogLevel)
|
||||
+ if err != nil {
|
||||
+ return errors.Wrapf(err, "unable to parse log level")
|
||||
+ }
|
||||
+ logrus.SetLevel(logrusLvl)
|
||||
+ if daemonOpts.Debug {
|
||||
+ logrus.SetLevel(logrus.DebugLevel)
|
||||
+ }
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func setupWorkingDirectories() error {
|
||||
+ if daemonOpts.RunRoot == daemonOpts.DataRoot {
|
||||
+ return errors.Errorf("runroot(%q) and dataroot(%q) must be different paths", daemonOpts.RunRoot, daemonOpts.DataRoot)
|
||||
+ }
|
||||
+
|
||||
+ buildTmpDir, err := securejoin.SecureJoin(daemonOpts.DataRoot, constant.DataRootTmpDirPrefix)
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ dirs := []string{daemonOpts.DataRoot, daemonOpts.RunRoot, buildTmpDir}
|
||||
+ for _, dir := range dirs {
|
||||
+ if !filepath.IsAbs(dir) {
|
||||
+ return errors.Errorf("%q not an absolute dir, the \"dataroot\" and \"runroot\" must be an absolute path", dir)
|
||||
+ }
|
||||
+
|
||||
+ if exist, err := util.IsExist(dir); err != nil {
|
||||
+ return err
|
||||
+ } else if !exist {
|
||||
+ if err := os.MkdirAll(dir, constant.DefaultRootDirMode); err != nil {
|
||||
+ return errors.Wrapf(err, "create directory for %q failed", dir)
|
||||
+ }
|
||||
+ continue
|
||||
+ }
|
||||
+ if !util.IsDirectory(dir) {
|
||||
+ return errors.Errorf("%q is not a directory", dir)
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // change config root owner as group current defined
|
||||
+ if err := util.ChangeGroup(constant.ConfigRoot, daemonOpts.Group); err != nil {
|
||||
+ logrus.Errorf("Chown for %s failed: %v", constant.ConfigRoot, err)
|
||||
+ return err
|
||||
+ }
|
||||
+
|
||||
+ return nil
|
||||
+}
|
||||
diff --git a/cmd/daemon/main_test.go b/cmd/daemon/before_test.go
|
||||
similarity index 100%
|
||||
rename from cmd/daemon/main_test.go
|
||||
rename to cmd/daemon/before_test.go
|
||||
diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go
|
||||
index 6deb9cb..5b6327d 100644
|
||||
--- a/cmd/daemon/main.go
|
||||
+++ b/cmd/daemon/main.go
|
||||
@@ -15,22 +15,15 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
- "io/ioutil"
|
||||
"os"
|
||||
- "path/filepath"
|
||||
|
||||
- "github.com/BurntSushi/toml"
|
||||
"github.com/containers/storage/pkg/reexec"
|
||||
- securejoin "github.com/cyphar/filepath-securejoin"
|
||||
- "github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
constant "isula.org/isula-build"
|
||||
- "isula.org/isula-build/cmd/daemon/config"
|
||||
"isula.org/isula-build/daemon"
|
||||
_ "isula.org/isula-build/exporter/register"
|
||||
- "isula.org/isula-build/image"
|
||||
"isula.org/isula-build/pkg/version"
|
||||
"isula.org/isula-build/store"
|
||||
"isula.org/isula-build/util"
|
||||
@@ -132,221 +125,3 @@ func main() {
|
||||
os.Exit(constant.DefaultFailedCode)
|
||||
}
|
||||
}
|
||||
-
|
||||
-func initLogging() error {
|
||||
- logrusLvl, err := logrus.ParseLevel(daemonOpts.LogLevel)
|
||||
- if err != nil {
|
||||
- return errors.Wrapf(err, "unable to parse log level")
|
||||
- }
|
||||
- logrus.SetLevel(logrusLvl)
|
||||
- if daemonOpts.Debug {
|
||||
- logrus.SetLevel(logrus.DebugLevel)
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-// before parses input params for runDaemon()
|
||||
-func before(cmd *cobra.Command) error {
|
||||
- if !util.SetUmask() {
|
||||
- return errors.New("setting umask failed")
|
||||
- }
|
||||
-
|
||||
- logrus.SetOutput(os.Stdout)
|
||||
- logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
|
||||
-
|
||||
- if err := validateConfigFileAndMerge(cmd); err != nil {
|
||||
- return err
|
||||
- }
|
||||
- if err := setStoreAccordingToDaemonOpts(); err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- if err := initLogging(); err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- if err := setupWorkingDirectories(); err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- image.SetSystemContext(daemonOpts.DataRoot)
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-func setStoreAccordingToDaemonOpts() error {
|
||||
- runRoot, err := securejoin.SecureJoin(daemonOpts.RunRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
- dataRoot, err := securejoin.SecureJoin(daemonOpts.DataRoot, "storage")
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- store.SetDefaultStoreOptions(store.DaemonStoreOptions{
|
||||
- RunRoot: runRoot,
|
||||
- DataRoot: dataRoot,
|
||||
- Driver: daemonOpts.StorageDriver,
|
||||
- DriverOption: util.CopyStrings(daemonOpts.StorageOpts),
|
||||
- })
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-func loadConfig(path string) (config.TomlConfig, error) {
|
||||
- var conf config.TomlConfig
|
||||
- if err := util.CheckFileInfoAndSize(path, constant.MaxFileSize); err != nil {
|
||||
- return conf, err
|
||||
- }
|
||||
-
|
||||
- configData, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
- if err != nil {
|
||||
- return conf, err
|
||||
- }
|
||||
- _, err = toml.Decode(string(configData), &conf)
|
||||
-
|
||||
- return conf, err
|
||||
-}
|
||||
-
|
||||
-func mergeStorageConfig(cmd *cobra.Command) error {
|
||||
- store.SetDefaultConfigFilePath(constant.StorageConfigPath)
|
||||
- option, err := store.GetDefaultStoreOptions(true)
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- if !cmd.Flag("runroot").Changed && option.RunRoot != "" {
|
||||
- daemonOpts.RunRoot = option.RunRoot
|
||||
- }
|
||||
- if !cmd.Flag("dataroot").Changed && option.GraphRoot != "" {
|
||||
- daemonOpts.DataRoot = option.GraphRoot
|
||||
- }
|
||||
- if !cmd.Flag("storage-driver").Changed && option.GraphDriverName != "" {
|
||||
- daemonOpts.StorageDriver = option.GraphDriverName
|
||||
- }
|
||||
- if !cmd.Flag("storage-opt").Changed && len(option.GraphDriverOptions) > 0 {
|
||||
- daemonOpts.StorageOpts = option.GraphDriverOptions
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-func mergeConfig(conf config.TomlConfig, cmd *cobra.Command) error {
|
||||
- if conf.Debug && !cmd.Flag("debug").Changed {
|
||||
- daemonOpts.Debug = true
|
||||
- }
|
||||
- if conf.Experimental && !cmd.Flag("experimental").Changed {
|
||||
- daemonOpts.Experimental = true
|
||||
- }
|
||||
- if conf.LogLevel != "" && !cmd.Flag("log-level").Changed {
|
||||
- daemonOpts.LogLevel = conf.LogLevel
|
||||
- }
|
||||
- if conf.Group != "" && !cmd.Flag("group").Changed {
|
||||
- daemonOpts.Group = conf.Group
|
||||
- }
|
||||
- if conf.Runtime != "" {
|
||||
- daemonOpts.RuntimePath = conf.Runtime
|
||||
- }
|
||||
- if conf.RunRoot != "" && !cmd.Flag("runroot").Changed {
|
||||
- daemonOpts.RunRoot = conf.RunRoot
|
||||
- }
|
||||
- if conf.DataRoot != "" && !cmd.Flag("dataroot").Changed {
|
||||
- daemonOpts.DataRoot = conf.DataRoot
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-func setupWorkingDirectories() error {
|
||||
- if daemonOpts.RunRoot == daemonOpts.DataRoot {
|
||||
- return errors.Errorf("runroot(%q) and dataroot(%q) must be different paths", daemonOpts.RunRoot, daemonOpts.DataRoot)
|
||||
- }
|
||||
-
|
||||
- buildTmpDir, err := securejoin.SecureJoin(daemonOpts.DataRoot, constant.DataRootTmpDirPrefix)
|
||||
- if err != nil {
|
||||
- return err
|
||||
- }
|
||||
- dirs := []string{daemonOpts.DataRoot, daemonOpts.RunRoot, buildTmpDir}
|
||||
- for _, dir := range dirs {
|
||||
- if !filepath.IsAbs(dir) {
|
||||
- return errors.Errorf("%q not an absolute dir, the \"dataroot\" and \"runroot\" must be an absolute path", dir)
|
||||
- }
|
||||
-
|
||||
- if exist, err := util.IsExist(dir); err != nil {
|
||||
- return err
|
||||
- } else if !exist {
|
||||
- if err := os.MkdirAll(dir, constant.DefaultRootDirMode); err != nil {
|
||||
- return errors.Wrapf(err, "create directory for %q failed", dir)
|
||||
- }
|
||||
- continue
|
||||
- }
|
||||
- if !util.IsDirectory(dir) {
|
||||
- return errors.Errorf("%q is not a directory", dir)
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- // change config root owner as group current defined
|
||||
- if err := util.ChangeGroup(constant.ConfigRoot, daemonOpts.Group); err != nil {
|
||||
- logrus.Errorf("Chown for %s failed: %v", constant.ConfigRoot, err)
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-func validateConfigFileAndMerge(cmd *cobra.Command) error {
|
||||
- confFiles := []struct {
|
||||
- path string
|
||||
- needed bool
|
||||
- mergeConfig func(cmd *cobra.Command) error
|
||||
- }{
|
||||
- {path: constant.StorageConfigPath, needed: false, mergeConfig: mergeStorageConfig},
|
||||
- {path: constant.RegistryConfigPath, needed: false, mergeConfig: nil},
|
||||
- // policy.json file must exists
|
||||
- {path: constant.SignaturePolicyPath, needed: true, mergeConfig: nil},
|
||||
- // main configuration comes last for the final merge operation
|
||||
- {path: constant.ConfigurationPath, needed: false, mergeConfig: loadMainConfiguration},
|
||||
- }
|
||||
-
|
||||
- for _, file := range confFiles {
|
||||
- if exist, err := util.IsExist(file.path); !exist {
|
||||
- if !file.needed {
|
||||
- logrus.Warnf("Config file %q missing, the default configuration is used", file.path)
|
||||
- continue
|
||||
- }
|
||||
-
|
||||
- if err != nil {
|
||||
- return errors.Wrapf(err, "check config file %q failed", file.path)
|
||||
- }
|
||||
- return errors.Errorf("config file %q is not exist", file.path)
|
||||
- }
|
||||
-
|
||||
- if err := util.CheckFileInfoAndSize(file.path, constant.MaxFileSize); err != nil {
|
||||
- return err
|
||||
- }
|
||||
- if file.mergeConfig == nil {
|
||||
- continue
|
||||
- }
|
||||
- if err := file.mergeConfig(cmd); err != nil {
|
||||
- return err
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
-
|
||||
-func loadMainConfiguration(cmd *cobra.Command) error {
|
||||
- conf, err := loadConfig(constant.ConfigurationPath)
|
||||
- if err != nil {
|
||||
- logrus.Errorf("Load and parse main config file failed: %v", err)
|
||||
- os.Exit(constant.DefaultFailedCode)
|
||||
- }
|
||||
-
|
||||
- if err = mergeConfig(conf, cmd); err != nil {
|
||||
- return err
|
||||
- }
|
||||
-
|
||||
- return nil
|
||||
-}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
From 8fcff0781793107de3123bb8e39890f2b17fc4bd Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Sun, 30 Jan 2022 10:00:21 +0800
|
||||
Subject: [PATCH 17/20] adapt refactor to integration_coverage and auto shfmt
|
||||
|
||||
---
|
||||
hack/integration_coverage.sh | 16 ++++++++--------
|
||||
1 file changed, 8 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/hack/integration_coverage.sh b/hack/integration_coverage.sh
|
||||
index 7462c54..e08e3af 100755
|
||||
--- a/hack/integration_coverage.sh
|
||||
+++ b/hack/integration_coverage.sh
|
||||
@@ -24,7 +24,7 @@ go_test_mod_method="-mod=vendor"
|
||||
go_test_count_method="-count=1"
|
||||
go_test_cover_method="-covermode=set"
|
||||
main_pkg="${vendor_name}/${project_name}/${main_relative_path}"
|
||||
-main_test_file=${project_root}/${main_relative_path}/main_test.go
|
||||
+main_test_file=${project_root}/${main_relative_path}/before_test.go
|
||||
main_file=${project_root}/${main_relative_path}/main.go
|
||||
coverage_file=${project_root}/cover_integration_test_all.out
|
||||
coverage_html=${project_root}/cover_integration_test_all.html
|
||||
@@ -33,7 +33,7 @@ coverage_client_log=${project_root}/cover_integration_test_all_client.log
|
||||
main_test_binary_file=${project_root}/main.test
|
||||
|
||||
function precheck() {
|
||||
- if pgrep isula-builder > /dev/null 2>&1; then
|
||||
+ if pgrep isula-builder >/dev/null 2>&1; then
|
||||
echo "isula-builder is already running, please stop it first"
|
||||
exit 1
|
||||
fi
|
||||
@@ -48,7 +48,7 @@ function modify_main_test() {
|
||||
sed -i "/${comment_pattern}/s/^#*/\/\/ /" "${main_file}"
|
||||
# add new line for main_test.go
|
||||
code_snippet="func TestMain(t *testing.T) { main() }"
|
||||
- echo "${code_snippet}" >> "${main_test_file}"
|
||||
+ echo "${code_snippet}" >>"${main_test_file}"
|
||||
}
|
||||
|
||||
function recover_main_test() {
|
||||
@@ -58,14 +58,14 @@ function recover_main_test() {
|
||||
|
||||
function build_main_test_binary() {
|
||||
pkgs=$(go list "${go_test_mod_method}" "${project_root}"/... | grep -Ev "${exclude_pattern}" | tr "\r\n" ",")
|
||||
- go test -coverpkg="${pkgs}" "${main_pkg}" "${go_test_mod_method}" "${go_test_cover_method}" "${go_test_count_method}" -c -o="${main_test_binary_file}" > /dev/null 2>&1
|
||||
+ go test -coverpkg="${pkgs}" "${main_pkg}" "${go_test_mod_method}" "${go_test_cover_method}" "${go_test_count_method}" -c -o="${main_test_binary_file}" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
function run_main_test_binary() {
|
||||
- ${main_test_binary_file} -test.coverprofile="${coverage_file}" > "${coverage_daemon_log}" 2>&1 &
|
||||
+ ${main_test_binary_file} -test.coverprofile="${coverage_file}" >"${coverage_daemon_log}" 2>&1 &
|
||||
main_test_pid=$!
|
||||
for _ in $(seq 1 10); do
|
||||
- if isula-build info > /dev/null 2>&1; then
|
||||
+ if isula-build info >/dev/null 2>&1; then
|
||||
break
|
||||
else
|
||||
sleep 1
|
||||
@@ -77,8 +77,8 @@ function run_coverage_test() {
|
||||
# do cover tests
|
||||
while IFS= read -r testfile; do
|
||||
printf "%-60s" "test $(basename "${testfile}"): "
|
||||
- echo -e "\n$(basename "${testfile}"):" >> "${coverage_client_log}"
|
||||
- if ! bash "${testfile}" >> "${coverage_client_log}" 2>&1; then
|
||||
+ echo -e "\n$(basename "${testfile}"):" >>"${coverage_client_log}"
|
||||
+ if ! bash "${testfile}" >>"${coverage_client_log}" 2>&1; then
|
||||
echo "FAIL"
|
||||
return_code=1
|
||||
else
|
||||
--
|
||||
2.27.0
|
||||
|
||||
1232
patch/0119-config-golangci-lint-to-lint-unit-test.patch
Normal file
1232
patch/0119-config-golangci-lint-to-lint-unit-test.patch
Normal file
File diff suppressed because it is too large
Load Diff
195
patch/0120-make-isula-build-store-more-simple.patch
Normal file
195
patch/0120-make-isula-build-store-more-simple.patch
Normal file
@ -0,0 +1,195 @@
|
||||
From 2fcdfbb31346650f5661c6ab5daed46bce0997f2 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Mon, 31 Jan 2022 23:24:37 +0800
|
||||
Subject: [PATCH 19/20] make isula-build store more simple
|
||||
|
||||
---
|
||||
builder/dockerfile/stage_builder_test.go | 8 ++--
|
||||
cmd/daemon/before.go | 4 +-
|
||||
cmd/daemon/before_test.go | 10 ++---
|
||||
store/store.go | 57 +++++++++---------------
|
||||
store/store_test.go | 4 +-
|
||||
5 files changed, 34 insertions(+), 49 deletions(-)
|
||||
|
||||
diff --git a/builder/dockerfile/stage_builder_test.go b/builder/dockerfile/stage_builder_test.go
|
||||
index 2c92266..e3a814e 100644
|
||||
--- a/builder/dockerfile/stage_builder_test.go
|
||||
+++ b/builder/dockerfile/stage_builder_test.go
|
||||
@@ -82,17 +82,17 @@ func cleanAndSetDefaultStoreOpt(t *testing.T) {
|
||||
}
|
||||
|
||||
func cleanDefaultStoreOpt(t *testing.T) {
|
||||
- opt, err := store.GetDefaultStoreOptions(false)
|
||||
+ store, err := store.GetStore()
|
||||
assert.NilError(t, err)
|
||||
|
||||
- driverRoot := opt.GraphRoot + "/overlay"
|
||||
+ driverRoot := store.GraphRoot() + "/overlay"
|
||||
os.RemoveAll(driverRoot)
|
||||
assert.NilError(t, err)
|
||||
- err = os.RemoveAll(opt.RunRoot)
|
||||
+ err = os.RemoveAll(store.RunRoot())
|
||||
assert.NilError(t, err)
|
||||
err = unix.Unmount(driverRoot, 0)
|
||||
assert.NilError(t, err)
|
||||
- err = os.RemoveAll(opt.GraphRoot)
|
||||
+ err = os.RemoveAll(store.GraphRoot())
|
||||
assert.NilError(t, err)
|
||||
err = os.RemoveAll("/tmp/isula-build")
|
||||
assert.NilError(t, err)
|
||||
diff --git a/cmd/daemon/before.go b/cmd/daemon/before.go
|
||||
index ac13303..1d28d9e 100644
|
||||
--- a/cmd/daemon/before.go
|
||||
+++ b/cmd/daemon/before.go
|
||||
@@ -102,8 +102,8 @@ func validateConfigFileAndMerge(cmd *cobra.Command) error {
|
||||
}
|
||||
|
||||
func mergeStorageConfig(cmd *cobra.Command) error {
|
||||
- store.SetDefaultConfigFilePath(constant.StorageConfigPath)
|
||||
- option, err := store.GetDefaultStoreOptions(true)
|
||||
+ store.SetStorageConfigFilePath(constant.StorageConfigPath)
|
||||
+ option, err := store.GetStorageConfigFileOptions()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
diff --git a/cmd/daemon/before_test.go b/cmd/daemon/before_test.go
|
||||
index b1b8859..19b1bc0 100644
|
||||
--- a/cmd/daemon/before_test.go
|
||||
+++ b/cmd/daemon/before_test.go
|
||||
@@ -139,8 +139,8 @@ func TestRunAndDataRootSet(t *testing.T) {
|
||||
defer tmpDir.Remove()
|
||||
filePath := tmpDir.Join(fileName)
|
||||
|
||||
- store.SetDefaultConfigFilePath(filePath)
|
||||
- option, err := store.GetDefaultStoreOptions(true)
|
||||
+ store.SetStorageConfigFilePath(filePath)
|
||||
+ option, err := store.GetStorageConfigFileOptions()
|
||||
if err != nil {
|
||||
t.Fatalf("get default store options failed with error: %v", err)
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func TestRunAndDataRootSet(t *testing.T) {
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.setF()
|
||||
- storeOptions, err := store.GetDefaultStoreOptions(false)
|
||||
+ storeOptions, err := store.GetDefaultStoreOptions()
|
||||
if err != nil {
|
||||
t.Fatalf("get default store options failed with error: %v", err)
|
||||
}
|
||||
@@ -250,10 +250,10 @@ func TestValidateConfigFileAndMerge(t *testing.T) {
|
||||
err = validateConfigFileAndMerge(cmd)
|
||||
assert.NilError(t, err)
|
||||
|
||||
- if err := setStoreAccordingToDaemonOpts(); err != nil {
|
||||
+ if err = setStoreAccordingToDaemonOpts(); err != nil {
|
||||
t.Fatalf("set store options failed with error: %v", err)
|
||||
}
|
||||
- storeOptions, err := store.GetDefaultStoreOptions(false)
|
||||
+ storeOptions, err := store.GetDefaultStoreOptions()
|
||||
if err != nil {
|
||||
t.Fatalf("get default store options failed with error: %v", err)
|
||||
}
|
||||
diff --git a/store/store.go b/store/store.go
|
||||
index 410eef1..5754466 100644
|
||||
--- a/store/store.go
|
||||
+++ b/store/store.go
|
||||
@@ -41,60 +41,45 @@ type Store struct {
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
-// GetDefaultStoreOptions returns default store options.
|
||||
-func GetDefaultStoreOptions(configOnly bool) (storage.StoreOptions, error) {
|
||||
+// SetStorageConfigFilePath sets the default file path of storage configuration
|
||||
+func SetStorageConfigFilePath(path string) {
|
||||
+ storage.SetDefaultConfigFilePath(path)
|
||||
+}
|
||||
+
|
||||
+// GetStorageConfigFileOptions returns the default storage config options.
|
||||
+func GetStorageConfigFileOptions() (storage.StoreOptions, error) {
|
||||
options, err := storage.DefaultStoreOptions(false, 0)
|
||||
if err != nil {
|
||||
return storage.StoreOptions{}, err
|
||||
}
|
||||
|
||||
- if !configOnly {
|
||||
- // StoreOpts override specific parameters of options
|
||||
- if storeOpts.DataRoot != "" {
|
||||
- options.GraphRoot = storeOpts.DataRoot
|
||||
- }
|
||||
- if storeOpts.RunRoot != "" {
|
||||
- options.RunRoot = storeOpts.RunRoot
|
||||
- }
|
||||
- if storeOpts.Driver != "" {
|
||||
- options.GraphDriverName = storeOpts.Driver
|
||||
- }
|
||||
- if len(storeOpts.DriverOption) > 0 {
|
||||
- options.GraphDriverOptions = storeOpts.DriverOption
|
||||
- }
|
||||
- }
|
||||
-
|
||||
return options, nil
|
||||
}
|
||||
|
||||
// SetDefaultStoreOptions sets the default store options
|
||||
func SetDefaultStoreOptions(opt DaemonStoreOptions) {
|
||||
- if opt.DataRoot != "" {
|
||||
- storeOpts.DataRoot = opt.DataRoot
|
||||
- }
|
||||
-
|
||||
- if opt.RunRoot != "" {
|
||||
- storeOpts.RunRoot = opt.RunRoot
|
||||
- }
|
||||
+ storeOpts = opt
|
||||
+}
|
||||
|
||||
- if opt.Driver != "" {
|
||||
- storeOpts.Driver = opt.Driver
|
||||
+// GetDefaultStoreOptions returns default store options.
|
||||
+func GetDefaultStoreOptions() (storage.StoreOptions, error) {
|
||||
+ options, err := storage.DefaultStoreOptions(false, 0)
|
||||
+ if err != nil {
|
||||
+ return storage.StoreOptions{}, err
|
||||
}
|
||||
|
||||
- if len(opt.DriverOption) > 0 {
|
||||
- storeOpts.DriverOption = opt.DriverOption
|
||||
- }
|
||||
-}
|
||||
+ options.GraphRoot = storeOpts.DataRoot
|
||||
+ options.RunRoot = storeOpts.RunRoot
|
||||
+ options.GraphDriverName = storeOpts.Driver
|
||||
+ options.GraphDriverOptions = storeOpts.DriverOption
|
||||
|
||||
-// SetDefaultConfigFilePath sets the default configuration to the specified path
|
||||
-func SetDefaultConfigFilePath(path string) {
|
||||
- storage.SetDefaultConfigFilePath(path)
|
||||
+ return options, nil
|
||||
}
|
||||
|
||||
-// GetStore returns a Store object.If it is called the first time,
|
||||
+// GetStore returns a Store object. If it is called the first time,
|
||||
// a store object will be created by the default store options.
|
||||
func GetStore() (Store, error) {
|
||||
- options, err := GetDefaultStoreOptions(false)
|
||||
+ options, err := GetDefaultStoreOptions()
|
||||
if err != nil {
|
||||
return Store{}, err
|
||||
}
|
||||
diff --git a/store/store_test.go b/store/store_test.go
|
||||
index 5c69dc8..d99d871 100644
|
||||
--- a/store/store_test.go
|
||||
+++ b/store/store_test.go
|
||||
@@ -31,8 +31,8 @@ func init() {
|
||||
reexec.Init()
|
||||
}
|
||||
|
||||
-func TestWithGetDefaultStoreOptions(t *testing.T) {
|
||||
- _, err := GetDefaultStoreOptions(false)
|
||||
+func TestGetDefaultStoreOptions(t *testing.T) {
|
||||
+ _, err := GetDefaultStoreOptions()
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
From 61fdeef3a9ea095bebaa952460085e81c67df734 Mon Sep 17 00:00:00 2001
|
||||
From: xingweizheng <xingweizheng@huawei.com>
|
||||
Date: Tue, 14 Jun 2022 14:09:40 +0800
|
||||
Subject: [PATCH 20/20] print first and second error when dockerfile not found
|
||||
|
||||
---
|
||||
cmd/cli/build.go | 4 +++-
|
||||
1 file changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/cmd/cli/build.go b/cmd/cli/build.go
|
||||
index c9efd4e..82e2ceb 100644
|
||||
--- a/cmd/cli/build.go
|
||||
+++ b/cmd/cli/build.go
|
||||
@@ -478,6 +478,7 @@ func resolveDockerfilePath() (string, error) {
|
||||
return resolvedPath, nil
|
||||
}
|
||||
logrus.Debugf("Stat dockerfile failed with path %s", resolvedPath)
|
||||
+ firstErr := errors.Errorf("check dockerfile %s failed: %v", resolvedPath, err)
|
||||
|
||||
// not found with filepath, try to resolve with contextDir+filepath
|
||||
resolvedPath = path.Join(buildOpts.contextDir, buildOpts.file)
|
||||
@@ -485,9 +486,10 @@ func resolveDockerfilePath() (string, error) {
|
||||
return resolvedPath, nil
|
||||
|
||||
}
|
||||
+ secondErr := errors.Errorf("check dockerfile %s failed again: %v", resolvedPath, err)
|
||||
logrus.Debugf("Stat dockerfile failed again with path %s", resolvedPath)
|
||||
|
||||
- return "", errors.Wrap(err, "check dockerfile failed")
|
||||
+ return "", errors.Errorf("%v, %v", firstErr, secondErr)
|
||||
}
|
||||
|
||||
func getAbsPath(path string) (string, error) {
|
||||
--
|
||||
2.27.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user