Skip to content

Commit

Permalink
feat: make variant in pkg.yaml explicit
Browse files Browse the repository at this point in the history
Fixes #183

Note: this is a breaking change.

Also highlight alpine variant in the graph.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Jan 31, 2025
1 parent d978bcc commit 4a79aeb
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: final
variant: alpine
dependencies:
# this arm64 variant of the image only contains the u-boot binary,
# so this is a good test to ensure that we can copy the binary from
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: final
variant: alpine
steps:
- test:
- test "${BUILD:-x}" = "aarch64-linux-musl"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: check-cache
variant: alpine
dependencies:
- stage: fill-cache
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: fill-cache
variant: alpine
steps:
- cachePaths:
- /.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: final
variant: scratch
dependencies:
- stage: onlyarm
platform: linux/arm64
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: onlyarm
variant: alpine
steps:
- test:
- test "${BUILD:-x}" = "aarch64-linux-musl"
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/integration/testdata/simple/go/pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: go
variant: alpine
steps:
- sources:
- url: https://dl.google.com/go/go1.12.5.src.tar.gz
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/integration/testdata/stages/final/pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: final
variant: alpine
dependencies:
- stage: stage-a
- stage: stage-b
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/integration/testdata/stages/stage-a/pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: stage-a
variant: alpine
steps:
- prepare:
- mkdir -p /root
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/integration/testdata/stages/stage-b/pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: stage-b
variant: alpine
steps:
- prepare:
- mkdir -p /root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: stage-c
variant: alpine
steps:
- prepare:
- mkdir -p /root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: stage-d
variant: alpine
dependencies:
- stage: stage-c
steps:
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/integration/testdata/variables/final/pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: final
variant: alpine
dependencies:
- stage: global-vars
- stage: std-vars
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: global-vars
variant: alpine
steps:
- prepare:
- mkdir -p /root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: local-vars
variant: alpine
steps:
- prepare:
- mkdir -p /root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: override
variant: alpine
steps:
- prepare:
- mkdir -p /root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: std-vars
variant: alpine
steps:
-
prepare:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: vars-yaml-inner
variant: alpine
steps:
-
prepare:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: vars-yaml-0
variant: alpine
dependencies:
- stage: vars-yaml-inner
from: /result
Expand Down
16 changes: 15 additions & 1 deletion internal/pkg/solver/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package solver

import (
"fmt"
"strings"

"github.com/emicklei/dot"

Expand Down Expand Up @@ -41,7 +42,11 @@ func (node *PackageNode) DumpDot(g *dot.Graph) dot.Node {
if dep.IsInternal() {
depNode = g.Node(dep.Stage)
} else {
depNode = g.Node(dep.Image)
imageRef := dep.Image
// cut the digest
imageRef, _, _ = strings.Cut(imageRef, "@")

depNode = g.Node(imageRef)
depNode.Box()
depNode.Attr("fillcolor", "lemonchiffon")
depNode.Attr("style", "filled")
Expand All @@ -55,6 +60,15 @@ func (node *PackageNode) DumpDot(g *dot.Graph) dot.Node {
}
}

if node.Pkg.Variant == v1alpha2.Alpine {
packageNode := g.Node("alpine")
packageNode.Box()
packageNode.Attr("fillcolor", "aquamarine")
packageNode.Attr("style", "filled")

packageNode.Edge(n)
}

for _, dep := range node.Pkg.Install {
packageNode := g.Node("Alpine: " + dep)
packageNode.Box()
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/types/v1alpha2/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func NewPkg(baseDir, fileName string, contents []byte, vars types.Variables) (*P
BaseDir: baseDir,
FileName: fileName,
Shell: "/bin/sh",
Variant: Alpine,
Context: vars.Copy(),
}

Expand Down Expand Up @@ -72,6 +71,10 @@ func (p *Pkg) Validate() error {
multiErr = multierror.Append(multiErr, errors.New("package name can't be empty"))
}

if p.Variant == Unset {
multiErr = multierror.Append(multiErr, errors.New("variant should be set"))
}

if len(p.Steps) > 0 && len(p.Finalize) == 0 {
multiErr = multierror.Append(multiErr, errors.New("finalize steps are missing, this is going to lead to empty build"))
}
Expand Down
6 changes: 4 additions & 2 deletions internal/pkg/types/v1alpha2/variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import "fmt"
type Variant int

const (
// Unset is a variant that is not set.
Unset Variant = iota
// Alpine variant uses Alpine as base image for the build.
Alpine Variant = iota
Alpine
// Scratch variant uses scratch image as base image for the build.
Scratch
)

func (v Variant) String() string {
return []string{"alpine", "scratch"}[v]
return []string{"unset", "alpine", "scratch"}[v]
}

// UnmarshalYAML implements yaml.Unmarshaller interface.
Expand Down

0 comments on commit 4a79aeb

Please sign in to comment.