/
Config.swift
98 lines (93 loc) · 4.09 KB
/
Config.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Foundation
struct Config: Codable {
init(
provisioner: ProvisionerConfig,
hardware: HardwareConfig,
directoryMounts: [DirectoryMountConfig],
source: VMSource,
vmClonePath: String,
numberOfRunsUntilHostReboot: Int? = nil,
runnerName: String? = nil,
editorMode: Bool,
autoTransferImageVolume: String? = nil,
retryDelay: Int,
sshCredentials: SSHCredentials,
preRun: String? = nil,
postRun: String? = nil
) {
self.provisioner = provisioner
self.hardware = hardware
self.directoryMounts = directoryMounts
self.source = source
self.vmClonePath = vmClonePath
self.numberOfRunsUntilHostReboot = numberOfRunsUntilHostReboot
self.runnerName = runnerName
self.editorMode = editorMode
self.retryDelay = retryDelay
self.sshCredentials = sshCredentials
self.preRun = preRun
self.postRun = postRun
}
/// Provisioner Configuration.
let provisioner: ProvisionerConfig
/// Hardware Configuration.
let hardware: HardwareConfig
/// Directories to mount on the Guest OS.
let directoryMounts: [DirectoryMountConfig]
/// The path where the VM bundle is located.
let source: VMSource
/// The path where the cloned VM bundle for each run is located.
/// This should be on the same APFS volume as `vmBundlePath`.
/// Can be omitted, in which case it defaults to `~/vmclone`.
let vmClonePath: String
/// Number of runs until the Host machine reboots.
let numberOfRunsUntilHostReboot: Int?
/// Overrides the runner name chosen by the provisioner.
let runnerName: String?
/// Does not copy the VM bundle and mounts the `Editor Resources` folder contained in the bundle on the guest machine.
let editorMode: Bool
/// Delay in seconds before retrying to provision the image a failed cycle.
let retryDelay: Int
/// Credentials to be used when connecting via SSH.
let sshCredentials: SSHCredentials
/// A command to run before the provisioning commands are run.
let preRun: String?
/// A command to run after the provisioning commands are run.
let postRun: String?
enum CodingKeys: CodingKey {
case provisioner
case hardware
case directoryMounts
case source
case vmClonePath
case numberOfRunsUntilHostReboot
case runnerName
case editorMode
case retryDelay
case sshCredentials
case preRun
case postRun
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.provisioner = try container.decode(ProvisionerConfig.self, forKey: .provisioner)
self.hardware = try container.decodeIfPresent(HardwareConfig.self, forKey: .hardware) ?? .default
self.directoryMounts = try container.decodeIfPresent([DirectoryMountConfig].self, forKey: .directoryMounts) ?? []
self.source = try container.decode(VMSource.self, forKey: .source)
self.vmClonePath = try (
container.decodeIfPresent(String.self, forKey: .vmClonePath).map { ($0 as NSString).standardizingPath }
) ?? URL(filePath: NSHomeDirectory()).appending(component: "vmclone").path
self.numberOfRunsUntilHostReboot = try container.decodeIfPresent(Int.self, forKey: .numberOfRunsUntilHostReboot)
self.runnerName = try container.decodeIfPresent(String.self, forKey: .runnerName)
self.editorMode = try container.decodeIfPresent(Bool.self, forKey: .editorMode) ?? false
self.retryDelay = try container.decodeIfPresent(Int.self, forKey: .retryDelay) ?? 5
self.sshCredentials = try container.decodeIfPresent(SSHCredentials.self, forKey: .sshCredentials) ?? .default
self.preRun = try container.decodeIfPresent(String.self, forKey: .preRun)
self.postRun = try container.decodeIfPresent(String.self, forKey: .postRun)
}
}
struct SSHCredentials: Codable {
static var `default` = Self(username: "admin", password: "admin")
let username: String
let password: String
}