Skip to content

Commit 61f3009

Browse files
committed
[Build] Disable rosetta during builds with a UserDefault
1 parent 75e9285 commit 61f3009

File tree

4 files changed

+181
-1
lines changed

4 files changed

+181
-1
lines changed

Sources/CLI/Builder/BuilderStart.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ extension Application {
194194
options: []
195195
),
196196
]
197-
config.rosetta = true
197+
// Enable Rosetta only if the user didn't ask to disable it
198+
config.rosetta = ClientDefaults.getBool(key: .buildRosetta) ?? true
198199

199200
let network = try await ClientNetwork.get(id: ClientNetwork.defaultNetworkName)
200201
guard case .running(_, let networkStatus) = network else {

Sources/ContainerClient/Core/ClientDefaults.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public enum ClientDefaults {
2828
case defaultInitImage = "image.init"
2929
case defaultKernelURL = "kernel.url"
3030
case defaultKernelBinaryPath = "kernel.binaryPath"
31+
case buildRosetta = "build.rosetta"
3132
}
3233

3334
public static func set(value: String, key: ClientDefaults.Keys) {
@@ -47,6 +48,15 @@ public enum ClientDefaults {
4748
udSuite.string(forKey: key.rawValue)
4849
}
4950

51+
public static func setBool(value: Bool, key: ClientDefaults.Keys) {
52+
udSuite.set(value, forKey: key.rawValue)
53+
}
54+
55+
public static func getBool(key: ClientDefaults.Keys) -> Bool? {
56+
guard udSuite.object(forKey: key.rawValue) != nil else { return nil }
57+
return udSuite.bool(forKey: key.rawValue)
58+
}
59+
5060
private static var udSuite: UserDefaults {
5161
guard let ud = UserDefaults.init(suiteName: self.userDefaultDomain) else {
5262
fatalError("Failed to initialize UserDefaults for domain \(self.userDefaultDomain)")
@@ -75,6 +85,9 @@ extension ClientDefaults.Keys {
7585
return "vminit:latest"
7686
}
7787
return "ghcr.io/apple/containerization/vminit:\(tag)"
88+
case .buildRosetta:
89+
// This is a boolean key, not used with the string get() method
90+
return "true"
7891
}
7992
}
8093
}

docs/how-to.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ Use the `--boot` option to see the logs for the virtual machine boot and init pr
235235
%
236236
</pre>
237237

238+
## Configure container defaults
239+
240+
`container` uses macOS user defaults to store configuration settings that persist between sessions. You can customize various aspects of container behavior, including build settings, default images, and network configuration.
241+
242+
For a complete list of available configuration options and detailed usage instructions, see the [user defaults documentation](user-defaults.md).
243+
244+
### Example: Disable Rosetta for builds
245+
246+
If you want to prevent the use of Rosetta translation during container builds on Apple Silicon Macs:
247+
248+
```bash
249+
defaults write com.apple.container.defaults build.rosetta -bool false
250+
```
251+
252+
This is useful when you want to ensure builds only produce native arm64 images and avoid any x86_64 emulation.
253+
238254
## View system logs
239255

240256
The `container system logs` command allows you to look at the log messages that `container` writes:

docs/user-defaults.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# User Defaults Configuration
2+
3+
The `container` CLI uses macOS user defaults to store configuration settings. These settings persist between sessions and allow you to customize the behavior of various commands.
4+
5+
## Viewing Current Defaults
6+
7+
To view a specific default value, use the macOS `defaults` command:
8+
9+
```bash
10+
defaults read com.apple.container.defaults <key>
11+
```
12+
13+
## Available User Defaults
14+
15+
### Build Settings
16+
17+
#### build.rosetta
18+
19+
Controls whether Rosetta translation is enabled during container builds. When enabled (default), allows building x86_64 images on Apple Silicon Macs.
20+
21+
**Default:** `true`
22+
23+
**Usage:**
24+
```bash
25+
# Disable Rosetta for builds
26+
defaults write com.apple.container.defaults build.rosetta -bool false
27+
28+
# Enable Rosetta for builds (default)
29+
defaults write com.apple.container.defaults build.rosetta -bool true
30+
31+
# Check current value
32+
defaults read com.apple.container.defaults build.rosetta
33+
```
34+
35+
**Note:** Disabling Rosetta will prevent building x86_64 images on Apple Silicon Macs. This setting only affects the build process and does not impact running containers.
36+
37+
### Image Settings
38+
39+
#### image.builder
40+
41+
Specifies the default BuildKit image used for building containers.
42+
43+
**Default:** `ghcr.io/apple/container-builder-shim/builder:<version>`
44+
45+
**Usage:**
46+
```bash
47+
# Set a custom builder image
48+
defaults write com.apple.container.defaults image.builder "my-registry.com/my-builder:latest"
49+
50+
# Reset to default
51+
defaults delete com.apple.container.defaults image.builder
52+
```
53+
54+
#### image.init
55+
56+
Specifies the default init image used for container initialization.
57+
58+
**Default:** `ghcr.io/apple/containerization/vminit:<version>`
59+
60+
**Usage:**
61+
```bash
62+
# Set a custom init image
63+
defaults write com.apple.container.defaults image.init "my-registry.com/my-init:latest"
64+
```
65+
66+
### Network Settings
67+
68+
#### dns.domain
69+
70+
Sets the default local DNS domain for containers.
71+
72+
**Default:** `test`
73+
74+
**Usage:**
75+
```bash
76+
# Set a custom DNS domain
77+
defaults write com.apple.container.defaults dns.domain "mycompany.local"
78+
79+
# Alternatively, use the container CLI
80+
container system dns default set mycompany.local
81+
```
82+
83+
### Registry Settings
84+
85+
#### registry.domain
86+
87+
Sets the default registry domain for pulling images.
88+
89+
**Default:** `docker.io`
90+
91+
**Usage:**
92+
```bash
93+
# Set a custom default registry
94+
defaults write com.apple.container.defaults registry.domain "ghcr.io"
95+
96+
# Alternatively, use the container CLI
97+
container registry default set ghcr.io
98+
```
99+
100+
### Kernel Settings
101+
102+
#### kernel.url
103+
104+
URL for downloading the default kernel used by containers.
105+
106+
**Default:** `https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz`
107+
108+
**Usage:**
109+
```bash
110+
# Set a custom kernel URL
111+
defaults write com.apple.container.defaults kernel.url "https://myserver.com/custom-kernel.tar.xz"
112+
```
113+
114+
#### kernel.binaryPath
115+
116+
Path within the kernel archive to the actual kernel binary.
117+
118+
**Default:** `opt/kata/share/kata-containers/vmlinux-6.12.28-153`
119+
120+
**Usage:**
121+
```bash
122+
# Set a custom kernel binary path
123+
defaults write com.apple.container.defaults kernel.binaryPath "path/to/vmlinux"
124+
```
125+
126+
## Resetting Defaults
127+
128+
To reset a specific setting to its default value:
129+
130+
```bash
131+
defaults delete com.apple.container.defaults <key>
132+
```
133+
134+
To reset all container defaults:
135+
136+
```bash
137+
defaults delete com.apple.container.defaults
138+
```
139+
140+
## Platform-Specific Settings
141+
142+
### macOS 15 Network Configuration
143+
144+
On macOS 15, if you experience network connectivity issues, you may need to manually configure the network subnet:
145+
146+
```bash
147+
defaults write com.apple.container.defaults network.subnet 192.168.66.1/24
148+
```
149+
150+
See the [technical overview](technical-overview.md#macos-15-limitations) for more details about macOS 15 limitations.

0 commit comments

Comments
 (0)