Skip to content

feat: expose container devices to templates#757

Merged
buchdag merged 2 commits into
nginx-proxy:mainfrom
JamBalaya56562:feat/277-device-passthrough
Jul 13, 2026
Merged

feat: expose container devices to templates#757
buchdag merged 2 commits into
nginx-proxy:mainfrom
JamBalaya56562:feat/277-device-passthrough

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Exposes container device passthrough (HostConfig.Devices) to templates, reimplementing the stale PR #277 against the current internal/ layout.

  • Adds a Device{PathOnHost, PathInContainer, Permissions} type and a Devices []Device field on RuntimeContainer.
  • Populates it in getContainers, mirroring the existing Mounts loop. go-dockerclient's Device.CgroupPermissions is mapped to Device.Permissions.

Use case: discovering forwarded device nodes (webcams, USB-serial adapters, etc.) from templates.

Notes

  • The populate loop iterates the nil-safe local copy of HostConfig (introduced in fix: avoid panic on nil container Config/NetworkSettings/HostConfig #748) instead of dereferencing container.HostConfig directly, so a container inspected with a nil HostConfig cannot panic.
  • The unrelated t.Fatalt.Fatalf churn from the original PR is dropped.
  • HostConfig.Devices has been stable in go-dockerclient since 2018, so no dependency change is required.

Tests

Added TestGetContainersDevices, which drives getContainers against a mock daemon returning a device and asserts the populated Devices. Documented the Device struct and a JSON example in the README.

Reimplements #277

🤖 Generated with Claude Code

@JamBalaya56562 JamBalaya56562 force-pushed the feat/277-device-passthrough branch from e1c6fe6 to 4b5e1bc Compare July 11, 2026 20:02
@buchdag

buchdag commented Jul 12, 2026

Copy link
Copy Markdown
Member

@JamBalaya56562 please flag AI-generated PR explicitly in the PR description (ie "🤖 Generated with Claude Code" like in this PR) and add the AI agent as co-author of the commits.

@JamBalaya56562 JamBalaya56562 force-pushed the feat/277-device-passthrough branch from 4b5e1bc to 4f1c9cd Compare July 12, 2026 22:39
@JamBalaya56562

Copy link
Copy Markdown
Contributor Author

Done — added the Co-Authored-By: Claude Opus 4.8 trailer to the commit and the 🤖 Generated with [Claude Code](https://claude.com/claude-code) note to the PR description. I also rebased onto the latest main. Thanks for the review!

Copilot AI left a comment

Copy link
Copy Markdown

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 exposing Docker device passthrough configuration (HostConfig.Devices) in the emitted RuntimeContainer context so templates can render forwarded device nodes (e.g., USB serial adapters, webcams).

Changes:

  • Introduces a Device type and adds Devices []Device to RuntimeContainer (context + README documentation).
  • Populates RuntimeContainer.Devices in getContainers by mapping docker.Device fields (including CgroupPermissionsPermissions).
  • Adds a unit test covering device extraction via a mock Docker daemon response.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
README.md Documents the new Devices field, Device struct, and provides a JSON example.
internal/context/context.go Adds Device and wires Devices []Device into RuntimeContainer.
internal/generator/generator.go Populates RuntimeContainer.Devices from inspected container HostConfig.Devices.
internal/generator/generator_test.go Adds TestGetContainersDevices to assert device passthrough is emitted into context.

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

Comment thread internal/generator/generator_test.go Outdated
JamBalaya56562 and others added 2 commits July 13, 2026 11:54
Co-Authored-By: Martin Koppehel <martin.koppehel@st.ovgu.de>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@buchdag buchdag force-pushed the feat/277-device-passthrough branch from 35fd8d2 to b601ea9 Compare July 13, 2026 09:54
@buchdag buchdag merged commit 3372a64 into nginx-proxy:main Jul 13, 2026
6 checks passed
@JamBalaya56562 JamBalaya56562 deleted the feat/277-device-passthrough branch July 13, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants