CI: Refactor versions.go (#55238)

* Refactor versions.go

* s/ReleaseModeConfig/BuildConfig
This commit is contained in:
Dimitris Sotirakis
2022-09-16 06:26:33 -04:00
committed by GitHub
parent e4741ce8d6
commit 95512c19e0
8 changed files with 82 additions and 41 deletions
+8
View File
@@ -40,3 +40,11 @@ type LibC string
const (
LibCMusl = "musl"
)
// Distribution is the base os image where the Grafana image is built on.
type Distribution string
const (
Ubuntu Distribution = "ubuntu"
Alpine Distribution = "alpine"
)
+20 -15
View File
@@ -29,33 +29,38 @@ type PluginSignature struct {
type Docker struct {
ShouldSave bool `json:"shouldSave,omitempty"`
Distribution []Distribution `json:"distribution,omitempty"`
Architectures []Architecture `json:"archs,omitempty"`
}
// Version represents the "version.json" that defines all of the different variables used to build Grafana
type Version struct {
Variants []Variant `json:"variants,omitempty"`
PluginSignature PluginSignature `json:"pluginSignature,omitempty"`
Docker Docker `json:"docker,omitempty"`
PackagesBucket string `json:"packagesBucket,omitempty"`
PackagesBucketEnterprise2 string `json:"packagesBucketEnterprise2,omitempty"`
CDNAssetsBucket string `json:"CDNAssetsBucket,omitempty"`
CDNAssetsDir string `json:"CDNAssetsDir,omitempty"`
StorybookBucket string `json:"storybookBucket,omitempty"`
StorybookSrcDir string `json:"storybookSrcDir,omitempty"`
type Buckets struct {
Artifacts string `json:"artifacts,omitempty"`
ArtifactsEnterprise2 string `json:"artifactsEnterprise2,omitempty"`
CDNAssets string `json:"CDNAssets,omitempty"`
CDNAssetsDir string `json:"CDNAssetsDir,omitempty"`
Storybook string `json:"storybook,omitempty"`
StorybookSrcDir string `json:"storybookSrcDir,omitempty"`
}
// BuildConfig represents the struct that defines all of the different variables used to build Grafana
type BuildConfig struct {
Variants []Variant `json:"variants,omitempty"`
PluginSignature PluginSignature `json:"pluginSignature,omitempty"`
Docker Docker `json:"docker,omitempty"`
Buckets Buckets `json:"buckets,omitempty"`
}
func (md *Metadata) GetReleaseMode() (ReleaseMode, error) {
return md.ReleaseMode, nil
}
// Versions is a map of versions. Each key of the Versions map is an event that uses the the config as the value for that key.
// VersionMap is a map of versions. Each key of the Versions map is an event that uses the the config as the value for that key.
// For example, the 'pull_request' key will have data in it that might cause Grafana to be built differently in a pull request,
// than the way it will be built in 'main'
type VersionMap map[VersionMode]Version
type VersionMap map[VersionMode]BuildConfig
// GetVersions reads the embedded config.json and decodes it.
func GetVersion(mode VersionMode) (*Version, error) {
// GetBuildConfig reads the embedded config.json and decodes it.
func GetBuildConfig(mode VersionMode) (*BuildConfig, error) {
if v, ok := Versions[mode]; ok {
return &v, nil
}
+42 -14
View File
@@ -17,6 +17,9 @@ var Versions = VersionMap{
Architectures: []Architecture{
ArchAMD64,
},
Distribution: []Distribution{
Alpine,
},
},
},
MainMode: {
@@ -42,10 +45,16 @@ var Versions = VersionMap{
ArchARM64,
ArchARMv7, // GOARCH=ARM is used for both armv6 and armv7. They are differentiated by the GOARM variable.
},
Distribution: []Distribution{
Alpine,
Ubuntu,
},
},
Buckets: Buckets{
Artifacts: "grafana-downloads",
ArtifactsEnterprise2: "grafana-downloads-enterprise2",
CDNAssets: "grafana-static-assets",
},
PackagesBucket: "grafana-downloads",
PackagesBucketEnterprise2: "grafana-downloads-enterprise2",
CDNAssetsBucket: "grafana-static-assets",
},
CustomMode: {
Variants: []Variant{
@@ -70,10 +79,16 @@ var Versions = VersionMap{
ArchARM64,
ArchARMv7, // GOARCH=ARM is used for both armv6 and armv7. They are differentiated by the GOARM variable.
},
Distribution: []Distribution{
Alpine,
Ubuntu,
},
},
Buckets: Buckets{
Artifacts: "grafana-downloads",
ArtifactsEnterprise2: "grafana-downloads-enterprise2",
CDNAssets: "grafana-static-assets",
},
PackagesBucket: "grafana-downloads",
PackagesBucketEnterprise2: "grafana-downloads-enterprise2",
CDNAssetsBucket: "grafana-static-assets",
},
ReleaseBranchMode: {
Variants: []Variant{
@@ -98,10 +113,16 @@ var Versions = VersionMap{
ArchARM64,
ArchARMv7,
},
Distribution: []Distribution{
Alpine,
Ubuntu,
},
},
Buckets: Buckets{
Artifacts: "grafana-downloads",
ArtifactsEnterprise2: "grafana-downloads-enterprise2",
CDNAssets: "grafana-static-assets",
},
PackagesBucket: "grafana-downloads",
PackagesBucketEnterprise2: "grafana-downloads-enterprise2",
CDNAssetsBucket: "grafana-static-assets",
},
TagMode: {
Variants: []Variant{
@@ -126,11 +147,18 @@ var Versions = VersionMap{
ArchARM64,
ArchARMv7,
},
Distribution: []Distribution{
Alpine,
Ubuntu,
},
},
Buckets: Buckets{
Artifacts: "grafana-prerelease/artifacts/downloads",
ArtifactsEnterprise2: "grafana-prerelease/artifacts/downloads-enterprise2",
CDNAssets: "grafana-prerelease",
CDNAssetsDir: "artifacts/static-assets",
Storybook: "grafana-prerelease",
StorybookSrcDir: "artifacts/storybook",
},
PackagesBucket: "grafana-prerelease/artifacts/downloads",
CDNAssetsBucket: "grafana-prerelease",
CDNAssetsDir: "artifacts/static-assets",
StorybookBucket: "grafana-prerelease",
StorybookSrcDir: "artifacts/storybook",
},
}