Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public struct ContainerConfiguration: Sendable, Codable {
public var capAdd: [String] = []
/// Linux capabilities to drop (normalized CAP_* strings, or "ALL").
public var capDrop: [String] = []
/// Size of /dev/shm in bytes. When nil, the default size is used.
public var shmSize: UInt64?

enum CodingKeys: String, CodingKey {
case id
Expand All @@ -79,6 +81,7 @@ public struct ContainerConfiguration: Sendable, Codable {
case useInit
case capAdd
case capDrop
case shmSize
}

/// Create a configuration from the supplied Decoder, initializing missing
Expand Down Expand Up @@ -112,6 +115,7 @@ public struct ContainerConfiguration: Sendable, Codable {
useInit = try container.decodeIfPresent(Bool.self, forKey: .useInit) ?? false
capAdd = try container.decodeIfPresent([String].self, forKey: .capAdd) ?? []
capDrop = try container.decodeIfPresent([String].self, forKey: .capDrop) ?? []
shmSize = try container.decodeIfPresent(UInt64.self, forKey: .shmSize)
}

public struct DNSConfiguration: Sendable, Codable {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Services/ContainerAPIService/Client/Flags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ public struct Flags {
@Flag(name: .long, help: "Forward SSH agent socket to container")
public var ssh = false

@Option(name: .customLong("shm-size"), help: "Size of /dev/shm (e.g. 64M, 1G)")
public var shmSize: String?

@Option(name: .customLong("tmpfs"), help: "Add a tmpfs mount to the container at the given path")
public var tmpFs: [String] = []

Expand Down
6 changes: 6 additions & 0 deletions Sources/Services/ContainerAPIService/Client/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ public struct Utility {

config.mounts = resolvedMounts

if let shmSizeStr = management.shmSize {
let measurement = try Measurement.parse(parsing: shmSizeStr)
let bytes = measurement.converted(to: .bytes)
config.shmSize = UInt64(bytes.value)
}

config.virtualization = management.virtualization

// Parse network specifications with properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,15 @@ public actor SandboxService {
czConfig.virtualization = config.virtualization
czConfig.useInit = config.useInit

if let shmSize = config.shmSize {
for i in czConfig.mounts.indices {
if czConfig.mounts[i].destination == "/dev/shm" {
czConfig.mounts[i].options.removeAll { $0.hasPrefix("size=") }
czConfig.mounts[i].options.append("size=\(shmSize)")
}
}
}

for mount in config.mounts {
if try mount.isSocket() {
let socket = UnixSocketConfiguration(
Expand Down
20 changes: 20 additions & 0 deletions Tests/CLITests/Subcommands/Run/TestCLIRunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,26 @@ class TestCLIRunCommand2: CLITest {
}
}

@Test func testRunCommandShmSize() throws {
do {
let name = getTestName()
let shmSize = "128m"
let expectedKB = 128 * 1024
try doLongRun(name: name, args: ["--shm-size", shmSize])
defer {
try? doStop(name: name)
}
let output = try doExec(name: name, cmd: ["mount"])
let shmLine = output.split(separator: "\n").first { $0.contains("/dev/shm") }
#expect(shmLine != nil, "expected /dev/shm in mount output")
#expect(shmLine!.contains("size=\(expectedKB)k"), "expected size=\(expectedKB)k in mount options, got: \(shmLine!)")
try doStop(name: name)
} catch {
Issue.record("failed to run container \(error)")
return
}
}

@Test func testRunCommandOSArch() throws {
do {
let name = getLowercasedTestName()
Expand Down