Skip to content

Commit

Permalink
Add provided node
Browse files Browse the repository at this point in the history
  • Loading branch information
keimoon committed Dec 28, 2017
1 parent 2652176 commit f7373db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Check https://github.com/anduintransaction/doriath/releases
```yaml
root_dir: .
build:
- name: "ubuntu"
tag: "16.04"
from: "provided"
- name: "human/aragorn"
from: "./human/aragorn"
tag: "1.2.0"
Expand All @@ -30,6 +33,7 @@ build:
- name: "elf/elrond"
from: "./elf/elrond"
tag: "2.1.0"
depend: "ubuntu"
credentials:
- name: dockerhub
username: "$YOUR_USERNAME"
Expand Down
18 changes: 14 additions & 4 deletions buildtree/buildtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func readBuildTree(fileContent []byte) (*BuildTree, error) {
for _, buildNodeConfig := range buildConfig.Build {
node := &buildNode{
buildRoot: utils.ResolveDir(buildConfig.RootDir, buildNodeConfig.From),
name: buildNodeConfig.Name,
name: utils.FormatDockerName(buildNodeConfig.Name),
tag: buildNodeConfig.Tag,
depend: buildNodeConfig.Depend,
depend: utils.FormatDockerName(buildNodeConfig.Depend),
children: []*buildNode{},
dirty: false,
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (t *BuildTree) assertDockerfile(node *buildNode) error {
if err != nil {
return err
}
if node.depend != imageInfo.FullName {
if !utils.CompareDockerName(node.depend, imageInfo.FullName) {
return stacktrace.NewError("Mismatch dependency for %q: %q in config but got %q in dockerfile", node.name, node.depend, imageInfo.FullName)
}
parentTag := t.allNodes[node.depend].tag
Expand All @@ -248,14 +248,20 @@ func (t *BuildTree) dirtyCheck(node *buildNode, parentIsDirty bool) error {
if err != nil {
return err
}
if parentIsDirty {
if t.isProvided(node) {
if !tagExists {
return stacktrace.NewError("Cannot find tag %q for provided image %q", node.tag, node.name)
}
node.dirty = false
} else if parentIsDirty {
node.dirty = true
if tagExists {
return stacktrace.NewError("Image needs to be updated but still using old tag: %s", node.name)
}
} else {
node.dirty = !tagExists
}

for _, child := range node.children {
err = t.dirtyCheck(child, node.dirty)
if err != nil {
Expand All @@ -265,6 +271,10 @@ func (t *BuildTree) dirtyCheck(node *buildNode, parentIsDirty bool) error {
return nil
}

func (t *BuildTree) isProvided(node *buildNode) bool {
return node.buildRoot == "provided"
}

func (t *BuildTree) buildNodeAndChildren(node *buildNode) error {
if !node.dirty {
fmt.Printf("====> Skipping %s\n", node.name)
Expand Down
2 changes: 1 addition & 1 deletion utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Version returns doriath version
func Version() string {
return "1.1.1"
return "1.2.0"
}

// ResolveDir appends a path to a rootDir
Expand Down
17 changes: 17 additions & 0 deletions utils/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ type dockerAuthInfo struct {
scope string
}

// FormatDockerName adds library/ if possible
func FormatDockerName(name string) string {
if name == "" {
return name
}
segments := strings.Split(name, "/")
if len(segments) == 1 {
return "library/" + name
}
return name
}

// CompareDockerName compares 2 docker image names
func CompareDockerName(a, b string) bool {
return strings.TrimPrefix(a, "library/") == strings.TrimPrefix(b, "library/")
}

// ExtractDockerImageInfo extracts docker image info
func ExtractDockerImageInfo(fullnameWithTag string) (*DockerImageInfo, error) {
imageInfo := &DockerImageInfo{}
Expand Down

0 comments on commit f7373db

Please sign in to comment.