Skip to content

Commit

Permalink
Merge pull request #387 from asteris-llc/feature/dont-render-module-deps
Browse files Browse the repository at this point in the history
Don't render module dependencies
  • Loading branch information
BrianHicks authored Oct 18, 2016
2 parents 12f2642 + 1c81189 commit b223b10
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ build

# docs
docs/extract
docs/converge
docs/resources.mk
docs/public

Expand Down
24 changes: 22 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TASKFILE=../resource/resource.go
TASKLOC=${TASKFILE}:\#$(shell grep -b 'type Task interface' ${TASKFILE} | cut -d: -f1)

public: content/*.md static/**/* content/resources content/license.md
public: content/*.md static/**/* content/resources content/license.md static/images/**/*.png
hugo

publish:
Expand Down Expand Up @@ -41,6 +41,26 @@ resources.mk: sources.csv resourceContent.mk.tmpl
-e "s|@@TARGET|content/resources/$$(echo $$line | cut -d, -f1 | tr -d '\n').md|g" \
resourceContent.mk.tmpl >> $@; \
echo >> $@; \
done
done

# Images

converge:
go build ..

static/images/dependencies/with-depends.png: static/images/dependencies/with-depends.hcl converge
./converge graph --local $< | dot -Tpng -o$@

static/images/dependencies/without-depends.png: static/images/dependencies/without-depends.hcl converge
./converge graph --local $< | dot -Tpng -o$@

static/images/getting-started/hello-world.png: static/images/getting-started/hello-world.hcl converge
./converge graph --local --show-params $< | dot -Tpng -o$@

static/images/getting-started/hello-world-params.png: static/images/getting-started/hello-world-params.hcl converge
./converge graph --local --show-params $< | dot -Tpng -o$@

static/images/getting-started/hello-you.png: static/images/getting-started/hello-you.hcl converge
./converge graph --local --show-params $< | dot -Tpng -o$@

.PHONY=publish
11 changes: 11 additions & 0 deletions docs/static/images/dependencies/with-depends.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
task "names" {
check = "test -d names"
apply = "mkdir names"
}

file.content "hello" {
destination = "names/hello.txt"
content = "Hello, World!"

depends = ["task.names"] # added in the resource that needs the dependency
}
Binary file modified docs/static/images/dependencies/with-depends.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/static/images/dependencies/without-depends.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
task "names" {
check = "test -d names"
apply = "mkdir names"
}

file.content "hello" {
destination = "names/hello.txt"
content = "Hello, World!"
}
Binary file modified docs/static/images/dependencies/without-depends.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/static/images/getting-started/hello-world-params.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
param "name" {
default = "World"
}

file.content "render" {
destination = "hello.txt"
content = "Hello, {{param `name`}}!"
}
Binary file modified docs/static/images/getting-started/hello-world-params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/static/images/getting-started/hello-world.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file.content "render" {
destination = "hello.txt"
content = "Hello, World!"
}
Binary file modified docs/static/images/getting-started/hello-world.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/static/images/getting-started/hello-you.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "hello-world-params.hcl" "hello" {
params {
name = "Spartacus"
}
}
Binary file modified docs/static/images/getting-started/hello-you.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/docker-swarm-mode/graphs/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/docker-swarm-mode/graphs/manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/docker-swarm-mode/graphs/worker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/elk/graphs/elk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion prettyprinters/graphviz/graphviz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/asteris-llc/converge/graph"
pp "github.com/asteris-llc/converge/prettyprinters"
"github.com/asteris-llc/converge/rpc/pb"
)

