Skip to content
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

Adds a process entry for all of the binaries #142

Merged
merged 3 commits into from
Feb 26, 2021
Merged

Conversation

ForestEckhardt
Copy link
Contributor

  • Every binary that is produced as part of the build process is now
    added to the process list with their type being their base binary name.

Resolves #139

Checklist

  • I have viewed, signed, and submitted the Contributor License Agreement.
  • I have linked issue(s) that this PR should close using keywords or the Github UI (See docs)
  • I have added an integration test, if necessary.
  • I have reviewed the styleguide for guidance on my code quality.

- Every binary that is produced as part of the build process is now
added to the process list with their type being thier base binary name.
@@ -94,22 +93,22 @@ func (p GoBuildProcess) Execute(config GoBuildConfiguration) (string, error) {
p.logs.Action("Failed after %s", duration.Round(time.Millisecond))
p.logs.Detail(buffer.String())

return "", fmt.Errorf("failed to execute 'go build': %w", err)
return nil, fmt.Errorf("failed to execute 'go build': %w", err)
}

p.logs.Action("Completed in %s", duration.Round(time.Millisecond))
p.logs.Break()

paths, err := filepath.Glob(fmt.Sprintf("%s/*", config.Output))

Choose a reason for hiding this comment

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

Now that the binaries are exposed as launch processes I think we need to provide the ability for buildpack consumers to control which one is the default process. I think the default process needs to be the first target listed in the BP_GO_TARGETS rather than just the first binary in the glob search. This decision is likely a breaking change since the buildpack today will select the first alphabetical globbed binary.

Copy link

@wburningham wburningham Feb 24, 2021

Choose a reason for hiding this comment

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

If I have

├── cmd
│   ├── one
│   │   └── main.go
│   └── two
│       └── main.go
├── go.mod
├── main.go

Then

BP_GO_TARGETS="./cmd/two:.:./cmd/one"
BP_GO_TARGETS=".:./cmd/one:./cmd/two"
BP_GO_TARGETS="./cmd/one:./cmd/two:."

should all provide a different default launch process

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I see what you mean. I will try and fix this up.

Copy link
Contributor Author

@ForestEckhardt ForestEckhardt Feb 25, 2021

Choose a reason for hiding this comment

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

@wburningham Alright after some fettling, I have managed to get all of the paths in order of appearance meaning the first target's binary should be the default process type. Take a look and see if that works for you.

"command": command,
}

command, ok := targetsLayer.Metadata["command"].(string)

Choose a reason for hiding this comment

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

@ForestEckhardt do you know why this code existed before or when you could ever get into the failure case where command would not be defined as a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use to reuse the binary layer from cache if nothing changed workspace directory. We no longer do that and always rebuild from source. This was metadata that we used to rewrite the start command on a rebuild where we reused the binary layer. That functionality has been removed so this is just dead code.

- This is so that we can obtain the binaries names in the order of the
targets that were passed to the build command. This is to ensure that we
set the correct default start command that is for the binary produced
from the first target.
return nil, fmt.Errorf("failed to parse 'go list' output: %w", err)
}

paths = append(paths, filepath.Join(config.Output, filepath.Base(list.ImportPath)))

Choose a reason for hiding this comment

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

Small optional microoptimization: Since the length of paths will be the length of config.Target, you can initialize path with a length of len(config.Targets and use path[i] = filepath.Join(config.Output, filepath.Base(list.ImportPath)) rather than append (which might have to grow).

@wburningham
Copy link

@ForestEckhardt LGTM 👍

@ryanmoran ryanmoran merged commit b904b3f into main Feb 26, 2021
@ryanmoran ryanmoran deleted the multi-process-writing branch February 26, 2021 00:19
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.

Feature: register all build targets as launch processes
3 participants