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

Added squash flag & associated fixes #24

Merged
merged 1 commit into from
Aug 3, 2017

Conversation

rgee0
Copy link
Contributor

@rgee0 rgee0 commented Aug 2, 2017

Signed-off-by: rgee0 richard@technologee.co.uk

Main Change:

Added a -squash flag to address #23.
Fixed issue where supplying -no-cache flag would cause builds to fail
Changed http_proxy test to include a test for https_proxy (typo in the OR)
Refactored the generation of the build string to alleviate need for multiple operations in a proxy environment.... Previously the builder var would be initialised once outside the proxy test and then reassigned within the proxy test with additional params. By buffering the docker build flags throughout the flag checks we can then just initialise builder once post-checks with code as succinct as the original initialisation.
EDIT Added a function buildFlagString to build the build flags string, as suggested.

Test:

Pre:
On Master ran ./faas-cli -action build -yaml ./samples.yml -no-cache
and confirmed bug:
docker build --no-cache-t alexellis2/faas-urlping .
unknown flag: --no-cache-t

Post:
Ran ./faas-cli -action build -yaml ./samples.yml
and confirmed the command run was docker build -t alexellis2/faas-urlping .
Ran ./faas-cli -action build -yaml ./samples.yml -no-cache
and confirmed the command run was docker build --no-cache -t alexellis2/faas-urlping .
Ran ./faas-cli -action build -yaml ./samples.yml -squash
and confirmed the command run was docker build --squash -t alexellis2/faas-urlping .
Ran ./faas-cli -action build -yaml ./samples.yml -no-cache -squash
and confirmed the command run was docker build --no-cache --squash -t alexellis2/faas-urlping .

Also tested -flag=true & -flag=false and confirmed expected outcomes.

Misc:

Used git commit -s as per the contribution guide

@alexellis
Copy link
Member

Refactored the generation of the build string to alleviate need for multiple operations in a proxy environment.

Can you be specific about this?

app.go Outdated

switch language {
case "node", "python":
tempPath := createBuildTemplate(functionName, handler, language)

fmt.Printf("Building: %s with Docker. Please wait..\n", image)

cacheFlag := ""
//lets create a buffer for any build flags
var flagBuf bytes.Buffer
Copy link
Member

Choose a reason for hiding this comment

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

Could this be a string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could. What I've read though suggests that using byte buffer is better performance wise when there is any kind of variability in length - strings are immutable. Less of a consideration with 3 functions and four concats per function, granted, but I'd hope users would be using the CLI for batching many more functions.

Copy link
Member

Choose a reason for hiding this comment

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

I thought that would be the thinking. This code is building a very short string so I think I prefer the string concatenation and readability.

Copy link
Member

Choose a reason for hiding this comment

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

We should probably extract a method to generate this string (whether it uses a buffer internally or a string) so it can be unit tested.

@alexellis
Copy link
Member

Squashing looks good - just a couple of questions/comments.

@rgee0
Copy link
Contributor Author

rgee0 commented Aug 2, 2017

Updated the original main change section with further detail about the builder refactor

app.go Outdated
if len(os.Getenv("http_proxy")) > 0 || len(os.Getenv("http_proxy")) > 0 {
builder = strings.Split(fmt.Sprintf("docker build %s--build-arg http_proxy=%s --build-arg https_proxy=%s -t %s .", cacheFlag, os.Getenv("http_proxy"), os.Getenv("https_proxy"), image), " ")
if len(os.Getenv("http_proxy")) > 0 || len(os.Getenv("https_proxy")) > 0 {
flagBuf.WriteString("--build-arg http_proxy=" + os.Getenv("http_proxy") + " ")
Copy link
Member

@alexellis alexellis Aug 2, 2017

Choose a reason for hiding this comment

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

Should this be changed to sprintf since we are concatenating strings here and in other places use fmt.Sprintf? Maybe we should also do separate checks to output http_proxy / https_proxy separately

Copy link
Contributor Author

@rgee0 rgee0 Aug 2, 2017

Choose a reason for hiding this comment

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

Well, ultimately, yes, now that we have to go back to strings.

Yes, we could split out the checks, now that they are checking different things.

app.go Outdated
}

builder := strings.Split(fmt.Sprintf("docker build %s-t %s .", flagBuf.String(), image), " ")
fmt.Println(strings.Join(builder, " "))
Copy link
Contributor Author

@rgee0 rgee0 Aug 2, 2017

Choose a reason for hiding this comment

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

Whats the idea here? Seems to split on spaces then join with spaces?

@rgee0
Copy link
Contributor Author

rgee0 commented Aug 2, 2017

Made changes as discussed, committed, squashed and pushed.

Signed-off-by: rgee0 <richard@technologee.co.uk>
@alexellis alexellis merged commit 8a12387 into openfaas:master Aug 3, 2017
@alexellis
Copy link
Member

Looks very clean and concise. Merged.

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.

2 participants