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

Remove master.zip file after building function with faas-cli build #66

Merged
merged 1 commit into from
Sep 22, 2017

Conversation

ericstoekl
Copy link
Contributor

@ericstoekl ericstoekl commented Sep 3, 2017

This change will remove the master.zip file after the fetchTemplates() function is done creating the templates from the downloaded zip file.

Description

Use the os.Remove() function to remove the zip file, whose name is now stored in a const variable, after making sure that the zip file is still present with os.Stat()

Motivation and Context

  • I have raised an issue to propose this change (required)
    Noticed the zip file hanging around, was confused as to its necessity to remain the directory. However, as long as the templates directory is present in your YAML build file location, the master.zip file will not be used. Therefore, it is not necessary to keep it around.

How Has This Been Tested?

Tried building the node, python, csharp, ruby, and Dockerfile templates, and checked that the master.zip file was removed, but the function worked when deployed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

It looks like the CI build is broken.. @ems5311 please can you take a look?

Would be great if you can squash these commits into one (also)

return err
}

func fetchMasterZip() error {
var err error
if _, err = os.Stat("master.zip"); err != nil {
err = nil
Copy link
Member

Choose a reason for hiding this comment

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

What's happening there? If there is an error you're ignoring 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.

That err variable is being set to nil because after we find that there is an error, we load the master.zip file location from the templateUrl environment variable, or if that env variable does not exist, we grab it from github. The error variable is not needed here, in fact it is a bug if it is not reset to nil, because if you have templateURL env variable set because you intend to load the master.zip from an alternative location, as this test does, then the test will normally fail on "master.zip os.Stat method failed", because that method and set the err at line 67. Let me know if there is a better way. Thanks

@ericstoekl
Copy link
Contributor Author

The magic bytes used in Test_mockBuild() in build_test.go are the data that makes up the smallest possible zip file. Therefore, this will expand without errors when zip.OpenReader() runs on it. Although it will expand into nothing, it will enable the fetch functionality to be tested.

@alexellis
Copy link
Member

I thought that's what they were - so let's make the code self-documenting and use that variable name.

I still need to look at the os.Stat line as I'm still not clear why we're clearing the error.

Otherwise very excited to see these tests emerging.

@ericstoekl
Copy link
Contributor Author

ericstoekl commented Sep 4, 2017

I was wrong about the os.Stat line. The test works without that change, so I'll revert it.

Also I should be calling PullTemplates(), so the test function/filename should be renamed accordingly.

Edit: Just updated the code with a new commit. Let me know if it looks good, and I'll squash them (wanted to leave unsquashed for now so it's easy to see what was updated)

build.sh Outdated
@@ -5,3 +5,5 @@ docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_p
docker cp faas-cli:/root/faas-cli . && \
docker rm -f faas-cli

go test
go test ./commands
Copy link
Contributor

Choose a reason for hiding this comment

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

You can replace both commands with a single invocation:

go test ./...

@ericstoekl
Copy link
Contributor Author

Httptest mock server used in this changelist is a solution for issue #45

@alexellis
Copy link
Member

Once you've had a chance to read feedback and apply if necessary can you squash he commits please?

Thanks for this change. It will mean smaller git ignore files

@ericstoekl
Copy link
Contributor Author

Just squashed into a single commit. The feedback has been addressed.

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

// Write out the minimum number of bytes to make the response a valid .zip file
w.Write([]byte{80, 75, 05, 06, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00})
Copy link
Member

Choose a reason for hiding this comment

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

This is a magic variable. Please extract it and give it a name like smallest zip etc

Copy link
Member

Choose a reason for hiding this comment

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

@ems5311 where are we with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will make this change this evening.

}))
defer ts.Close()

os.Setenv("templateUrl", ts.URL)
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid using the environmental variable? Since this is now using httptest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to the 3rd party template issue, I can pass a variable to the PullTemplates() function

log.Printf("Writing %dKb to master.zip\n", len(bytesOut)/1024)
err = ioutil.WriteFile("./master.zip", bytesOut, 0700)
log.Printf("Writing %dKb to %s\n", len(bytesOut)/1024, ZipFileName)
err = ioutil.WriteFile(ZipFileName, bytesOut, 0700)
if err != nil {
log.Println(err.Error())
}
Copy link
Member

Choose a reason for hiding this comment

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

Please can you do one final new line print at the end of this function? It will separate the output when someone does new or build for the first time.

@ghost
Copy link

ghost commented Sep 14, 2017

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off.
That's something we need before your Pull Request can be merged. Please see our contributing guide.

@ghost ghost added the no-dco label Sep 14, 2017
@ericstoekl
Copy link
Contributor Author

Just pushed this update. I'm gonna need to rebase this if it looks good, but wanted it to be more clear for now.

"testing"
)

var SmallestZipFile = []byte{80, 75, 05, 06, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}
Copy link
Member

@alexellis alexellis Sep 15, 2017

Choose a reason for hiding this comment

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

Perfect, this is 10x better. It could start with small s so it's not exported too.

@alexellis
Copy link
Member

Hi Eric,

With the mantra of "Less is more":

I'm not sure we need keep-archive.. overwrite seems like a good idea. Let's get this finished and then I can merge?

@ericstoekl
Copy link
Contributor Author

keep-archive and overwrite are actually options for the add-template change, which is similar to this change but a completely separate issue. I'll update #87 with those suggestions.

I'll change the SmallestZipFile to smallestZipFile, then squash and we should be good to go with this one.

@ericstoekl
Copy link
Contributor Author

ericstoekl commented Sep 17, 2017

Closing this PR as #87 (with changes pending in my local branch) will supercede this PR. It will provide the same functionality along with the add-template function

@ericstoekl ericstoekl closed this Sep 17, 2017
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

I thought we were ready to merge this?

@ericstoekl
Copy link
Contributor Author

ericstoekl commented Sep 17, 2017 via email

@ghost ghost removed the no-dco label Sep 22, 2017
1. Remove master.zip after pulling template directory
2. Tests template fetch with mock HTTP server

Signed-off-by: Eric Stoekl <ems5311@gmail.com>
@alexellis alexellis merged commit db425d5 into openfaas:master Sep 22, 2017
@alexellis
Copy link
Member

Thank you for re-opening.

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