// SubgraphMarkerKey is a type alias for an integer and represents the state
Expand Down Expand Up @@ -221,9 +222,15 @@ func (p *Printer) DrawEdge(g *graph.Graph, id1, id2 string) (pp.Renderable, erro
attributes := p.printProvider.EdgeGetProperties(sourceEntity, destEntity)
maybeSetProperty(attributes, "label", escapeNewline(label))

srcVert, sok := srcVal.(*pb.GraphComponent_Vertex)
destVert, dok := destVal.(*pb.GraphComponent_Vertex)
if sok && dok && srcVert.Kind == "module" && destVert.Kind != "module" {
return pp.HiddenString(), nil
}

edgeStr := fmt.Sprintf("\"%s\" -> \"%s\" %s;\n",
escapeNewline(sourceVertex),
escapeNewline(destVertex),
escapeNewline(sourceVertex),
buildAttributeString(attributes),
)
visible := sourceVertex.Visible() && destVertex.Visible()
Expand Down
4 changes: 2 additions & 2 deletions prettyprinters/graphviz/graphviz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func Test_DrawEdge_SetsSourceAndDestVertexToSourceAndDest(t *testing.T) {
printer := graphviz.New(graphviz.DefaultOptions(), provider)
dotSource, _ := printer.DrawEdge(edgeTestGraph(), "A", "B")
sourceVertex, destVertex := parseDotEdge(dotSource)
assert.Equal(t, "A", sourceVertex)
assert.Equal(t, "B", destVertex)
assert.Equal(t, "B", sourceVertex)
assert.Equal(t, "A", destVertex)
}

func Test_DrawEdge_WhenFirstVertexIDReturnsError_ReturnsError(t *testing.T) {
Expand Down
47 changes: 45 additions & 2 deletions prettyprinters/graphviz/providers/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import (

pp "github.com/asteris-llc/converge/prettyprinters"
"github.com/asteris-llc/converge/prettyprinters/graphviz"
"github.com/asteris-llc/converge/resource/docker/container"
"github.com/asteris-llc/converge/resource/docker/image"
"github.com/asteris-llc/converge/resource/file/content"
"github.com/asteris-llc/converge/resource/file/directory"
"github.com/asteris-llc/converge/resource/param"
"github.com/asteris-llc/converge/resource/wait/port"
"github.com/asteris-llc/converge/rpc/pb"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -62,7 +66,8 @@ func (p RPCProvider) VertexGetLabel(e graphviz.GraphEntity) (pp.VisibleRenderabl
if e.Name == rootNodeID {
name = "/"
} else {
name = strings.Split(e.Name, "root/")[1]
parts := strings.Split(e.Name, "/")
name = parts[len(parts)-1]
}

val, ok := e.Value.(*pb.GraphComponent_Vertex)
Expand All @@ -79,6 +84,14 @@ func (p RPCProvider) VertexGetLabel(e graphviz.GraphEntity) (pp.VisibleRenderabl

return pp.VisibleString(fmt.Sprintf("File: %s", dest.Destination)), nil

case "file.directory":
var dest = new(directory.Directory)
if err := json.Unmarshal(val.Details, dest); err != nil {
return nil, errors.Wrap(err, "could not unmarshal directory")
}

return pp.VisibleString(fmt.Sprintf("Directory: %s", dest.Destination)), nil

case "module":
return pp.VisibleString(fmt.Sprintf("Module: %s", name)), nil

Expand All @@ -93,6 +106,30 @@ func (p RPCProvider) VertexGetLabel(e graphviz.GraphEntity) (pp.VisibleRenderabl
p.ShowParams,
), nil

case "docker.image":
var dest = new(image.Image)
if err := json.Unmarshal(val.Details, dest); err != nil {
return nil, errors.Wrap(err, "could not unmarshal docker image")
}

return pp.VisibleString(fmt.Sprintf("Docker Image: %s:%s", dest.Name, dest.Tag)), nil

case "docker.container":
var dest = new(container.Container)
if err := json.Unmarshal(val.Details, dest); err != nil {
return nil, errors.Wrap(err, "could not unmarshal docker container")
}

return pp.VisibleString(fmt.Sprintf("Docker Container: %s", dest.Name)), nil

case "wait.port":
var dest = new(port.Port)
if err := json.Unmarshal(val.Details, dest); err != nil {
return nil, errors.Wrap(err, "could not unmarshal docker port")
}

return pp.VisibleString(fmt.Sprintf("Wait: %s:%d", dest.Host, dest.Port)), nil

default:
return pp.VisibleString(name), nil
}
Expand All @@ -113,8 +150,14 @@ func (p RPCProvider) VertexGetProperties(e graphviz.GraphEntity) graphviz.Proper
case "task":
properties["shape"] = "component"

case "file.content":
case "file.content", "file.directory":
properties["shape"] = "tab"

case "module":
properties["shape"] = "folder"

case "docker.image", "docker.container":
properties["shape"] = "box3d"
}

return properties
Expand Down

0 comments on commit b223b10

Please sign in to comment.