Skip to content

Commit

Permalink
Switch to using stream-metadata-go library
Browse files Browse the repository at this point in the history
After we have a shared Go library for streams, we can use it
in e.g. coreos-assembler/mantle as well as openshift-install.
  • Loading branch information
cgwalters committed Dec 18, 2020
1 parent f7008f7 commit e1d4ca4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 205 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# fedora-coreos-stream-generator
Generates stream metadata for Fedora CoreOS using release metadata and overrides.

For more information, see https://github.com/coreos/fedora-coreos-tracker/issues/98

# Running
Make sure you have latest go installed and then download the package.
```
Expand Down
21 changes: 0 additions & 21 deletions common.go

This file was deleted.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/coreos/fedora-coreos-stream-generator

go 1.12

require github.com/cgwalters/stream-metadata-go v0.0.0-20201218003402-b23c51ccf8c7
62 changes: 32 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ import (
"net/url"
"os"
"time"

stream "github.com/cgwalters/stream-metadata-go"
)

var errReleaseIndexMissing = errors.New("Please specify release index url or release override")

func releaseToStream(releaseArch *ReleaseArch, release Release) StreamArch {
artifacts := StreamArtifacts{}
cloudImages := StreamImages{}
func releaseToStream(releaseArch *stream.ReleaseArch, release stream.Release) stream.Arch {
artifacts := stream.Artifacts{}
cloudImages := stream.Images{}
if releaseArch.Media.Aws != nil {
aws := StreamMediaDetails{
aws := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Aws.Artifacts,
}
artifacts.Aws = &aws
awsAmis := StreamAwsImage{
Regions: make(map[string]*StreamAwsAMI),
awsAmis := stream.AwsImage{
Regions: make(map[string]*stream.AwsAMI),
}

if releaseArch.Media.Aws != nil && releaseArch.Media.Aws.Images != nil {
for region, ami := range *releaseArch.Media.Aws.Images {
streamAwsAMI := StreamAwsAMI{}
streamAwsAMI := stream.AwsAMI{}
streamAwsAMI.Release = release.Release
streamAwsAMI.Image = *ami.Image
awsAmis.Regions[region] = &streamAwsAMI
Expand All @@ -41,53 +43,53 @@ func releaseToStream(releaseArch *ReleaseArch, release Release) StreamArch {
}

if releaseArch.Media.Azure != nil {
azure := StreamMediaDetails{
azure := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Azure.Artifacts,
}
artifacts.Azure = &azure

if az := releaseArch.Media.Azure.Images; az != nil && az.Global != nil && az.Global.Image != nil {
azureImage := StreamCloudImage{}
azureImage := stream.CloudImage{}
azureImage.Image = fmt.Sprintf("Fedora:CoreOS:%s:latest", release.Stream)
cloudImages.Azure = &azureImage
}

}

if releaseArch.Media.Aliyun != nil {
aliyun := StreamMediaDetails{
aliyun := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Aliyun.Artifacts,
}
artifacts.Aliyun = &aliyun
}

if releaseArch.Media.Exoscale != nil {
exoscale := StreamMediaDetails{
exoscale := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Exoscale.Artifacts,
}
artifacts.Exoscale = &exoscale
}

if releaseArch.Media.Vultr != nil {
vultr := StreamMediaDetails{
vultr := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Vultr.Artifacts,
}
artifacts.Vultr = &vultr
}

if releaseArch.Media.Gcp != nil {
gcp := StreamMediaDetails{
gcp := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Gcp.Artifacts,
}
artifacts.Gcp = &gcp

if releaseArch.Media.Gcp != nil && releaseArch.Media.Gcp.Image != nil {
gcpImage := StreamGcpImage{
gcpImage := stream.GcpImage{
Name: releaseArch.Media.Gcp.Image.Name,
Family: releaseArch.Media.Gcp.Image.Family,
Project: releaseArch.Media.Gcp.Image.Project,
Expand All @@ -98,83 +100,83 @@ func releaseToStream(releaseArch *ReleaseArch, release Release) StreamArch {
}

if releaseArch.Media.Digitalocean != nil {
digitalOcean := StreamMediaDetails{
digitalOcean := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Digitalocean.Artifacts,
}
artifacts.Digitalocean = &digitalOcean

/* We're producing artifacts but they're not yet available
in DigitalOcean as distribution images.
digitalOceanImage := StreamCloudImage{Image: fmt.Sprintf("fedora-coreos-%s", release.Stream)}
digitalOceanImage := stream.CloudImage{Image: fmt.Sprintf("fedora-coreos-%s", release.Stream)}
cloudImages.Digitalocean = &digitalOceanImage
*/
}

if releaseArch.Media.Ibmcloud != nil {
ibmcloud := StreamMediaDetails{
ibmcloud := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Ibmcloud.Artifacts,
}
artifacts.Ibmcloud = &ibmcloud
}

if releaseArch.Media.Packet != nil {
packet := StreamMediaDetails{
packet := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Packet.Artifacts,
}
artifacts.Packet = &packet

packetImage := StreamCloudImage{Image: fmt.Sprintf("fedora_coreos_%s", release.Stream)}
packetImage := stream.CloudImage{Image: fmt.Sprintf("fedora_coreos_%s", release.Stream)}
cloudImages.Packet = &packetImage
}

if releaseArch.Media.Openstack != nil {
openstack := StreamMediaDetails{
openstack := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Openstack.Artifacts,
}
artifacts.Openstack = &openstack
}

if releaseArch.Media.Qemu != nil {
qemu := StreamMediaDetails{
qemu := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Qemu.Artifacts,
}
artifacts.Qemu = &qemu
}

if releaseArch.Media.Virtualbox != nil {
virtualbox := StreamMediaDetails{
virtualbox := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Virtualbox.Artifacts,
}
artifacts.Virtualbox = &virtualbox
}

if releaseArch.Media.Vmware != nil {
vmware := StreamMediaDetails{
vmware := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Vmware.Artifacts,
}
artifacts.Vmware = &vmware
}

if releaseArch.Media.Metal != nil {
metal := StreamMediaDetails{
metal := stream.MediaDetails{
Release: release.Release,
Formats: releaseArch.Media.Metal.Artifacts,
}
artifacts.Metal = &metal
}

streamArch := StreamArch{
streamArch := stream.Arch{
Artifacts: artifacts,
}

if cloudImages != (StreamImages{}) {
if cloudImages != (stream.Images{}) {
streamArch.Images = &cloudImages
}

Expand Down Expand Up @@ -258,20 +260,20 @@ func run() error {
decoder = json.NewDecoder(resp.Body)
}

var release Release
var release stream.Release
if err = decoder.Decode(&release); err != nil {
return fmt.Errorf("Error while decoding json: %v", err)
}

streamArch := make(map[string]*StreamArch)
streamArch := make(map[string]*stream.Arch)
for arch, releaseArch := range release.Architectures {
archContent := releaseToStream(releaseArch, release)
streamArch[arch] = &archContent
}

streamMetadata := StreamMetadata{
streamMetadata := stream.Metadata{
Stream: release.Stream,
Metadata: Metadata{LastModified: time.Now().UTC().Format(time.RFC3339)},
Meta: stream.BuildMetadata{LastModified: time.Now().UTC().Format(time.RFC3339)},
Architectures: streamArch,
// Updates: StreamUpdates{Release: release.Release},
}
Expand Down
78 changes: 0 additions & 78 deletions release.go

This file was deleted.

Loading

0 comments on commit e1d4ca4

Please sign in to comment.