-
Notifications
You must be signed in to change notification settings - Fork 0
fix: stacker convert should check if FROMAS base is in current build #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "path/filepath" | ||
| "regexp" | ||
| "runtime" | ||
| "slices" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
|
|
@@ -72,6 +73,8 @@ type Command struct { | |
| Value []string // The contents of the command (ex: `ubuntu:xenial`) | ||
| } | ||
|
|
||
| var buildstages []string | ||
|
|
||
| func (c *Converter) convertCommand(cmd *Command) error { | ||
| var layer *types.Layer | ||
| if c.currLayer != "" { | ||
|
|
@@ -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") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tells me that Stacker does not support |
||
| 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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you looked into enabling this flag versus setting I'm wondering if setting |
||
| } else { | ||
| return errors.Errorf("unsupported FROM directive") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this tells me the |
||
| } | ||
| 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] | ||
| } | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works for parsing Does Stacker handle multi-platform image references? If so, we should handle that use-case here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest |
||
| } | ||
|
|
||
| // Do conversion | ||
| for _, child := range res.AST.Children { | ||
| cmd := Command{ | ||
| Cmd: child.Value, | ||
|
|
||
There was a problem hiding this comment.
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 intoconvertCommand()instead as an argument?