Skip to content

Conversation

@digia
Copy link

@digia digia commented Dec 23, 2025

Enables running Ryuk in privileged mode via ryuk.container.privileged=true. Needed for Podman on macOS where SELinux blocks socket access.

1. Environment variables (TESTCONTAINERS_* prefix)
2. User file (~/.testcontainers.properties)
3. Project file (.testcontainers.properties)
Parse properties earlier to allow controlling Ryuk container config,
specifically supporting the `with_privileged` flag.
Copilot AI review requested due to automatic review settings December 23, 2025 03:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for running Ryuk (the Testcontainers cleanup utility) in privileged mode, which is needed for Podman on macOS where SELinux blocks socket access.

Key changes:

  • Adds read_property_sources/1 to PropertiesParser to read configuration from multiple sources (environment variables, user file, and project file) with proper precedence
  • Implements Container.with_privileged/2 to set privileged mode on containers
  • Updates Testcontainers setup to read properties before configuring Ryuk and applies the privileged setting from ryuk.container.privileged property

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/container.ex Adds with_privileged/2 function to enable setting privileged mode on containers
lib/util/properties.ex Implements read_property_sources/1 to read properties from environment variables, user file, and project file with proper precedence; adds helper functions for file reading and environment variable conversion
lib/testcontainers.ex Modifies setup to read properties before Ryuk configuration and applies the privileged setting from properties
test/container_test.exs Adds tests for with_privileged/2 functionality
test/util/properties_test.exs Adds comprehensive tests for the new PropertiesParser functionality including environment variable reading, file reading, and precedence handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +31
test "reads environment variables with TESTCONTAINERS_ prefix" do
System.put_env("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "true")
System.put_env("TESTCONTAINERS_SOME_OTHER_PROPERTY", "value")

{:ok, props} = PropertiesParser.read_property_sources()

assert props["ryuk.container.privileged"] == "true"
assert props["some.other.property"] == "value"

# Cleanup
System.delete_env("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED")
System.delete_env("TESTCONTAINERS_SOME_OTHER_PROPERTY")
end
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The test lacks proper cleanup if an assertion fails. Use ExUnit's on_exit/1 callback or setup/teardown to ensure environment variables are always cleaned up, even when tests fail. This prevents test isolation issues where a failing test could pollute the environment for subsequent tests.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +44
test "environment variables take precedence over file properties" do
# Set env var
System.put_env("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "from_env")

{:ok, props} = PropertiesParser.read_property_sources()

# Env should win over any file-based setting
assert props["ryuk.container.privileged"] == "from_env"

# Cleanup
System.delete_env("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED")
end
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The test lacks proper cleanup if an assertion fails. Use ExUnit's on_exit/1 callback or setup/teardown to ensure environment variables are always cleaned up, even when tests fail.

Copilot uses AI. Check for mistakes.
- `:project_file` - path to project properties file (default: .testcontainers.properties)
- `:env_prefix` - environment variable prefix (default: TESTCONTAINERS_)
Returns `{:ok, map}` with merged properties.
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The documentation should follow the project's standard format by using a proper "## Returns" section header instead of inline text. This maintains consistency with other documented functions in the codebase (see lib/testcontainers.ex and lib/ecto.ex for examples).

Suggested change
Returns `{:ok, map}` with merged properties.
## Returns
- `{:ok, map}` with merged properties.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +17
test "returns empty map when no files or env vars exist" do
# Clean env vars that might interfere
System.get_env()
|> Enum.filter(fn {k, _} -> String.starts_with?(k, "TESTCONTAINERS_") end)
|> Enum.each(fn {k, _} -> System.delete_env(k) end)

{:ok, props} = PropertiesParser.read_property_sources()

# Should at least return a map (may have project file props)
assert is_map(props)
end
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The test name claims "returns empty map when no files or env vars exist" but the test doesn't ensure no files exist and doesn't verify the map is empty. The comment on line 15 acknowledges this by noting "may have project file props". Consider either renaming the test to accurately describe what it tests (e.g., "returns a map with merged properties from all sources") or modify the test to actually verify an empty map when no sources exist by mocking the file system and environment.

Copilot uses AI. Check for mistakes.
@jarlah
Copy link
Member

jarlah commented Dec 23, 2025

Is this containing the same properties parser / code as the other pr ?

@digia
Copy link
Author

digia commented Dec 23, 2025

Is this containing the same properties parser / code as the other pr ?

It does, but only because it's forked from the other branch. Sorry for that confusion.

Original intention was to split them as they're technically two separate changes. But of course, my late evening shuffle botched that.

Copy link
Member

@jarlah jarlah left a comment

Choose a reason for hiding this comment

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

I cant see any obvious wrongdoings other than what copilot has mentioned. I suggest that you look into copilots comments, especially about doc strings, test name and test cleanup. Other than that you could maybe also look into removing the read_property_file function completely if not used anymore.

@jarlah
Copy link
Member

jarlah commented Dec 24, 2025

Nice work btw. Appreciate your contribution. 🤌

@digia
Copy link
Author

digia commented Jan 5, 2026

Nice work btw. Appreciate your contribution. 🤌

You're welcome, thanks for your efforts here as well!

Getting caught up from the holidays here, but I will wrap up the feedback and get an update pushed here as soon as I can.

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.

2 participants