Skip to content

Commit

Permalink
Merge pull request #507 from MUzairS15/MUzairS15/artifacthub-pkg
Browse files Browse the repository at this point in the history
Add support for generating pkg file.
  • Loading branch information
MUzairS15 committed Jun 12, 2024
2 parents 93397db + 66d0e5c commit 202100b
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 8 deletions.
2 changes: 1 addition & 1 deletion helpers/component_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "meshkit",
"type": "library",
"next_error_code": 11243
"next_error_code": 11245
}
2 changes: 1 addition & 1 deletion models/meshmodel/entity/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
ErrUpdateEntityStatusCode = ""
ErrUpdateEntityStatusCode = "meshkit-11243"
)

func ErrUpdateEntityStatus(err error, entity string, status EntityStatus) error {
Expand Down
2 changes: 1 addition & 1 deletion models/meshmodel/registry/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var (
ErrUnknownHostCode = "meshkit-11146"
ErrRegisterEntityCode = ""
ErrRegisterEntityCode = "meshkit-11244"
)

func ErrUnknownHost(err error) error {
Expand Down
42 changes: 42 additions & 0 deletions utils/archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package utils

import (
"archive/tar"
"bytes"
)

type TarWriter struct {
Writer *tar.Writer
Buffer *bytes.Buffer
}

func NewTarWriter() *TarWriter {
buffer := bytes.Buffer{}
return &TarWriter{
Writer: tar.NewWriter(&buffer),
Buffer: &buffer,
}
}

func (tw *TarWriter) Compress(name string, data []byte) error {
header := tar.Header{
Name: name,
Size: int64(len(data)),
Mode: 777,
}
err := tw.Writer.WriteHeader(&header)
if err != nil {
return ErrCompressToTarGZ(err, "")
}

_, err = tw.Writer.Write(data)
if err != nil {
return ErrCompressToTarGZ(err, "")
}
return nil
}

func (tw *TarWriter) Close() {
_ = tw.Writer.Flush()
_ = tw.Writer.Close()
}
69 changes: 69 additions & 0 deletions utils/catalog/artifacthub_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package catalog

type ContainersImage struct {
Name string `yaml:"name,omitempty"`
Image string `yaml:"image,omitempty"`
Whitelisted string `yaml:"whitelisted,omitempty"`
}

type Link struct {
Name string `yaml:"name,omitempty"`
URL string `yaml:"url,omitempty"`
}

type Change struct {
Kind string `yaml:"kind,omitempty"`
Description string `yaml:"description,omitempty"`
Links []Link `yaml:"links,omitempty"`
}

type Maintainer struct {
Name string `yaml:"name,omitempty"`
Email string `yaml:"email,omitempty"`
}

type Provider struct {
Name string `yaml:"name,omitempty"`
}

type Recommendation struct {
URL string `yaml:"url,omitempty"`
}

type Screenshot struct {
Title string `yaml:"title,omitempty"`
URL string `yaml:"url,omitempty"`
}

type ArtifactHubMetadata struct {
Version string `yaml:"version,omitempty"`
Name string `yaml:"name,omitempty"`
DisplayName string `yaml:"displayName,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty"`
Description string `yaml:"description,omitempty"`
LogoPath string `yaml:"logoPath,omitempty"`
LogoURL string `yaml:"logoURL,omitempty"`
Digest string `yaml:"digest,omitempty"`
License string `yaml:"license,omitempty"`
HomeURL string `yaml:"homeURL,omitempty"`
AppVersion string `yaml:"appVersion,omitempty"`
ContainersImages []ContainersImage `yaml:"containersImages,omitempty"`
ContainsSecurityUpdates string `yaml:"containsSecurityUpdates,omitempty"`
Operator string `yaml:"operator,omitempty"`
Deprecated string `yaml:"deprecated,omitempty"`
Prerelease string `yaml:"prerelease,omitempty"`
Keywords []string `yaml:"keywords,omitempty"`
Links []Link `yaml:"links,omitempty"`
Readme string `yaml:"readme,omitempty"`
Install string `yaml:"install,omitempty"`
Changes []Change `yaml:"changes,omitempty"`
Maintainers []Maintainer `yaml:"maintainers,omitempty"`
Provider Provider `yaml:"provider,omitempty"`
Ignore []string `yaml:"ignore,omitempty"`
Recommendations []Recommendation `yaml:"recommendations,omitempty"`
Screenshots []Screenshot `yaml:"screenshots,omitempty"`
Annotations struct {
Key1 string `yaml:"key1,omitempty"`
Key2 string `yaml:"key2,omitempty"`
} `yaml:"annotations,omitempty"`
}
55 changes: 55 additions & 0 deletions utils/catalog/package.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package catalog

import (
"fmt"

"github.com/layer5io/meshkit/models/catalog/v1beta1"
)

func BuildArtifactHubPkg(name, downloadURL, user, version, createdAt string, catalogData *v1beta1.CatalogData) *ArtifactHubMetadata {
artifacthubPkg := &ArtifactHubMetadata{
Name: name,
Description: catalogData.PatternInfo,
Provider: Provider{
Name: user,
},
Links: []Link{
{
Name: "download",
URL: downloadURL, // this depends on where the design is stored by the user, we can give remote provider URL otherwise
},
{
Name: "Meshery Catalog",
URL: "https://meshery.io/catalog",
},
},
HomeURL: "https://docs.meshery.io/concepts/logical/designs",
Version: version,
CreatedAt: createdAt,
License: "Apache-2.0",
LogoURL: "https://raw.githubusercontent.com/meshery/meshery.io/0b8585231c6e2b3251d38f749259360491c9ee6b/assets/images/brand/meshery-logo.svg",
Install: "mesheryctl design import -f",
Readme: fmt.Sprintf("%s \n ##h4 Caveats and Consideration \n", catalogData.PatternCaveats),
}

if len(catalogData.SnapshotURL) > 0 {
artifacthubPkg.Screenshots = append(artifacthubPkg.Screenshots, Screenshot{
Title: "MeshMap Snapshot",
URL: catalogData.SnapshotURL[0],
})

if len(catalogData.SnapshotURL) > 1 {
artifacthubPkg.Screenshots = append(artifacthubPkg.Screenshots, Screenshot{
Title: "MeshMap Snapshot",
URL: catalogData.SnapshotURL[1],
})
}
}

artifacthubPkg.Screenshots = append(artifacthubPkg.Screenshots, Screenshot{
Title: "Meshery Project",
URL: "https://raw.githubusercontent.com/meshery/meshery.io/master/assets/images/logos/meshery-gradient.png",
})

return artifacthubPkg
}
16 changes: 11 additions & 5 deletions utils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ var (
ErrCreateDirCode = "meshkit-11182"
// ErrDecodeYamlCode represents the error which is generated when yaml
// decode process fails
ErrDecodeYamlCode = "meshkit-11183"
ErrExtractTarXZCode = "meshkit-11184"
ErrExtractZipCode = "meshkit-11185"
ErrReadDirCode = "meshkit-11186"
ErrDecodeYamlCode = "meshkit-11183"
ErrExtractTarXZCode = "meshkit-11184"
ErrExtractZipCode = "meshkit-11185"
ErrReadDirCode = "meshkit-11186"
ErrCompressToTarGZCode = "meshkit-11248"
)

func ErrCueLookup(err error) error {
Expand Down Expand Up @@ -146,6 +147,11 @@ func ErrDecodeYaml(err error) error {
return errors.New(ErrDecodeYamlCode, errors.Alert, []string{"Error occurred while decoding YAML"}, []string{err.Error()}, []string{}, []string{})
}

// ErrCompressTar is the error for zipping a file into targz
func ErrCompressToTarGZ(err error, path string) error {
return errors.New(ErrCompressToTarGZCode, errors.Alert, []string{fmt.Sprintf("Error while compressing file %s", path)}, []string{err.Error()}, []string{"The file might be corrupt", "Insufficient permissions to read the file"}, []string{"Verify sufficient read permissions"})
}

// ErrExtractTarXVZ is the error for unzipping the targz file
func ErrExtractTarXZ(err error, path string) error {
return errors.New(ErrExtractTarXZCode, errors.Alert, []string{fmt.Sprintf("Error while extracting file at %s", path)}, []string{err.Error()}, []string{"The gzip might be corrupt"}, []string{})
Expand All @@ -158,4 +164,4 @@ func ErrExtractZip(err error, path string) error {

func ErrReadDir(err error, dirPath string) error {
return errors.New(ErrReadDirCode, errors.Alert, []string{"error reading directory"}, []string{err.Error()}, []string{fmt.Sprintf("Directory does not exist at the location %s", dirPath), "Insufficient permissions"}, []string{"Verify that directory exist at the provided location", "Verify sufficient directory read permission."})
}
}

0 comments on commit 202100b

Please sign in to comment.