Skip to content

Commit 6087c2b

Browse files
authored
Merge pull request #68 from traderepublic/feature/dummy-console-devices
Add dummy console device support
2 parents 66f374b + 3eba6df commit 6087c2b

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

Cilicon/Config/Config.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ struct Config: Codable {
1313
retryDelay: Int,
1414
sshCredentials: SSHCredentials,
1515
preRun: String? = nil,
16-
postRun: String? = nil
16+
postRun: String? = nil,
17+
consoleDevices: [String] = []
1718
) {
1819
self.provisioner = provisioner
1920
self.hardware = hardware
@@ -26,6 +27,7 @@ struct Config: Codable {
2627
self.sshCredentials = sshCredentials
2728
self.preRun = preRun
2829
self.postRun = postRun
30+
self.consoleDevices = consoleDevices
2931
}
3032

3133
/// Provisioner Configuration.
@@ -52,6 +54,8 @@ struct Config: Codable {
5254
let preRun: String?
5355
/// A command to run after the provisioning commands are run.
5456
let postRun: String?
57+
/// A list of console device names that are going to be injected into the VM.
58+
let consoleDevices: [String]
5559

5660
enum CodingKeys: CodingKey {
5761
case provisioner
@@ -65,6 +69,7 @@ struct Config: Codable {
6569
case sshCredentials
6670
case preRun
6771
case postRun
72+
case consoleDevices
6873
}
6974

7075
init(from decoder: Decoder) throws {
@@ -82,6 +87,7 @@ struct Config: Codable {
8287
self.sshCredentials = try container.decodeIfPresent(SSHCredentials.self, forKey: .sshCredentials) ?? .default
8388
self.preRun = try container.decodeIfPresent(String.self, forKey: .preRun)
8489
self.postRun = try container.decodeIfPresent(String.self, forKey: .postRun)
90+
self.consoleDevices = try container.decodeIfPresent([String].self, forKey: .consoleDevices) ?? []
8591
}
8692
}
8793

Cilicon/VMConfigHelper+RunConfig.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ extension VMConfigHelper {
2424
virtualMachineConfiguration.audioDevices = [createAudioDeviceConfiguration()]
2525
}
2626
virtualMachineConfiguration.directorySharingDevices = try [createDirectorySharingConfiguration(config: config)]
27+
28+
for consoleDeviceConfig in config.consoleDevices {
29+
let consolePort = VZVirtioConsolePortConfiguration()
30+
consolePort.name = consoleDeviceConfig
31+
let consoleDevice = VZVirtioConsoleDeviceConfiguration()
32+
consoleDevice.ports[0] = consolePort
33+
virtualMachineConfiguration.consoleDevices.append(consoleDevice)
34+
}
35+
2736
try virtualMachineConfiguration.validate()
2837

2938
return virtualMachineConfiguration
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import XCTest
2+
import Yams
3+
4+
@testable import Cilicon
5+
6+
final class ConfigTests: XCTestCase {
7+
private var yamlDecoder: YAMLDecoder!
8+
9+
override func setUp() {
10+
yamlDecoder = YAMLDecoder()
11+
}
12+
13+
override func tearDown() {
14+
yamlDecoder = nil
15+
}
16+
17+
func test_decode_consoleDevices_notPresent_isEmptyArray() throws {
18+
let yaml = fixtureConfig
19+
let sut = try yamlDecoder.decode(Config.self, from: Data(yaml.utf8))
20+
21+
XCTAssertEqual(sut.consoleDevices, [])
22+
}
23+
24+
func test_decode_consoleDevices_isPresent_isParsedCorrectly() throws {
25+
let yaml = fixtureConfig.appending("""
26+
consoleDevices:
27+
- test-device
28+
- test-device2
29+
""")
30+
31+
let sut = try yamlDecoder.decode(Config.self, from: Data(yaml.utf8))
32+
XCTAssertEqual(sut.consoleDevices, ["test-device", "test-device2"])
33+
}
34+
}
35+
36+
private extension ConfigTests {
37+
var fixtureConfig: String {
38+
"""
39+
source: oci://example.com/namespace/image_name:tag
40+
provisioner:
41+
type: github
42+
config:
43+
appId: 123456
44+
organization: test-organization
45+
runnerGroup: test-group
46+
privateKeyPath: ~/github.pem
47+
48+
"""
49+
}
50+
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ provisioner:
104104
downloadLatest: <DOWNLOAD_LATEST> # defaults to 'true'. If 'false' it expects the binary to be present at the user's home directory
105105
downloadURL: <DOWNLOAD_URL> # defaults to GitLab official S3 bucket
106106
tomlPath: <PATH_TO_TOML> # defaults to `nil`. If set, it ignores the other runner related variables and passes the specified path to the runner executable
107+
consoleDevices:
108+
- tart-version-cilicon
107109
```
108110
109111
#### Buildkite Agent
@@ -132,6 +134,17 @@ provisioner:
132134
sleep 10
133135
```
134136

137+
#### Console Devices
138+
139+
Cilicon supports injecting console devices into the VM configuration. This is particularly useful for compatibility with tools like [tart-guest-agent](https://github.com/cirruslabs/tart-guest-agent) which expect specific console devices to be present.
140+
141+
To add console devices, use the `consoleDevices` field in your configuration:
142+
143+
```yml
144+
consoleDevices:
145+
- tart-version-cilicon
146+
```
147+
135148
### 🔨 Setting Up the Host OS
136149
It is recommended to use Cilicon on a macOS device fully dedicated to the task, ideally one that is [freshly restored](https://support.apple.com/en-gb/guide/apple-configurator-mac/apdd5f3c75ad/mac).
137150

0 commit comments

Comments
 (0)