mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 解决镜像构建失败的问题
This commit is contained in:
parent
dd06ff73e6
commit
d04121c551
@ -122,7 +122,7 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
if req.From == "edit" {
|
||||
dir := fmt.Sprintf("%s/docker/build/%s", constant.DataDir, req.Name)
|
||||
dir := fmt.Sprintf("%s/docker/build/%s", constant.DataDir, strings.ReplaceAll(req.Name, ":", "_"))
|
||||
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
return "", err
|
||||
@ -139,6 +139,8 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
|
||||
_, _ = write.WriteString(string(req.Dockerfile))
|
||||
write.Flush()
|
||||
req.Dockerfile = dir
|
||||
} else {
|
||||
req.Dockerfile = strings.ReplaceAll(req.Dockerfile, "/Dockerfile", "")
|
||||
}
|
||||
tar, err := archive.TarWithOptions(req.Dockerfile+"/", &archive.TarOptions{})
|
||||
if err != nil {
|
||||
@ -161,13 +163,27 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
|
||||
go func() {
|
||||
defer file.Close()
|
||||
defer tar.Close()
|
||||
res, err := client.ImageBuild(context.TODO(), tar, opts)
|
||||
res, err := client.ImageBuild(context.Background(), tar, opts)
|
||||
if err != nil {
|
||||
global.LOG.Errorf("build image %s failed, err: %v", req.Name, err)
|
||||
_, _ = file.WriteString("image build failed!")
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
global.LOG.Errorf("build image %s failed, err: %v", req.Name, err)
|
||||
_, _ = file.WriteString(fmt.Sprintf("build image %s failed, err: %v", req.Name, err))
|
||||
_, _ = file.WriteString("image build failed!")
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(string(body), "error") && strings.Contains(string(body), "failed:") {
|
||||
global.LOG.Errorf("build image %s failed", req.Name)
|
||||
_, _ = file.Write(body)
|
||||
_, _ = file.WriteString("image build failed!")
|
||||
return
|
||||
}
|
||||
global.LOG.Infof("build image %s successful!", req.Name)
|
||||
_, _ = io.Copy(file, res.Body)
|
||||
_, _ = file.WriteString("image build successful!")
|
||||
|
@ -5,6 +5,11 @@ export function formatImageStdout(stdout: string) {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (isJson(lines[i])) {
|
||||
const data = JSON.parse(lines[i]);
|
||||
if (data.errorDetail || data.error) {
|
||||
lines[i] = data.errorDetail || data.errorDetail;
|
||||
lines[i] = data.error || data.error;
|
||||
continue;
|
||||
}
|
||||
if (data.stream) {
|
||||
lines[i] = data.stream;
|
||||
continue;
|
||||
|
@ -117,7 +117,7 @@ const form = reactive({
|
||||
tags: [] as Array<string>,
|
||||
});
|
||||
const varifyPath = (rule: any, value: any, callback: any) => {
|
||||
if (value.indexOf('docker-compose.yml') === -1) {
|
||||
if (value.indexOf('Dockerfile') === -1) {
|
||||
callback(new Error(i18n.global.t('commons.rule.selectHelper', ['Dockerfile'])));
|
||||
}
|
||||
callback();
|
||||
|
Loading…
x
Reference in New Issue
Block a user