ソースを参照

graph per release

sunguroku 5 年 前
コミット
8ee2294c52

+ 32 - 0
.goreleaser.yml

@@ -0,0 +1,32 @@
+before:
+  hooks:
+    - go mod download
+builds:
+  - id: "porter-cli"
+    env:
+      - CGO_ENABLED=1
+    dir: cli
+    main: ./cli/main.go
+    goos:
+      - linux
+      - windows
+      - darwin
+    flags:
+      - -tags=cli
+archives:
+  - replacements:
+      darwin: Darwin
+      linux: Linux
+      windows: Windows
+      386: i386
+      amd64: x86_64
+checksum:
+  name_template: 'checksums.txt'
+snapshot:
+  name_template: "{{ .Tag }}-next"
+changelog:
+  sort: asc
+  filters:
+    exclude:
+      - '^docs:'
+      - '^test:'

+ 2 - 0
dashboard/src/main/home/dashboard/expanded-chart/ExpandedChart.tsx

@@ -74,11 +74,13 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
 
   renderTabContents = () => {
     let { currentChart, refreshChart, setSidebar} = this.props;
+    
     if (this.state.currentTab === 'graph') {
       return (
         <GraphSection
           components={this.state.components}
           currentChartName={currentChart.name}
+          currentChartVersion={currentChart.version}
           setSidebar={setSidebar}
         />
       );

+ 2 - 0
dashboard/src/main/home/dashboard/expanded-chart/GraphSection.tsx

@@ -10,6 +10,7 @@ import Loading from '../../../../components/Loading';
 type PropsType = {
   components: ResourceType[],
   currentChartName: string,
+  currentChartVersion: number,
   setSidebar: (x: boolean) => void
 };
 
@@ -30,6 +31,7 @@ export default class GraphSection extends Component<PropsType, StateType> {
           components={this.props.components}
           isExpanded={this.state.isExpanded}
           currentChartName={this.props.currentChartName}
+          currentChartVersion={this.props.currentChartVersion}
         />
       );
     }

+ 12 - 5
dashboard/src/main/home/dashboard/expanded-chart/graph/GraphDisplay.tsx

@@ -15,7 +15,8 @@ type PropsType = {
   components: ResourceType[],
   isExpanded: boolean,
   setSidebar: (x: boolean) => void,
-  currentChartName: string
+  currentChartName: string,
+  currentChartVersion: number
 };
 
 type StateType = {
@@ -100,8 +101,7 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
     // Suppress trackpad gestures
     this.spaceRef.addEventListener("touchmove", (e: any) => e.preventDefault());
     this.spaceRef.addEventListener("mousewheel", (e: any) => e.preventDefault());
-
-    let graph = localStorage.getItem(`charts.${this.props.currentChartName}`)
+    let graph = localStorage.getItem(`charts.${this.props.currentChartName}-${this.props.currentChartVersion}`)
     let nodes = [] as NodeType[]
     let edges = [] as EdgeType[]
 
@@ -110,7 +110,10 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
       edges = this.createEdges(components)
       this.setState({ nodes, edges });
     } else {
-      let storedState = JSON.parse(localStorage.getItem(`charts.${this.props.currentChartName}`))
+      let storedState = JSON.parse(localStorage.getItem(
+        `charts.${this.props.currentChartName}-${this.props.currentChartVersion}`
+        )
+      )
       this.setState(storedState);
     }
 
@@ -175,7 +178,11 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
     graph.suppressDisplay = false;
     graph.suppressCloseNode = false;
 
-    localStorage.setItem(`charts.${this.props.currentChartName}`, JSON.stringify(graph))
+    localStorage.setItem(
+      `charts.${this.props.currentChartName}-${this.props.currentChartVersion}`, 
+      JSON.stringify(graph)
+    )
+    
     this.spaceRef.removeEventListener("touchmove", (e: any) => e.preventDefault());
     this.spaceRef.removeEventListener("mousewheel", (e: any) => e.preventDefault());
     document.removeEventListener("keydown", this.handleKeyDown);

+ 12 - 1
docs/DEVELOPING.md

@@ -14,4 +14,15 @@ From the root directory, run `go test ./...` to run all tests and ensure the bui
 
 From the root directory, run `DOCKER_BUILDKIT=1 docker build . --file ./docker/Dockerfile -t porter`. Then you can run `docker run -p 8080:8080 porter`. 
 
-To build the test container, run `DOCKER_BUILDKIT=1 docker build . --file ./docker/Dockerfile -t porter-test --target porter-test`. 
+To build the test container, run `DOCKER_BUILDKIT=1 docker build . --file ./docker/Dockerfile -t porter-test --target porter-test`. 
+
+### CLI Release
+
+```sh
+docker run --rm --privileged \
+-v $PWD:/go/src/github.com/porter-dev/porter \
+-v /var/run/docker.sock:/var/run/docker.sock \
+-w /go/src/github.com/porter-dev/porter \
+-e GORELEASER_GITHUB_TOKEN='THEGITHUBTOKEN' \
+mailchain/goreleaser-xcgo ""
+```

+ 0 - 2
go.mod

@@ -30,7 +30,6 @@ require (
 	github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd
 	github.com/json-iterator/go v1.1.10 // indirect
 	github.com/kr/pretty v0.2.0 // indirect
-	github.com/leodido/go-urn v1.2.0 // indirect
 	github.com/mattn/go-colorable v0.1.7 // indirect
 	github.com/pelletier/go-toml v1.8.1 // indirect
 	github.com/pkg/errors v0.9.1
@@ -58,7 +57,6 @@ require (
 	k8s.io/client-go v0.18.8
 	k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac // indirect
 	k8s.io/helm v2.16.12+incompatible
-	k8s.io/klog v1.0.0 // indirect
 	k8s.io/klog/v2 v2.2.0 // indirect
 	k8s.io/utils v0.0.0-20200912215256-4140de9c8800 // indirect
 	sigs.k8s.io/structured-merge-diff/v4 v4.0.1 // indirect

+ 15 - 5
internal/helm/grapher/object.go

@@ -16,25 +16,35 @@ func ParseObjs(objs []map[string]interface{}) []Object {
 	objArr := []Object{}
 
 	for i, obj := range objs {
-		kind := getField(obj, "kind").(string)
-		name := getField(obj, "metadata", "name").(string)
+		kind := getField(obj, "kind")
 
+		// ignore block comments
+		if kind == nil {
+			continue
+		}
+
+		name := getField(obj, "metadata", "name")
 		namespace := getField(obj, "metadata", "namespace")
 
 		if namespace == nil {
-			namespace = ""
+			namespace = "default"
+		}
+
+		if name == nil {
+			name = ""
 		}
 
 		// First add the object that appears on the YAML
 		parsedObj := Object{
 			ID:        i,
-			Kind:      kind,
-			Name:      name,
+			Kind:      kind.(string),
+			Name:      name.(string),
 			Namespace: namespace.(string),
 			RawYAML:   obj,
 			Relations: Relations{
 				ControlRels: []ControlRel{},
 				LabelRels:   []LabelRel{},
+				SpecRels:    []SpecRel{},
 			},
 		}
 		objArr = append(objArr, parsedObj)

+ 14 - 5
internal/helm/grapher/relation.go

@@ -64,15 +64,24 @@ func (parsed *ParsedObjs) GetControlRel() {
 	children := []Object{}
 	for i, obj := range parsed.Objects {
 		yaml := obj.RawYAML
+		kind := getField(yaml, "kind")
 
-		switch kind := getField(yaml, "kind").(string); kind {
+		if kind == nil {
+			kind = ""
+		}
+
+		switch kind.(string) {
 		// Parse for all possible controller types
 		case "Deployment", "StatefulSet", "ReplicaSet", "DaemonSet", "Job":
 			rs := getField(yaml, "spec", "replicas")
 
 			if rs != nil && rs.(int) > 0 {
 				// Add Pods for controller objects
-				template := getField(yaml, "spec", "template").(map[string]interface{})
+				template := getField(yaml, "spec", "template")
+				if template == nil {
+					continue
+				}
+
 				for j := 0; j < rs.(int); j++ {
 					cid := len(parsed.Objects) + len(children)
 					crel := ControlRel{
@@ -88,7 +97,7 @@ func (parsed *ParsedObjs) GetControlRel() {
 						Kind:      "Pod",
 						Name:      obj.Name + "-" + strconv.Itoa(j), // tentative name pre-deploy
 						Namespace: obj.Namespace,
-						RawYAML:   template,
+						RawYAML:   template.(map[string]interface{}),
 						Relations: Relations{
 							ControlRels: []ControlRel{
 								crel,
@@ -287,8 +296,8 @@ func (parsed *ParsedObjs) findRBACTargets(parentID int, yaml map[string]interfac
 			}
 
 			// first consider case of targets added via subjects, which are namespace scoped.
-			if tr["namespace"] != nil && o.Kind == tr["kind"] &&
-				o.Name == tr["name"] && (o.Namespace == tr["namespace"] || o.Namespace == "default") {
+			if tr["namespace"] != nil && o.Kind == tr["kind"] && o.Name == tr["name"] &&
+				(o.Namespace == tr["namespace"] || o.Namespace == "default") {
 
 				// Add bidirectional link from children as well.
 				parsed.Objects[i].Relations.SpecRels = append(parsed.Objects[i].Relations.SpecRels, newrel)