Skip to content

Commit

Permalink
pass dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-codefresh committed Oct 18, 2023
1 parent 5ad33ef commit 0629d5c
Showing 8 changed files with 678 additions and 494 deletions.
17 changes: 17 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
@@ -5019,6 +5019,23 @@
"appVersion": {
"type": "string",
"title": "Application version presented by single value"
},
"dependencies": {
"$ref": "#/definitions/repositoryDependencies"
}
}
},
"repositoryDependencies": {
"type": "object",
"properties": {
"Deps": {
"type": "string"
},
"Lock": {
"type": "string"
},
"Requirements": {
"type": "string"
}
}
},
364 changes: 60 additions & 304 deletions pkg/apiclient/events/events.pb.go

Large diffs are not rendered by default.

694 changes: 520 additions & 174 deletions reposerver/apiclient/repository.pb.go

Large diffs are not rendered by default.

72 changes: 67 additions & 5 deletions reposerver/repository/app_version.go
Original file line number Diff line number Diff line change
@@ -3,13 +3,44 @@ package repository
import (
"fmt"
"os"
"path/filepath"
"strings"

"gopkg.in/yaml.v2"
"k8s.io/client-go/util/jsonpath"
)

func getValueFromYAMLByJSONPath(appPath, jsonPathExpression string) (*string, error) {
type DependenciesMap struct {
Lock string `json:"helm/Chart.lock"`
Deps string `json:"helm/dependencies"`
Requirements string `json:"helm/requirements.yaml"`
}

type Result struct {
AppVersion string `json:"appVersion"`
Dependencies DependenciesMap `json:"dependencies"`
}

func getDependenciesFromChart(appPath string) (*string, error) {
content, err := os.ReadFile(appPath)
if err != nil {
return nil, err
}

var obj map[interface{}]interface{}
if err := yaml.Unmarshal(content, &obj); err != nil {
return nil, err
}

dependencies, err := yaml.Marshal(&map[interface{}]interface{}{"dependencies": obj["dependencies"]})
if err != nil {
return nil, err
}
dependenciesStr := string(dependencies)
return &dependenciesStr, nil
}

func getVersionFromYaml(appPath, jsonPathExpression string) (*string, error) {
content, err := os.ReadFile(appPath)
if err != nil {
return nil, err
@@ -54,13 +85,44 @@ func convertToJSONCompatible(i interface{}) (interface{}, error) {
return obj, nil
}

func getAppVersion(appPath string, resourceName string, jsonPathExpression string) (*string, error) {
value, err := getValueFromYAMLByJSONPath(appPath+"/"+resourceName, jsonPathExpression)
func getAppVersions(appPath string, resourceName string, jsonPathExpression string) (*Result, error) {
// Defaults
if resourceName == "" {
resourceName = "Chart.yaml"
}
if jsonPathExpression == "" {
jsonPathExpression = "{.appVersion}"
}

// Get version of root
appVersion, err := getVersionFromYaml(filepath.Join(appPath, resourceName), jsonPathExpression)
if err != nil {
return nil, err
}
fmt.Printf("appVersion value: %v\n", *appVersion)

fmt.Printf("appVersion value: %v\n", *value)
result := &Result{
AppVersion: *appVersion,
Dependencies: DependenciesMap{},
}

// Get Chart.lock if exists
lock, err := os.ReadFile(filepath.Join(appPath, "Chart.lock"))
if err == nil && lock != nil {
result.Dependencies.Lock = string(lock)
}

// Get `dependencies` property from Chart.yaml if exists
deps, err := getDependenciesFromChart(filepath.Join(appPath, resourceName))
if err == nil && deps != nil {
result.Dependencies.Deps = *deps
}

// Get requirements.yaml if exists
requirements, err := os.ReadFile(filepath.Join(appPath, "requirements.yaml"))
if err == nil && requirements != nil {
result.Dependencies.Requirements = string(requirements)
}

return value, nil
return result, nil
}
9 changes: 7 additions & 2 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
@@ -1416,12 +1416,17 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
SourceType: string(appSourceType),
}

appVersion, err := getAppVersion(appPath, q.VersionConfig.ResourceName, q.VersionConfig.JsonPath)
appVersions, err := getAppVersions(appPath, q.VersionConfig.ResourceName, q.VersionConfig.JsonPath)
if err != nil {
log.Errorf("failed to retrieve application version, app name: %q: %s", q.AppName, err.Error())
} else {
res.ApplicationVersions = &apiclient.ApplicationVersions{
AppVersion: *appVersion,
AppVersion: appVersions.AppVersion,
Dependencies: &apiclient.Dependencies{
Lock: appVersions.Dependencies.Lock,
Deps: appVersions.Dependencies.Deps,
Requirements: appVersions.Dependencies.Requirements,
},
}
}

7 changes: 7 additions & 0 deletions reposerver/repository/repository.proto
Original file line number Diff line number Diff line change
@@ -99,9 +99,16 @@ message Manifest {
int32 line = 4;
}

message Dependencies {
string Lock = 1;
string Deps = 2;
string Requirements = 3;
}

message ApplicationVersions {
// Application version presented by single value
string appVersion = 1;
Dependencies dependencies = 2;
}

message ManifestResponse {
1 change: 0 additions & 1 deletion server/application/application_event_reporter.go
Original file line number Diff line number Diff line change
@@ -703,7 +703,6 @@ func (s *applicationEventReporter) getApplicationEventPayload(
Cluster: a.Spec.Destination.Server,
AppInstanceLabelKey: appInstanceLabelKey,
TrackingMethod: string(trackingMethod),
AppVersions: nil,
}

payload := events.EventPayload{
8 changes: 0 additions & 8 deletions server/application/events.proto
Original file line number Diff line number Diff line change
@@ -51,13 +51,6 @@ message EventPayload {
repeated ObjectError errors = 4;
}

/**
* Application versions
*/
message AppVersions {
optional string appVersion = 1 [(gogoproto.nullable) = false];
}

/**
* Holds information about the object source
*/
@@ -85,7 +78,6 @@ message ObjectSource {
optional string appNamespace = 21 [(gogoproto.nullable) = false];
optional string appInstanceLabelKey = 22 [(gogoproto.nullable) = false];
optional string trackingMethod = 23 [(gogoproto.nullable) = false];
optional AppVersions appVersions = 24;
}

/**

0 comments on commit 0629d5c

Please sign in to comment.