WIP: Add containerRunOptions, add support for privielged, mounts and#82
WIP: Add containerRunOptions, add support for privielged, mounts and#82mogthesprog wants to merge 1 commit into
Conversation
| @@ -1,4 +1,14 @@ | |||
| schemaVersion: '2.0.0' # Make sure to test the latest schema version | |||
|
|
|||
| driver: "docker" | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| args: | ||
| - "-d" | ||
| - "/tmp/test" | ||
| exitCode: 0 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'm not sure I totally understand, can you explain a little more what you're actually testing here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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().
| FileContentTests []FileContentTest `yaml:"fileContentTests"` | ||
| MetadataTest MetadataTest `yaml:"metadataTest"` | ||
| LicenseTests []LicenseTest `yaml:"licenseTests"` | ||
| Driver string `yaml:"driver"` |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 👍
|
|
||
| containerRunOpts: | ||
| bindMounts: | ||
| - "/tmp/test:/tmp/test" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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!
a835611 to
44581ec
Compare
|
Hey man. I've rebased against the cobra changes (much better after that :)) Any chance you could take another look? |
|
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. I figured i wouldn't get this in the CI. Any ideas on how i can debug this? |
nkubala
left a comment
There was a problem hiding this comment.
@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.
| return nil, errors.New("Please provide JSON schema version") | ||
| } | ||
|
|
||
| // We |
There was a problem hiding this comment.
something missing here? :)
| } | ||
| logrus.Infof("Using driver %s\n", driver) | ||
| return driverImpl | ||
|
|
44581ec to
b24f34b
Compare
|
@mogthesprog any updates here? This is looking pretty close, could you rebase? |
|
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! |
|
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. |
|
+1 |
* 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
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.