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

Add build command #13

Merged
merged 6 commits into from
Jul 4, 2018
Merged

Add build command #13

merged 6 commits into from
Jul 4, 2018

Conversation

marcomorain
Copy link
Contributor

Port the majority of the current bash script that runs the existing CLI tool.

The allows people to run circleci build locally using the new CLI.

@marcomorain marcomorain requested a review from zzak July 4, 2018 14:47
@marcomorain marcomorain force-pushed the refactor-common-code branch 2 times, most recently from 15af7f2 to 94e21c9 Compare July 4, 2018 14:54
Port the majority of the current bash script that runs the existing CLI tool.

The allows people to run `circleci build` locally using the new CLI.
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Suggestion for testing, support overriding the image version from an env var. Then call it with a shim image that write args to a file. That way you can just assert the args are as expected, and you know all the code ran as expected.

cmd/build.go Outdated
func newBuildCommand() *cobra.Command {

command := &cobra.Command{
Use: "build",
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this command is still running a job (not a full build) I've been wondering if we should rename it to either run or job run. We can always add build as an alias for backwards compatbility.

cmd/build.go Outdated
*/

flags := command.Flags()
flags.StringVarP(&dockerAPIVersion, "docker-api-version", "d", dockerAPIVersion, "The Docker API version to use")
Copy link
Contributor

@dnephin dnephin Jul 4, 2018

Choose a reason for hiding this comment

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

I don't think you want to duplicate all the flags here. There is a better way!

One option is to use flags.SetIntersperced(false) https://godoc.org/github.com/spf13/pflag#SetInterspersed. That way any flags after a positional argument (or a --) are kept in Args. It might also work for any not recognized flags, I don't remember. If that doesn't work I would just omit flgs all together and pass all the args along.

You're already appending args so that should be it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sweet, that will make things easier 👌

cmd/build.go Outdated
// Otherwise pulling latest image in background
// TODO - this should write to a file to record
// the fact that we have the latest image.
newPullLatestImageCommand().Start()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should reconsider this "pull latest in background on every run". I think it's unexpected behaviour and not a good user experience. This is Windows Updates.

Instead I think we could provide a subcommand to update it.

cmd/build.go Outdated

// TODO: marc:
// I can't find a way to pass `-it` and have carriage return
// characters work correctly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Because you are setting stdout to a pipe, which is not a tty. You could use a pty, but I think there is a better option.

Instead of fork/exec, why not just exec (https://golang.org/pkg/syscall/#Exec)? That way you don't need to stream output (not sure how that works on windows). Alternatively just set Stdout/Stderr to os.Stdout/os.Stderr, which also fixes the tty issue and removes the need to stream output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea. We will need to do something else on Windows I imagine?

Copy link
Contributor

@dnephin dnephin Jul 4, 2018

Choose a reason for hiding this comment

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

Ya, I think there will be other problems with windows as well. I don't think bind mounting /var/run/docker.sock works, because it uses a named pipe if I remember correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 781bebe

cmd/build.go Outdated
// I can't find a way to pass `-it` and have carriage return
// characters work correctly.
arguments := []string{"run", "--rm",
"-e", fmt.Sprintf("DOCKER_API_VERSION=%s", dockerAPIVersion),
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be a flag. Use -e DOCKER_API_VERSION and it will use the value from cmd.Env, which defaults to os.Environ() which is exactly what you want I think.

This replaces the current process with the spawn process, simplifying everything.
@ndintenfass
Copy link
Contributor

:thatmotivatesme:

@codecov-io
Copy link

codecov-io commented Jul 4, 2018

Codecov Report

Merging #13 into master will increase coverage by 17.21%.
The diff coverage is 15.44%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #13       +/-   ##
===========================================
+ Coverage   22.13%   39.34%   +17.21%     
===========================================
  Files           9       10        +1     
  Lines         488      615      +127     
===========================================
+ Hits          108      242      +134     
+ Misses        366      357        -9     
- Partials       14       16        +2
Impacted Files Coverage Δ
cmd/config.go 46.93% <ø> (+46.93%) ⬆️
cmd/configure.go 13.69% <0%> (+13.69%) ⬆️
cmd/build.go 14.17% <14.17%> (ø)
cmd/root.go 74.5% <75%> (+52.5%) ⬆️
cmd/diagnostic.go 27.27% <0%> (+27.27%) ⬆️
cmd/orb.go 28.81% <0%> (+28.81%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fa5416...5d55e9c. Read the comment docs.

@marcomorain marcomorain merged commit feadf79 into master Jul 4, 2018
@marcomorain marcomorain deleted the refactor-common-code branch July 4, 2018 23:28
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.

5 participants