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

GenericContainerBuilder false pull policy should not pull image #771

Merged
merged 5 commits into from
Jun 16, 2024

Conversation

schummar
Copy link
Contributor

@schummar schummar commented Jun 3, 2024

Small issue I found by accident. Instead of this.pullPolicy the check should be this.pullPolicy.shouldPull().
The cleanOpts part makes sure that configs with undefined value are not included in the request - it caused issues for me.

Copy link

netlify bot commented Jun 3, 2024

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 9706aaa
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-node/deploys/666d740626692a00083674ea
😎 Deploy Preview https://deploy-preview-771--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@schummar schummar changed the title Fix/pull policy fix: pull policy in GenericContainerBuilder Jun 3, 2024
@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Jun 10, 2024

Thanks for raising @schummar. Could you give an example where providing an undefined value caused issues? For now I'd accept the change to generic-container-builder.ts which seems like a bug

@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Jun 10, 2024
@cristianrgreco cristianrgreco changed the title fix: pull policy in GenericContainerBuilder GenericContainerBuilder false pull policy should not pull image Jun 10, 2024
@cristianrgreco cristianrgreco changed the title GenericContainerBuilder false pull policy should not pull image GenericContainerBuilder false pull policy should not pull image Jun 10, 2024
@schummar
Copy link
Contributor Author

Hmm, I am pretty sure I saw some kind of error when the parameter was passed as undefined. But I cannot reproduce it now. Maybe I mixed something up. I have reverted that change now.

@schummar
Copy link
Contributor Author

Ok I guess that was the reason - it results in an error when running the build via Podman.

image

So I guess I bring the change back? I could also extract the logic to a util function to keep the code in docker-image-client.ts cleaner?

@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Jun 15, 2024

It is interesting that undefined is interpreted as an empty string and fails validation with Podman.

What about if we use null instead of undefined? If not I'd rather explicitly add the pull field to the opts if shouldPull returns true. I think that code is easier to reason about than something which dynamically alters the options.

Thanks again for raising this PR!

@schummar
Copy link
Contributor Author

That's how the querystring lib handles it. Both undefined and null result in an empty string being sent. See https://runkit.com/embed/8n76jv2sc2lc

I changed it like you suggested. And I added a test case that fails without the fix.

@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Jun 15, 2024

Thanks @schummar, the implementation LGTM.

I think the test added is a duplicate of this one, which is unfortunately disabled for Podman

// https://github.com/containers/podman/issues/17779
if (!process.env.CI_PODMAN) {
it("should use pull policy", async () => {
const dockerfile = path.resolve(fixtures, "docker");
const containerSpec = GenericContainer.fromDockerfile(dockerfile).withPullPolicy(PullPolicy.alwaysPull());
await containerSpec.build();
const dockerEventStream = await getDockerEventStream();
const dockerPullEventPromise = waitForDockerEvent(dockerEventStream, "pull");
await containerSpec.build();
await dockerPullEventPromise;
dockerEventStream.destroy();
});
}

@schummar
Copy link
Contributor Author

That one test that the image is pulled when the pull policy says so. The new test tests that it doesn't pull when no pull policy is supplied.

@cristianrgreco cristianrgreco merged commit 441b61f into testcontainers:main Jun 16, 2024
137 checks passed
@cristianrgreco cristianrgreco changed the title GenericContainerBuilder false pull policy should not pull image GenericContainerBuilder false pull policy should not pull image Jun 16, 2024
@jonesbusy
Copy link

Without any other changes, upgrading from 10.9 to 10.10 break my build on my environment

[05:23:12.330+02:00] -     Could not find a working container runtime strategy
[05:23:12.330+02:00] - 
[05:23:12.330+02:00] -       18 |
[05:23:12.330+02:00] -       19 | export async function buildWireMockContainer(): Promise<StartedTestContainer> {
[05:23:12.330+02:00] -     > 20 |   return await new GenericContainer(`wiremock/wiremock:${WIREMOCK_VERSION}`)

Is suspect this PR cause my issue beucase it cause only GenericContainer to fail with Could not find a working container runtime strategy

I'm running testcontainer using kubedock (https://github.com/joyrex2001/kubedock)

@cristianrgreco
Copy link
Collaborator

Hi @jonesbusy, the code change in this PR only takes effect after a working container runtime is established. If you want help please raise an issue and fill out the template, providing logs, etc.

@jonesbusy
Copy link

Hi @jonesbusy, the code change in this PR only takes effect after a working container runtime is established. If you want help please raise an issue and fill out the template, providing logs, etc.

Hi, sure I will provide all the details like I did for #747

It's just that I didn't saw any other difference between 10.9 and 10.10 that might have cause the new issue I'm facing.

Thanks

@schummar schummar deleted the fix/pull-policy branch June 24, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch Backward compatible bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants