Skip to content

WIP: Add containerRunOptions, add support for privielged, mounts and#82

Closed
mogthesprog wants to merge 1 commit into
GoogleContainerTools:masterfrom
mogthesprog:mogthesprog/container-run-opts
Closed

WIP: Add containerRunOptions, add support for privielged, mounts and#82
mogthesprog wants to merge 1 commit into
GoogleContainerTools:masterfrom
mogthesprog:mogthesprog/container-run-opts

Conversation

@mogthesprog

Copy link
Copy Markdown

covering some of the changes discussed in #70

@nkubala

I'm still working on this, but it's coming together a bit now. Apologies for the delay, had some issue getting the tests to run on OS X.

If you've got feedback on what i've got so far that'd be great. I'll add some comments where i've got questions too.

Comment thread tests/debian_test.yaml
@@ -1,4 +1,14 @@
schemaVersion: '2.0.0' # Make sure to test the latest schema version

driver: "docker"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've added this, but i'm not sure how we should handle this in code.

It feels to me like this should be the default, and overridable by the command line flag. Let me know your thoughts on how to proceed with this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Currently, the driver gets passed in as a CLI flag and then instantiated here: https://github.com/GoogleCloudPlatform/container-structure-test/blob/master/structure_test.go#L111

Instead, that will have to happen in the Parse() method, similar to how the schemaVersion gets parsed out of the config file: https://github.com/GoogleCloudPlatform/container-structure-test/blob/master/structure_test.go#L80

You should still be able to reuse the logic for InitDriverImpl here.

Comment thread tests/debian_test.yaml
args:
- "-d"
- "/tmp/test"
exitCode: 0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I had to test this using the command module, since it looks like the fileExistenceTests only work on the image content. Hopefully this is all fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I totally understand, can you explain a little more what you're actually testing here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I had tested this using the fileExistenceTests, but the test was failing. I think that's because the fileExistenceTests don't run inside the running container, but on the underlying image data? (maybe i've misunderstood).

So instead, I use the command module and run test -d /tmp/test which i've added as a bindMount. This tests that a file exists at path /tmp/test and that it's of type directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah right, so the whole idea of this framework is that nothing happens inside the "running container": a new container is created from the base image on each test, as a way to isolate the testing environment. When you make changes through Setup command for example, those get made on a running container and then committed to a new image which is used as the base image for all subsequent tests.

The idea here is that you'll want to treat your runOpts as a sort of setup, that gets run before any of the tests get run, and then committed to a new image. Then you should be able to use the fileExistence tests to test this as normal. Does that make sense?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, I think i understand what you mean. I'm not sure this can work with docker though.

Mounting volumes is something that happens at container creation time, and you can't commit their contents along with an image layer commit. The same goes for the privileged boolean and capabilities.

The idea here is if i wanted to bootstrap an airflow test (for instance), I might want to mount in a test configuration in order to run the command tests. This was one example of a use case of ours.

What shall we do about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah ok, I see what you mean.

In that case, I think we'll need to just pass the runOpts anytime we create a container in the docker driver (e.g. here). We'll need to just be careful to pass it everywhere since we can't commit this as the "base image".

One idea would be to make the runOpts a subset of the Config struct that gets passed around in the client library we're using: then you could just have a method that creates a Config with the values in the runOpts, and use that where ever we're called CreateContainer().

Comment thread types/v2/structure.go Outdated
FileContentTests []FileContentTest `yaml:"fileContentTests"`
MetadataTest MetadataTest `yaml:"metadataTest"`
LicenseTests []LicenseTest `yaml:"licenseTests"`
Driver string `yaml:"driver"`

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Again, as above. While i've added this. I'm not sure what to do with it now that it's there. Let me know, and i'll make the required changes :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You actually probably don't want to put this here. Check out the example I linked above for the schemaVersion, it should look very similar to that 👍

Comment thread tests/debian_test.yaml

containerRunOpts:
bindMounts:
- "/tmp/test:/tmp/test"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've actually been thinking about this overnight...

I'm wondering whether we should support environment variable interpolation here. Because Docker requires absolute paths. So being able to interpolate a ~ or $PWD would be really useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, yeah I see what you mean. In order to do that we'd need to first parse the config, then somehow retrieve the env from the image, and then substitute that into a new config before running the tests. This is probably doable, but might get tricky especially if we're not using docker. Feel free and give it a shot though, I'd like to see what it looks like

@nkubala nkubala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is definitely looking like the right shape. Check out the inline comments I made, hopefully those should point you in the right direction. Let me know if you have other questions!

@mogthesprog mogthesprog force-pushed the mogthesprog/container-run-opts branch 3 times, most recently from a835611 to 44581ec Compare March 26, 2018 20:03
@mogthesprog

Copy link
Copy Markdown
Author

@nkubala

Hey man. I've rebased against the cobra changes (much better after that :)) Any chance you could take another look?

@mogthesprog

mogthesprog commented Mar 27, 2018

Copy link
Copy Markdown
Author

Just noticed this is failing, any ideas why?

When i run locally by just compiling and running the code against the tests i get no failures. However if i run the bazel then i get the following, which i think is related to me running on a Mac.

standard_init_linux.go:195: exec user process caused "exec format error"

I figured i wouldn't get this in the CI. Any ideas on how i can debug this?

@nkubala nkubala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mogthesprog getting real close, thanks for the work on this. Currently Bazel's cross compilation is broken, so if you're trying to run the normal bazel build on a Mac it won't work. I think you can change your platform with the --cpu flag and it should work, but I wouldn't worry too much about it. You can build with make locally and test that way.

CI is failing with

FATA[0000] Unsupported driver type:  

though, looks like you need to provide the default driver somewhere.

Comment thread cmd/test.go Outdated
return nil, errors.New("Please provide JSON schema version")
}

// We

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

something missing here? :)

Comment thread cmd/test.go Outdated
}
logrus.Infof("Using driver %s\n", driver)
return driverImpl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove newline

@nkubala

nkubala commented May 21, 2018

Copy link
Copy Markdown
Contributor

@mogthesprog any updates here? This is looking pretty close, could you rebase?

@nkubala

nkubala commented Dec 4, 2018

Copy link
Copy Markdown
Contributor

hey @mogthesprog, this PR has been inactive for 6 months now, so I'm going to close it. Please reopen if and when you start working on this again!

@nkubala nkubala closed this Dec 4, 2018
@vishalsangave

Copy link
Copy Markdown

This will be a good feature to be have as some configuration files are needed to be mapped with the container to work correctly. Can we check on this request.

@fentonfentonfenton

Copy link
Copy Markdown

+1

loosebazooka pushed a commit that referenced this pull request Mar 15, 2023
* add containerRunOptions

* largely picked up from #82, add privileged, capabilities and host
  volume mounts. these are passed into HostConfig if set
* added "user" field which corresponds -u/--user arg in docker

wasn't tested for other drivers and more tests likely needed

* rename 16.04 tests, pull test image

* additional options, update docs

* update deps

* github.com/containerd/containerd - resolve CVE-2022-23471,
  CVE-2023-25153 & CVE-2023-25173
* golang.org/x/net - resolve CVE-2022-41717
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.

4 participants