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

Porter explain warns for docker host access #1868

Conversation

joshuabezaleel
Copy link
Contributor

What does this change

When the bundle has docker as one of the required mixins, porter explain command warns for the host access in advance and also include --allow-docker-host-access flag for the installation command at the end.

I attached the screenshot for running the porter explain command for the tabbycat-demo bundle with docker added as one of the required mixins and also for the whalesay bundle.
image

What issue does it fix

Closes #1830

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our [Contributors][contributors] list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Can you also add a test case for the warning that should appear when the bundle requires the docker extension? Here's where we have a similar test already:

func TestExplain_generateTable(t *testing.T) {


// Check whether the bundle requires docker mixin and warn for host access.
var requireDocker bool = false
for _, mixin := range bun.Mixins {
Copy link
Member

Choose a reason for hiding this comment

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

Using the docker mixin isn't the problem we need to warn about. What we are looking for is when a bundle declares that it requires docker host access:

https://porter.sh/author-bundles/#required

required:
  - docker # this says inject the docker socket into the bundle

The preferred way to check for that is with bun.SupportsX, like bun.SupportsFileParameters, which checks if a CNAB required extension is defined on the bundle. There should be a function named bun.SupportsDocker but I guess that function never made.

It should look like this:

func SupportsParameterSources(b bundle.Bundle) bool {

which should be added to https://github.com/getporter/porter/blob/main/pkg/cnab/extensions/docker.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just realized that I didn't stumble upon this one since the directory of pkg/cnab/extensions doesn't exist on release/v1 branch but only exists on main branch. Does this mean that the PR for this particular issue should be made upon the main branch?

Copy link
Member

Choose a reason for hiding this comment

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

Oops, sorry I shouldn't have linked to the main branch. This PR should target release/v1 but the code that I wanted to show you as an example moved a bit:

func (b ExtendedBundle) SupportsParameterSources() bool {
return b.SupportsExtension(ParameterSourcesExtensionKey)
}
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Edited, thank you so much for the guidance, Carolyn! 😄

@joshuabezaleel
Copy link
Contributor Author

@carolynvs Also I found this particular TODO line while working on this issue. Does this mean that we have to address this before v1.0? And if the answer to the previous question is yes, do we already have a corresponding issue for this one?

https://github.com/getporter/porter/blob/release/v1/pkg/cnab/file_parameter.go#L39-L42

@joshuabezaleel
Copy link
Contributor Author

Wait why can't my link for line of code on GitHub be rendered as a snippet like yours 🤔

@joshuabezaleel joshuabezaleel force-pushed the 1830-porter-explain-warn-docker-host-access branch from d7e8c5f to 9a21508 Compare February 9, 2022 14:32
@carolynvs
Copy link
Member

Also I found this particular TODO line while working on this issue. Does this mean that we have to address this before v1.0? And if the answer to the previous question is yes, do we already have a corresponding issue for this one?

oof, that is a good question. If we removed that and relied 100% on if the bundle says that it supports file parameters, then old bundles would stop working in porter v1.0.0. I don't really see a good reason to do that, and it's just a single line to keep around to keep old bundles working. We should just remove that todo and not remove that line of code.

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

This looks great! I just had some small suggestions. Once the unit tests are passing (there's a build failure in the tests), this is ready to go! 🚀

fmt.Fprintf(p.Out, "porter install%s%s%s\n", bundleReferenceFlag, requiredParameterFlags, credentialFlags)
porterInstallCommand := fmt.Sprintf("porter install%s%s%s", bundleReferenceFlag, requiredParameterFlags, credentialFlags)

// Check whether the bundle requires docker mixin and add flag for host access for install command.
Copy link
Member

Choose a reason for hiding this comment

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

This comment is a bit misleading since we aren't checking for the docker mixin, but if the bundle requires the docker socket to be mounted into the bundle.

err = p.printBundleExplain(opts, pb, b)
assert.NoError(t, err)
gotOutput := p.TestConfig.TestContext.GetOutput()
expected, err := ioutil.ReadFile("testdata/explain/expected-table-output-docker.txt")
Copy link
Member

Choose a reason for hiding this comment

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

We have a test helper that makes it easier to compare command output with the contents of a file and keep it in sync when the command output changes.

import "get.porter.sh/porter/pkg/test"

test.CompareGoldenFile(t, "testdata/explain/expected-table-output-docker.txt", gotOutput)

If you run mage updateTestFiles it will find any tests whose output has changed and updates the testdata file automatically so the test passes.

We aren't using that new helper function everywhere in Porter yet, but I'd like new tests to use it so they are easier to maintain.

@carolynvs carolynvs self-assigned this Feb 20, 2022
@joshuabezaleel joshuabezaleel force-pushed the 1830-porter-explain-warn-docker-host-access branch 2 times, most recently from 93fc135 to cc5b376 Compare February 21, 2022 15:42
…is docker as one of the required mixins in the bundle

Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
@joshuabezaleel joshuabezaleel force-pushed the 1830-porter-explain-warn-docker-host-access branch from da29fba to b794ac2 Compare February 21, 2022 15:56
@joshuabezaleel
Copy link
Contributor Author

@carolynvs Sorry for the failing test, my bad. Should be all green by now. Thank you Carolyn! 😄

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

I love all the improvements to porter explain! It really makes it a much better experience for new users and helping them learn how to use bundles. 👍

@carolynvs carolynvs merged commit d18c5c5 into getporter:release/v1 Feb 22, 2022
@joshuabezaleel
Copy link
Contributor Author

joshuabezaleel commented Feb 23, 2022

I really hope the explain command along with its updates will come useful for people using it! 😄

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.

None yet

2 participants