|
|
|
@ -123,6 +123,7 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
|
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
fileName := "Dockerfile" |
|
|
|
|
dockerLogDir := path.Join(global.CONF.System.TmpDir, "/docker_logs") |
|
|
|
|
if req.From == "edit" { |
|
|
|
|
dir := fmt.Sprintf("%s/docker/build/%s", constant.DataDir, strings.ReplaceAll(req.Name, ":", "_")) |
|
|
|
|
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) { |
|
|
|
@ -156,10 +157,9 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
|
|
|
|
|
Remove: true, |
|
|
|
|
Labels: stringsToMap(req.Tags), |
|
|
|
|
} |
|
|
|
|
logName := fmt.Sprintf("%s/build.log", req.Dockerfile) |
|
|
|
|
|
|
|
|
|
pathItem := logName |
|
|
|
|
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
|
|
|
|
logItem := fmt.Sprintf("%s/image_build_%s_%s.log", dockerLogDir, strings.ReplaceAll(req.Name, ":", "_"), time.Now().Format("20060102150405")) |
|
|
|
|
file, err := os.OpenFile(logItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
@ -192,7 +192,7 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
|
|
|
|
|
_, _ = file.WriteString("image build successful!") |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
return logName, nil |
|
|
|
|
return path.Base(logItem), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) { |
|
|
|
@ -200,15 +200,15 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) {
|
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
dockerLogDir := global.CONF.System.TmpDir + "/docker_logs" |
|
|
|
|
dockerLogDir := path.Join(global.CONF.System.TmpDir, "/docker_logs") |
|
|
|
|
if _, err := os.Stat(dockerLogDir); err != nil && os.IsNotExist(err) { |
|
|
|
|
if err = os.MkdirAll(dockerLogDir, os.ModePerm); err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
imageItemName := strings.ReplaceAll(path.Base(req.ImageName), ":", "_") |
|
|
|
|
pathItem := fmt.Sprintf("%s/image_pull_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405")) |
|
|
|
|
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
|
|
|
|
logItem := fmt.Sprintf("%s/image_pull_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405")) |
|
|
|
|
file, err := os.OpenFile(logItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
@ -224,7 +224,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) {
|
|
|
|
|
global.LOG.Infof("pull image %s successful!", req.ImageName) |
|
|
|
|
_, _ = io.Copy(file, out) |
|
|
|
|
}() |
|
|
|
|
return pathItem, nil |
|
|
|
|
return path.Base(logItem), nil |
|
|
|
|
} |
|
|
|
|
repo, err := imageRepoRepo.Get(commonRepo.WithByID(req.RepoID)) |
|
|
|
|
if err != nil { |
|
|
|
@ -257,7 +257,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) {
|
|
|
|
|
_, _ = io.Copy(file, out) |
|
|
|
|
_, _ = file.WriteString("image pull successful!") |
|
|
|
|
}() |
|
|
|
|
return pathItem, nil |
|
|
|
|
return path.Base(logItem), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (u *ImageService) ImageLoad(req dto.ImageLoad) error { |
|
|
|
@ -354,8 +354,8 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
imageItemName := strings.ReplaceAll(path.Base(req.Name), ":", "_") |
|
|
|
|
pathItem := fmt.Sprintf("%s/image_push_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405")) |
|
|
|
|
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
|
|
|
|
logItem := fmt.Sprintf("%s/image_push_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405")) |
|
|
|
|
file, err := os.OpenFile(logItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
@ -373,7 +373,7 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) {
|
|
|
|
|
_, _ = file.WriteString("image push successful!") |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
return pathItem, nil |
|
|
|
|
return path.Base(logItem), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (u *ImageService) ImageRemove(req dto.BatchDelete) error { |
|
|
|
|