Skip to content

Commit

Permalink
Merge branch 'refs/heads/UGREEN-DEV' into UGREEN
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyLTY committed Jun 9, 2024
2 parents fe69b00 + c7b4005 commit a7a4b06
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.20

require (
github.com/distribution/reference v0.5.0
github.com/docker/distribution v2.8.3+incompatible
github.com/docker/docker v25.0.1+incompatible
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3
github.com/golang-jwt/jwt v3.2.2+incompatible
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v25.0.1+incompatible h1:k5TYd5rIVQRSqcTwCID+cyVA0yRg86+Pcrz1ls0/frA=
github.com/docker/docker v25.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
Expand Down
2 changes: 1 addition & 1 deletion internal/logic/auth/loginlogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.Resp, err error) {
resp.Data = JwtResponse{Jwt: ""}
return resp, errors.New("生成 token出现错误,请重试")
}
resp.Code = 201
resp.Code = 200
resp.Msg = "success"
resp.Data = JwtResponse{Jwt: jwtToken}
return resp, nil
Expand Down
7 changes: 6 additions & 1 deletion internal/utiles/restorecontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ func RestoreContainer(ctx *svc.ServiceContext, filename string, taskID string) e
logx.Errorf("Failed to pull image: %s", err)
continue
}
decodePullResp(reader, ctx, taskID)
err = decodePullResp(reader, ctx, taskID)
if err != nil {
backupList = append(backupList, containerInfo.Config.Image+"拉取镜像出现错误"+err.Error())
logx.Errorf("Failed to pull image: %s", err)
continue
}
_, err = ctx.DockerClient.ContainerCreate(context.TODO(), containerInfo.Config, containerInfo.HostConfig, containerInfo.NetworkingConfig, nil, containerInfo.Name)
if err != nil {
logx.Error("Failed to create container: %s", err)
Expand Down
22 changes: 16 additions & 6 deletions internal/utiles/updatecontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ func UpdateContainer(ctx *svc.ServiceContext, id string, name string, imageNameA
oldTaskProgress.IsDone = true
ctx.UpdateProgress(taskID, oldTaskProgress)
logx.Errorf("Failed to pull image: %s", err)
return err
}
err = decodePullResp(reader, ctx, taskID)
if err != nil {
oldTaskProgress.Message = "拉取镜像失败"
oldTaskProgress.DetailMsg = err.Error()
oldTaskProgress.IsDone = true
ctx.UpdateProgress(taskID, oldTaskProgress)
logx.Errorf("Failed to pull image: %s", err)
return err
}
decodePullResp(reader, ctx, taskID)
oldTaskProgress, result = ctx.GetProgress(taskID)
if !result {
oldTaskProgress = svc.TaskProgress{
Expand Down Expand Up @@ -166,7 +175,7 @@ func UpdateContainer(ctx *svc.ServiceContext, id string, name string, imageNameA
return nil
}

func decodePullResp(reader io.Reader, ctx *svc.ServiceContext, taskID string) {
func decodePullResp(reader io.Reader, ctx *svc.ServiceContext, taskID string) (err error) {
decoder := json.NewDecoder(reader)
var oldTaskProgress, result = ctx.GetProgress(taskID)
if !result {
Expand All @@ -180,16 +189,17 @@ func decodePullResp(reader io.Reader, ctx *svc.ServiceContext, taskID string) {
}
for {
var msg dockerMsgType.JSONMessage
if err := decoder.Decode(&msg); err != nil {
if err = decoder.Decode(&msg); err != nil {
if err == io.EOF {
break
return nil
}
oldTaskProgress.Message = "拉取镜像失败"
oldTaskProgress.DetailMsg = err.Error()
oldTaskProgress.Percentage = 25
oldTaskProgress.IsDone = true
ctx.UpdateProgress(taskID, oldTaskProgress)
logx.Errorf("Failed to decode pull image response: %s", err)
return fmt.Errorf("拉取镜像失败: %w", err)
}
// Print the progress or error information from the response
if msg.Error != nil {
Expand All @@ -199,6 +209,7 @@ func decodePullResp(reader io.Reader, ctx *svc.ServiceContext, taskID string) {
oldTaskProgress.IsDone = true
ctx.UpdateProgress(taskID, oldTaskProgress)
logx.Errorf("Error: %s", msg.Error)
return fmt.Errorf("拉取镜像失败: %w", msg.Error)
} else {
var formattedMsg string
if msg.Progress != nil {
Expand All @@ -207,10 +218,9 @@ func decodePullResp(reader io.Reader, ctx *svc.ServiceContext, taskID string) {
formattedMsg = fmt.Sprintf("进度%s", msg.Status)
}
oldTaskProgress.DetailMsg = formattedMsg
logx.Errorf("Error: %s", formattedMsg)
oldTaskProgress.Percentage = 25
ctx.UpdateProgress(taskID, oldTaskProgress)
logx.Infof("%s: %s\n", msg.Status, msg.Progress)
logx.Infof("拉取镜像进度\t %s: %s\n", msg.Status, msg.Progress)
}
}
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.4-UGREEN
v2.0.5-UGREEN

0 comments on commit a7a4b06

Please sign in to comment.