8000 Typed builder commands (updated) by simonferquel · Pull Request #5 · tonistiigi/docker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Typed builder commands (updated) #5

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

Open
wants to merge 17 commits into
base: typed-builder-commands-base
Choose a base branch
from

Conversation

simonferquel
Copy link

This the result of my workday, implementing feedback from #4.

Still have to rewrite equivalent tests, and to run the whole builder integration test suite, but I think it is much better

This is a work base to introduce more features like build time
dockerfile optimisations, dependency analysis and parallel build, as
well as a first step to go from a dispatch-inline process to a
frontend+backend process.

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
…spatch time

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
8000
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
@simonferquel
Copy link
Author

Especially the env var expansion is much easier to understand this way.

@tonistiigi tonistiigi mentioned this pull request Jun 1, 2017
@@ -0,0 +1,316 @@
package typedcommand
Copy link

Choose a reason for hiding this comment

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

In the docs we call these "instructions" not commands. It would be good to keep the terms consistent. Maybe we can name this package instructions ?

Copy link
Author

Choose a reason for hiding this comment

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

Ok !

return parseShell(newParseRequestFromNode(node))
}

buildsFailed.WithValues(metricsUnknownInstructionError).Inc()
Copy link
Owner

Choose a reason for hiding this comment

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

move this metrics to the caller package


func Parse(ast *parser.Node, targetStage string, buildsFailed metrics.LabeledCounter) (stages BuildableStages, metaArgs []ArgCommand, err error) {
for _, n := range ast.Children {
if n.Value == command.From && stages.IsCurrentStage(targetStage) {
Copy link
Owner

Choose a reason for hiding this comment

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

Parser pkg should not define stateful public functions like this. If you need helper functions that work on returned types, that is fine.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, Will move the "Tree shaking" on the caller site

return nil, fmt.Errorf("unknown instruction: %s", strings.ToUpper(node.Value))
}

func Parse(ast *parser.Node, targetStage string, buildsFailed metrics.LabeledCounter) (stages BuildableStages, metaArgs []ArgCommand, err error) {
Copy link
Owner

Choose a reason for hiding this comment

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

Either return stages slice or define a type that contains the args.

Copy link
Author

Choose a reason for hiding this comment

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

BuildableStages is a type alias for []BuildableStage with helper methods. Do you prefer explicit []BuildableStage return type and convertion of methods to free functions ?

}
switch c := cmd.(type) {
case *ArgCommand:
if len(stages) == 0 {
Copy link
Owner

Choose a reason for hiding this comment

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

This isn't very clear. You can just parse all args first. After that switch between from and any other command.

Copy link
Author

Choose a reason for hiding this comment

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

Ok

}

func ParseCommand(node *parser.Node, buildsFailed metrics.LabeledCounter) (interface{}, error) {
switch node.Value {
Copy link
Owner

Choose a reason for hiding this comment

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

make the request object before the switch for readability

sourceCode = src.SourceCode()
}
if len(parseResult) > 1 {
fmt.Fprintf(b.Stdout, "Stage %v: %v / %v %v", stage.Name, i+1, len(stage.Commands), sourceCode)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe avoid doing new logging output for now as it will likely change more in the future. No issue if it changes a bit just because the logic is different.

Copy link
Author

Choose a reason for hiding this comment

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

I made it so that it is clearer when I debugged multi-stage related issues. I'll rollback it

return "", errors.Errorf("invalid name for build stage: %q, name can't start with a number or contain symbols", stageName)
state := d.state
state.beginStage(cmd.StageName, image)
state.runConfig.OpenStdin = false
Copy link
Owner

Choose a reason for hiding this comment

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

this should be part of/called by beginStage

Copy link
Author

Choose a reason for hiding this comment

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

+1

return nil, err
runConfigEnv := d.state.runConfig.Env
envs := append(runConfigEnv, d.builder.buildArgs.FilterAllowed(runConfigEnv)...)
if ex, ok := cmd.(typedcommand.SupportsMultiWordExpansion); ok {
Copy link
Owner

Choose a reason for hiding this comment

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

As this is only allowed for expose, the expose dispatcher should just call this call this function.

Copy link
Author

Choose a reason for hiding this comment

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

+1

envs := append(runConfigEnv, d.builder.buildArgs.FilterAllowed(runConfigEnv)...)
if ex, ok := cmd.(typedcommand.SupportsMultiWordExpansion); ok {
ex.Expand(func(word string) ([]string, error) {
return d.shlex.ProcessWords(word, envs)
Copy link
Owner

Choose a reason for hiding this comment

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

Follow up: shlex could be removed from dispatchers.

Copy link
Author

Choose a reason for hiding this comment

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

This will be needed for "expose" special case and for "from" as well (from has a different buildargs handling than default)

case *typedcommand.StopSignalCommand:
return d.dispatchStopSignal(c)
case *typedcommand.ArgCommand:
if d.state.hasDispatchedFrom {
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't be required. "meta" should use a different path.

Copy link
Author

Choose a reason for hiding this comment

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

+1

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
… logic

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
…ildable stage

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0