提交 0367900a 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!22 bugfix: use abs path instead of relative path in build

Merge pull request !22 from DCCooper/bugfix
......@@ -260,12 +260,13 @@ func parseStaticBuildOpts() (*pb.BuildStatic, error) {
func runBuild(ctx context.Context, cli Cli) (string, error) {
var (
err error
content string
dest string
isIsulad bool
imageID string
msg *pb.BuildResponse
isIsulad bool
msg *pb.BuildResponse
err error
content string
dest string
imageID string
imageIDFilePath string
)
if dest, isIsulad, err = checkAndProcessOutput(); err != nil {
......@@ -277,6 +278,12 @@ func runBuild(ctx context.Context, cli Cli) (string, error) {
if err = encryptBuildArgs(); err != nil {
return "", errors.Wrap(err, "encrypt --build-arg failed")
}
imageIDFilePath, err = getAbsPath(buildOpts.imageIDFile)
if err != nil {
return "", err
}
buildOpts.imageIDFile = imageIDFilePath
buildStatic, err := parseStaticBuildOpts()
if err != nil {
return "", err
......@@ -457,3 +464,18 @@ func resolveDockerfilePath() (string, error) {
}
return resolvedPath, nil
}
func getAbsPath(path string) (string, error) {
if path == "" {
return "", nil
}
if filepath.IsAbs(path) {
return path, nil
}
pwd, err := os.Getwd()
if err != nil {
return "", err
}
return util.MakeAbsolute(path, pwd), nil
}
......@@ -613,3 +613,41 @@ func TestEncryptBuildArgs(t *testing.T) {
})
}
}
func TestGetAbsPath(t *testing.T) {
pwd, _ := os.Getwd()
type args struct {
path string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "TC1 - normal case with relative path",
args: args{path: "./imageID.txt"},
want: filepath.Join(pwd, "imageID.txt"),
wantErr: false,
},
{
name: "TC2 - normal case with abs path",
args: args{path: filepath.Join(pwd, "imageID.txt")},
want: filepath.Join(pwd, "imageID.txt"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getAbsPath(tt.args.path)
if (err != nil) != tt.wantErr {
t.Errorf("getAbsPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("getAbsPath() got = %v, want %v", got, tt.want)
}
})
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册