diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-09-14 13:08:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 13:08:13 -0400 |
commit | 65b1ff25a3444f16c9b0524f8a02cd6e56976e2b (patch) | |
tree | be2c5f3d62037954360ff8cb741c3d5530cf44a2 /pkg/machine/fcos.go | |
parent | bb8b2ed7deb71431521d24486b0856845e7a7867 (diff) | |
parent | 952fc4a6f9b01060d35fdb9e2577e76eeeb83526 (diff) | |
download | podman-65b1ff25a3444f16c9b0524f8a02cd6e56976e2b.tar.gz podman-65b1ff25a3444f16c9b0524f8a02cd6e56976e2b.tar.bz2 podman-65b1ff25a3444f16c9b0524f8a02cd6e56976e2b.zip |
Merge pull request #11569 from baude/macaarch64pullfcos
Use new aarch64 fcos repos
Diffstat (limited to 'pkg/machine/fcos.go')
-rw-r--r-- | pkg/machine/fcos.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go index 4ea965b7f..cfcadeb02 100644 --- a/pkg/machine/fcos.go +++ b/pkg/machine/fcos.go @@ -3,12 +3,20 @@ package machine import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" url2 "net/url" "os" "path/filepath" "runtime" "strings" + "github.com/coreos/stream-metadata-go/fedoracoreos" + "github.com/coreos/stream-metadata-go/stream" + "github.com/pkg/errors" + digest "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" ) @@ -121,3 +129,68 @@ func getFcosArch() string { } return arch } + +// This should get Exported and stay put as it will apply to all fcos downloads +// getFCOS parses fedoraCoreOS's stream and returns the image download URL and the release version +func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) { + var ( + fcosstable stream.Stream + streamType string + ) + switch imageStream { + case "testing", "": + streamType = fedoracoreos.StreamNext + case "stable": + streamType = fedoracoreos.StreamStable + default: + return nil, errors.Errorf("invalid stream %s: valid streams are `testing` and `stable`", imageStream) + } + streamurl := fedoracoreos.GetStreamURL(streamType) + resp, err := http.Get(streamurl.String()) + if err != nil { + return nil, err + } + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + defer func() { + if err := resp.Body.Close(); err != nil { + logrus.Error(err) + } + }() + + if err := json.Unmarshal(body, &fcosstable); err != nil { + return nil, err + } + arch, ok := fcosstable.Architectures[getFcosArch()] + if !ok { + return nil, fmt.Errorf("unable to pull VM image: no targetArch in stream") + } + artifacts := arch.Artifacts + if artifacts == nil { + return nil, fmt.Errorf("unable to pull VM image: no artifact in stream") + } + qemu, ok := artifacts[artifact] + if !ok { + return nil, fmt.Errorf("unable to pull VM image: no qemu artifact in stream") + } + formats := qemu.Formats + if formats == nil { + return nil, fmt.Errorf("unable to pull VM image: no formats in stream") + } + qcow, ok := formats[Format] + if !ok { + return nil, fmt.Errorf("unable to pull VM image: no qcow2.xz format in stream") + } + disk := qcow.Disk + if disk == nil { + return nil, fmt.Errorf("unable to pull VM image: no disk in stream") + } + return &fcosDownloadInfo{ + Location: disk.Location, + Release: qemu.Release, + Sha256Sum: disk.Sha256, + CompressionType: "xz", + }, nil +} |