Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate stream metadata from releases #1

Merged
merged 1 commit into from
Jul 11, 2019
Merged

Generate stream metadata from releases #1

merged 1 commit into from
Jul 11, 2019

Conversation

sinnykumari
Copy link
Contributor

No description provided.

main.go Outdated
os.Exit(1)
}

defer file.Close()

This comment was marked as resolved.

release.go Outdated
Release string `json:"release"`
Stream string `json:"stream"`
Metadata Metadata `json:"metadata"`
Architectures ReleaseArchitectures `json:"architectures"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worthwhile to use a map of strings to a generic architecture type over a wrapper struct.


defer file.Close()

if overrideFilename != "" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended that stream.json is still produced if overrideFilename is specified? I would expect that if specified the output would be routed to that location instead of stream.json.

Copy link
Contributor Author

@sinnykumari sinnykumari Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand yes, stream.json will be automatically generated in both cases - a) when release.json is updated b) when an override file is specified.
As per coreos/fedora-coreos-tracker#192 (comment) , stream.json is what user will be referring to download latest media . Override file be a partial file(following stream,json schema) which will be used only when we want users to download some other version than what is available in release.json .Some detail on override file is in coreos/fedora-coreos-tracker#98 . @bgilbert did I get things right?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misread this initially as an additional output file. Don't mind me.

@sinnykumari
Copy link
Contributor Author

Thanks @lucab and @arithx for review! Addressed review comment in sinnykumari@2899dae

main.go Outdated

if releaseArch.Media.Azure.Images.Global != nil {
if releaseArch.Media.Azure.Images != nil &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The golang style of formatting makes this block a bit hard to read at a glance. Might read better doing something like so:

if az := releaseArch.Media.Azure.Images; az != nil && az.Global != nil && az.Global.Image != nil {
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, fixed it!

return "", err
}

return relIndex.Releases[len(relIndex.Releases)-1].Metadata, nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to have a check that len(relIndex.Releases) > 0, this may panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, nice catch. fixed!

main.go Outdated

func main() {
err := run()
if err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style suggestion: you can write this as if err := run(); err != nil {...}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still picking up Go, thanks for the suggestion, fixed!

@lucab
Copy link

lucab commented Jul 1, 2019

Just two minor things, looks good otherwise. I didn't spot any logic mistake in here, but I didn't look too hard...

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments from a quick scan!

main.go Outdated Show resolved Hide resolved
main.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@arithx
Copy link

arithx commented Jul 5, 2019

I tested this against the meta translation tool I'm writing and it worked. I would suggest a patch dropping the Artifacts type and using a map[string]*ImageFormat where you're currently declaring them. That way the Artifacts type doesn't have to specify every single format for them to be picked up.

Here's an example of the patch I hacked together:

From 84c61de26b553b775bff1eebb358e95129bbf52c Mon Sep 17 00:00:00 2001
From: Stephen Lowrie
Date: Fri, 5 Jul 2019 10:27:15 -0500
Subject: [PATCH] *: switch artifacts to map

This allows the tool to pick up different artifact formats without
needing to add additional keys.
---
 common.go  | 14 --------------
 release.go | 16 ++++++++--------
 stream.go  |  4 ++--
 3 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/common.go b/common.go
index 310266d..6af7481 100644
--- a/common.go
+++ b/common.go
@@ -5,20 +5,6 @@ type Metadata struct {
 	LastModified string `json:"last-modified"`
 }
 
-// Artifacts contains various artifacts
-type Artifacts struct {
-	Raw     *ImageFormat `json:"raw.xz,omitempty"`
-	Qemu    *ImageFormat `json:"qcow.xz,omitempty"`
-	Ova     *ImageFormat `json:"ova,omitempty"`
-	Tar     *ImageFormat `json:"tar.gz,omitempty"`
-	Vmdk    *ImageFormat `json:"vmdk.xz,omitempty"`
-	Vdi     *ImageFormat `json:"vdi.xz,omitempty"`
-	Iso     *ImageFormat `json:"iso,omitempty"`
-	Pxe     *ImageFormat `json:"pxe,omitempty"`
-	InstIso *ImageFormat `json:"installer.iso,omitempty"`
-	InstPxe *ImageFormat `json:"installer-pxe,omitempty"`
-}
-
 // ImageFormat contains Disk image details
 type ImageFormat struct {
 	Disk      *ImageType `json:"disk,omitempty"`
diff --git a/release.go b/release.go
index 6e14ac8..56d3ffe 100644
--- a/release.go
+++ b/release.go
@@ -29,20 +29,20 @@ type ReleaseMedia struct {
 
 // ReleaseAws contains AWS image information
 type ReleaseAws struct {
-	Artifacts Artifacts                      `json:"artifacts"`
+	Artifacts map[string]*ImageFormat        `json:"artifacts"`
 	Images    *map[string]*ReleaseCloudImage `json:"images"`
 }
 
 // ReleaseDigitalOcean DigitalOcean image detail
 type ReleaseDigitalOcean struct {
-	Artifacts Artifacts `json:"artifacts"`
-	Image     string    `json:"image"`
+	Artifacts map[string]*ImageFormat `json:"artifacts"`
+	Image     string                  `json:"image"`
 }
 
 // ReleaseAzure Azure image detail
 type ReleaseAzure struct {
-	Artifacts Artifacts           `json:"artifacts"`
-	Images    *ReleaseAzureImages `json:"images"`
+	Artifacts map[string]*ImageFormat `json:"artifacts"`
+	Images    *ReleaseAzureImages     `json:"images"`
 }
 
 // ReleaseAzureImages Azure image detail
@@ -52,8 +52,8 @@ type ReleaseAzureImages struct {
 
 // ReleaseGcp GCP image detail
 type ReleaseGcp struct {
-	Artifacts Artifacts `json:"artifacts"`
-	Image     *string   `json:"image"`
+	Artifacts map[string]*ImageFormat `json:"artifacts"`
+	Image     *string                 `json:"image"`
 }
 
 // ReleaseCloudImage cloud image information
@@ -63,5 +63,5 @@ type ReleaseCloudImage struct {
 
 // ReleaseTargetPlatform target platforms
 type ReleaseTargetPlatform struct {
-	Artifacts Artifacts `json:"artifacts"`
+	Artifacts map[string]*ImageFormat `json:"artifacts"`
 }
diff --git a/stream.go b/stream.go
index 23fded1..4f6a3cc 100644
--- a/stream.go
+++ b/stream.go
@@ -30,8 +30,8 @@ type StreamArtifacts struct {
 
 // StreamMediaDetails contains image artifact and release detail
 type StreamMediaDetails struct {
-	Release string    `json:"release"`
-	Formats Artifacts `json:"formats"`
+	Release string                  `json:"release"`
+	Formats map[string]*ImageFormat `json:"formats"`
 }
 
 // StreamImages contains images available in cloud providers
-- 
2.21.0

@sinnykumari
Copy link
Contributor Author

Thanks @arithx for the patch! it looks good and have pushed same in sinnykumari@5e56fa0

@sinnykumari
Copy link
Contributor Author

Can we have a final review on this PR before we merge it to master?

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment, otherwise LGTM!

}

// If outputFile option not specified print on stdout
if outputFile != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: could dedupe this logic by having e.g. an out variable that you set to either os.Stdout or streamFile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed it

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comment: in the interest of keeping the git history clean, WDYT about squashing it all to a single "initial commit" patch to seed master with? I find my initial git commits are usually of low quality as I hack things together, and so becomes mostly noise.

Up to you though, it mostly comes down to personal preference. :)

@sinnykumari
Copy link
Contributor Author

I am also in favor if keeping git history clean. Squashed all commits to single commit.

Will wait for some time before merging to address any final review comment

@sinnykumari sinnykumari merged commit 725ea8b into master Jul 11, 2019
@sinnykumari
Copy link
Contributor Author

merged, thanks all for review!

@dustymabe dustymabe deleted the init branch May 11, 2021 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants