mirror of https://github.com/containers/podman.git
Merge pull request #14968 from jmguzik/compat
Compat API: unify pull/push and add missing progress info
This commit is contained in:
commit
02eb057920
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v4/pkg/domain/infra/abi"
|
"github.com/containers/podman/v4/pkg/domain/infra/abi"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -325,16 +326,8 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
loop: // break out of for/select infinite loop
|
loop: // break out of for/select infinite loop
|
||||||
for {
|
for {
|
||||||
var report struct {
|
report := jsonmessage.JSONMessage{}
|
||||||
Stream string `json:"stream,omitempty"`
|
report.Progress = &jsonmessage.JSONProgress{}
|
||||||
Status string `json:"status,omitempty"`
|
|
||||||
Progress struct {
|
|
||||||
Current uint64 `json:"current,omitempty"`
|
|
||||||
Total int64 `json:"total,omitempty"`
|
|
||||||
} `json:"progressDetail,omitempty"`
|
|
||||||
Error string `json:"error,omitempty"`
|
|
||||||
Id string `json:"id,omitempty"` //nolint:revive,stylecheck
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case e := <-progress:
|
case e := <-progress:
|
||||||
switch e.Event {
|
switch e.Event {
|
||||||
|
@ -342,14 +335,15 @@ loop: // break out of for/select infinite loop
|
||||||
report.Status = "Pulling fs layer"
|
report.Status = "Pulling fs layer"
|
||||||
case types.ProgressEventRead:
|
case types.ProgressEventRead:
|
||||||
report.Status = "Downloading"
|
report.Status = "Downloading"
|
||||||
report.Progress.Current = e.Offset
|
report.Progress.Current = int64(e.Offset)
|
||||||
report.Progress.Total = e.Artifact.Size
|
report.Progress.Total = e.Artifact.Size
|
||||||
|
report.ProgressMessage = report.Progress.String()
|
||||||
case types.ProgressEventSkipped:
|
case types.ProgressEventSkipped:
|
||||||
report.Status = "Already exists"
|
report.Status = "Already exists"
|
||||||
case types.ProgressEventDone:
|
case types.ProgressEventDone:
|
||||||
report.Status = "Download complete"
|
report.Status = "Download complete"
|
||||||
}
|
}
|
||||||
report.Id = e.Artifact.Digest.Encoded()[0:12]
|
report.ID = e.Artifact.Digest.Encoded()[0:12]
|
||||||
if err := enc.Encode(report); err != nil {
|
if err := enc.Encode(report); err != nil {
|
||||||
logrus.Warnf("Failed to json encode error %q", err.Error())
|
logrus.Warnf("Failed to json encode error %q", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -358,7 +352,11 @@ loop: // break out of for/select infinite loop
|
||||||
err := pullRes.err
|
err := pullRes.err
|
||||||
pulledImages := pullRes.images
|
pulledImages := pullRes.images
|
||||||
if err != nil {
|
if err != nil {
|
||||||
report.Error = err.Error()
|
msg := err.Error()
|
||||||
|
report.Error = &jsonmessage.JSONError{
|
||||||
|
Message: msg,
|
||||||
|
}
|
||||||
|
report.ErrorMessage = msg
|
||||||
} else {
|
} else {
|
||||||
if len(pulledImages) > 0 {
|
if len(pulledImages) > 0 {
|
||||||
img := pulledImages[0].ID()
|
img := pulledImages[0].ID()
|
||||||
|
@ -367,9 +365,13 @@ loop: // break out of for/select infinite loop
|
||||||
} else {
|
} else {
|
||||||
report.Status = "Download complete"
|
report.Status = "Download complete"
|
||||||
}
|
}
|
||||||
report.Id = img[0:12]
|
report.ID = img[0:12]
|
||||||
} else {
|
} else {
|
||||||
report.Error = "internal error: no images pulled"
|
msg := "internal error: no images pulled"
|
||||||
|
report.Error = &jsonmessage.JSONError{
|
||||||
|
Message: msg,
|
||||||
|
}
|
||||||
|
report.ErrorMessage = msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := enc.Encode(report); err != nil {
|
if err := enc.Encode(report); err != nil {
|
||||||
|
|
|
@ -156,6 +156,7 @@ loop: // break out of for/select infinite loop
|
||||||
Current: int64(e.Offset),
|
Current: int64(e.Offset),
|
||||||
Total: e.Artifact.Size,
|
Total: e.Artifact.Size,
|
||||||
}
|
}
|
||||||
|
report.ProgressMessage = report.Progress.String()
|
||||||
case types.ProgressEventSkipped:
|
case types.ProgressEventSkipped:
|
||||||
report.Status = "Layer already exists"
|
report.Status = "Layer already exists"
|
||||||
case types.ProgressEventDone:
|
case types.ProgressEventDone:
|
||||||
|
|
Loading…
Reference in New Issue