Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkg/stacker/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -72,6 +73,8 @@ type Command struct {
Value []string // The contents of the command (ex: `ubuntu:xenial`)
}

var buildstages []string

Comment on lines +76 to +77

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if creating a new package-level variable is appropriate here. Perhaps create a local variable in parseFile() and pass it into convertCommand() instead as an argument?

func (c *Converter) convertCommand(cmd *Command) error {
var layer *types.Layer
if c.currLayer != "" {
Expand All @@ -90,13 +93,22 @@ func (c *Converter) convertCommand(cmd *Command) error {
c.subs["IMAGE"] = "app"
} else if len(cmd.Value) == 3 && strings.EqualFold(cmd.Value[1], "as") {

@jsatterfield-geico jsatterfield-geico Jul 28, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells me that Stacker does not support --platform <platform> in FROM, so maybe you don't need to support it yet.

c.currLayer = cmd.Value[2]

// Check if the base stage is in a build stage
if slices.Contains(buildstages, cmd.Value[0]) {
layer.From.Type = "built"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a raw string, I would use the Stacker-defined type: https://github.com/project-stacker/stacker/blob/main/pkg/types/layer.go#L25

layer.From.Tag = cmd.Value[0]
}
// layer.BuildOnly = true // FIXME: should be enabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you looked into enabling this flag versus setting layer.From? Is there a difference between the two? Just wondering because this comment implies that they do keep track of these "build-only" stages using this flag.

I'm wondering if setting layer.From directly maybe bypasses some of that logic?

} else {
return errors.Errorf("unsupported FROM directive")

@jsatterfield-geico jsatterfield-geico Jul 28, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this tells me the --platform <platform> would be outright rejected. Please close the other two comments as resolved...

}
if !strings.EqualFold(cmd.Value[0], "scratch") {
layer.From.Type = "docker"
layer.From.Url = fmt.Sprintf("docker://%s", cmd.Value[0])
// Have we seen this...
if layer.From.Type != "built" {
layer.From.Type = "docker"
layer.From.Url = fmt.Sprintf("docker://%s", cmd.Value[0])
}
} else {
layer.From.Type = cmd.Value[0]
}
Expand Down Expand Up @@ -309,6 +321,15 @@ func (c *Converter) parseFile() error {
return err
}

// Collect all possible build stages before starting conversion.
for _, child := range res.AST.Children {
fields := strings.Fields(child.Original)
if fields[0] == "FROM" && len(fields) == 4 {
buildstages = append(buildstages, fields[3])
}
Comment on lines +327 to +329

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for parsing FROM <image> AS <name>, but FROM --platform=<platform> <image> AS <name> is equally valid. https://docs.docker.com/reference/dockerfile/#from

Does Stacker handle multi-platform image references? If so, we should handle that use-case here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest len(fields) > 4 and fields[len(fields) - 1] which should cover both.

}

// Do conversion
for _, child := range res.AST.Children {
cmd := Command{
Cmd: child.Value,
Expand Down
Loading