|
| 1 | +/// Describes the structure of Nomad configurations. |
| 2 | +@ModuleInfo { minPklVersion = "0.28.1" } |
| 3 | +module elide.deployment.nomad |
| 4 | + |
| 5 | +import "../Base.pkl" as _base |
| 6 | + |
| 7 | +/// Represents a region in which a datacenter or job can run. |
| 8 | +typealias NomadRegion = String |
| 9 | + |
| 10 | +/// Name for a group of tasks within a Nomad job. |
| 11 | +typealias GroupName = String |
| 12 | + |
| 13 | +/// Name of a port within a port definition or request. |
| 14 | +typealias PortName = String |
| 15 | + |
| 16 | +/// Represents a datacenter in which a job can run. |
| 17 | +typealias NomadDatacenter = String |
| 18 | + |
| 19 | +/// Name of a task within a task group. |
| 20 | +typealias TaskName = String |
| 21 | + |
| 22 | +/// Defines types of task health checks. |
| 23 | +typealias TaskCheckType = "http" | "tcp" | String |
| 24 | + |
| 25 | +/// Defines Nomad task execution drivers. |
| 26 | +typealias NomadDriver = "docker" | "exec" | "java" | "raw_exec" | String |
| 27 | + |
| 28 | +/// Cgroup namespace selections. |
| 29 | +typealias CGroupNamespace = "host" | "private" |
| 30 | + |
| 31 | +/// Container image coordinate. |
| 32 | +typealias ContainerImage = String |
| 33 | + |
| 34 | +/// Settings which apply to a job's update strategy. |
| 35 | +class JobUpdateStrategy { |
| 36 | + /// Duration with which to stagger allocation updates. |
| 37 | + stagger: Duration? |
| 38 | + |
| 39 | + /// Max number of parallel updates. |
| 40 | + maxParallel: Int? |
| 41 | +} |
| 42 | + |
| 43 | +/// Settings for networking which apply at various job scopes. |
| 44 | +open class NetworkSettings {} |
| 45 | + |
| 46 | +/// Specifies parameters for a port request within a task group. |
| 47 | +abstract class TaskGroupPortRequest {} |
| 48 | + |
| 49 | +/// Represents a named dynamic port request within a task group. |
| 50 | +class DynamicPortRequest extends TaskGroupPortRequest {} |
| 51 | + |
| 52 | +/// Represents a named static port request within a task group. |
| 53 | +class StaticPortRequest extends TaskGroupPortRequest { |
| 54 | + /// Specifies the static port number requested for this task group. |
| 55 | + static: _base.NonRootPortNumber |
| 56 | +} |
| 57 | + |
| 58 | +/// Defines the type of health check to perform for a task group's registered service. |
| 59 | +class TaskGroupCheck { |
| 60 | + /// Type of health check to perform. |
| 61 | + type: TaskCheckType |
| 62 | + |
| 63 | + /// Optional HTTP path to use for this check. |
| 64 | + path: String? |
| 65 | + |
| 66 | + /// Check interval to apply. |
| 67 | + interval: Duration? |
| 68 | + |
| 69 | + /// Timeout for this check. |
| 70 | + timeout: Duration? |
| 71 | +} |
| 72 | + |
| 73 | +/// Service registration settings for a task group. |
| 74 | +open class Service { |
| 75 | + /// Tells Consul to monitor the assigned port; uses a port name as defined within the task group block. |
| 76 | + port: PortName? |
| 77 | +} |
| 78 | + |
| 79 | +/// Settings which apply to the Consul Connect sidecar integration. |
| 80 | +class ConnectSidecar {} |
| 81 | + |
| 82 | +/// Settings which apply to Consul Connect. |
| 83 | +class ConnectSettings { |
| 84 | + /// Consul Connect sidecar service settings. |
| 85 | + sidecarService: ConnectSidecar |
| 86 | +} |
| 87 | + |
| 88 | +/// Service settings for a group of tasks. |
| 89 | +open class GroupService { |
| 90 | + /// Required registration name for this service. |
| 91 | + name: String |
| 92 | + |
| 93 | + /// Consul Connect settings for this service group. |
| 94 | + connect: ConnectSettings |
| 95 | +} |
| 96 | + |
| 97 | +/// Settings for networking which apply to task groups. |
| 98 | +typealias TaskGroupNetworking = Mapping<PortName, TaskGroupPortRequest> |
| 99 | + |
| 100 | +/// Specifies the resource constraints applied to a given Nomad task. |
| 101 | +class TaskResources { |
| 102 | + /// CPU share to allocate to this task. |
| 103 | + cpu: Int? |
| 104 | + |
| 105 | + /// Memory, in megabytes, to allocate to this task. |
| 106 | + memory: Int? |
| 107 | +} |
| 108 | + |
| 109 | +/// Nomad task configuration. |
| 110 | +typealias NomadTaskConfig = Mapping<String, Any> |
| 111 | + |
| 112 | +/// Specifies the particulars for an actual running process/task within a Nomad job's task group; this is where process |
| 113 | +/// execution is defined, along with resource constraints and other settings. |
| 114 | +open class NomadTask { |
| 115 | + /// Nomad execution driver to use. |
| 116 | + driver: NomadDriver |
| 117 | + |
| 118 | + /// Driver-specific configuration for this task. |
| 119 | + config: NomadTaskConfig = new {} |
| 120 | + |
| 121 | + /// Environment variables to set for this task. |
| 122 | + env: Mapping<String, String> = new {} |
| 123 | + |
| 124 | + /// Resource limits to apply to this task. |
| 125 | + resources: TaskResources = new {} |
| 126 | +} |
| 127 | + |
| 128 | +/// Abstract base class for task configurations. |
| 129 | +abstract class TaskConfig {} |
| 130 | + |
| 131 | +/// Settings which apply to a container task's health checks. |
| 132 | +class ContainerHealthchecksConfig { |
| 133 | + /// Force-disable enforcement of HEALTHCHECK directives. |
| 134 | + disable: Boolean? |
| 135 | +} |
| 136 | + |
| 137 | +/// Specifies task configuration for a container-based task. |
| 138 | +class ContainerTaskConfig extends TaskConfig { |
| 139 | + /// Container image coordinates to use for this task. |
| 140 | + image: ContainerImage |
| 141 | + |
| 142 | + /// Timeout duration for pulling the container image. |
| 143 | + imagePullTimeout: Duration? |
| 144 | + |
| 145 | + /// Ports to expose from this container. |
| 146 | + ports: Listing<PortName> = new {} |
| 147 | + |
| 148 | + /// Arguments to set for this container. |
| 149 | + args: Listing<String> = new {} |
| 150 | + |
| 151 | + /// Command string to execute. |
| 152 | + command: String? |
| 153 | + |
| 154 | + /// Cgroup namespace to use; set to `host` or `private`. |
| 155 | + cgroupns: CGroupNamespace? |
| 156 | + |
| 157 | + /// Number of attempts to be made to purge a container. |
| 158 | + containerExistsAttempts: Int? |
| 159 | + |
| 160 | + /// A list of DNS search domains for the container to use. |
| 161 | + dnsSearchDomains: Listing<_base.DomainName>? |
| 162 | + |
| 163 | + /// A suite of DNS options for the container to use; if you are using bridge networking mode with a `network` block in |
| 164 | + /// the task group, you must set all DNS options in the `network.dns` block instead. |
| 165 | + dnsOptions: Mapping<String, String>? |
| 166 | + |
| 167 | + /// A list of DNS servers for the container to use; requires Docker v1.10 or greater. If you are using bridge |
| 168 | + /// networking mode with a `network` block in the task group, you must set all DNS options within the `network.dns` |
| 169 | + /// block instead. |
| 170 | + dnsServers: Listing<String>? |
| 171 | + |
| 172 | + /// Entrypoint to set for this container. |
| 173 | + entrypoint: String? |
| 174 | + |
| 175 | + /// A list of hosts, given as `host:IP`, to be added to `/etc/hosts`. This option may not work as expected in `bridge` |
| 176 | + /// network mode when there is more than one task within the same group. |
| 177 | + extraHosts: Listing<String>? |
| 178 | + |
| 179 | + /// Always pull the most recent image instead of using existing local image. Should be set to `true` if repository |
| 180 | + /// tags are mutable; if image's tag is `latest` or omitted, the image will always be pulled regardless of this |
| 181 | + /// setting. |
| 182 | + forcePull: Boolean? |
| 183 | + |
| 184 | + /// A list of supplementary groups to be applied to the container user. |
| 185 | + groupAdd: List<String>? |
| 186 | + |
| 187 | + /// Health check configuration for this container task. |
| 188 | + healthchecks: ContainerHealthchecksConfig |
| 189 | + |
| 190 | + /// The hostname to assign to the container. When launching more than one of a task (using `count`) with this option |
| 191 | + /// set, every container the task starts will have the same hostname. |
| 192 | + hostname: String? |
| 193 | +} |
| 194 | + |
| 195 | +/// Defines a Nomad task implemented via a Docker or OCI container. |
| 196 | +class ContainerTask extends NomadTask { |
| 197 | + /// Default driver as Docker. |
| 198 | + driver = "docker" |
| 199 | + |
| 200 | + /// Container-specific task configuration. |
| 201 | + config: ContainerTaskConfig = new {} |
| 202 | +} |
| 203 | + |
| 204 | +/// Defines the constituent tasks for a given task group within a Nomad job. |
| 205 | +typealias NomadTasks = Mapping<TaskName, NomadTask> |
| 206 | + |
| 207 | +/// Represents a group of tasks within a Nomad job; task groups define related co-located tasks which are scheduled on |
| 208 | +/// the same host machine. |
| 209 | +class NomadTaskGroup { |
| 210 | + /// Count of task instances to run. |
| 211 | + count: Int? |
| 212 | + |
| 213 | + /// Network configuration for this group. |
| 214 | + network: TaskGroupNetworking = new {} |
| 215 | + |
| 216 | + /// The service block tells Nomad how to register this service with Consul for service discovery and monitoring. |
| 217 | + service: Service = new {} |
| 218 | + |
| 219 | + /// Defines tasks which are constituent to this task group. |
| 220 | + tasks: NomadTasks = new {} |
| 221 | +} |
| 222 | + |
| 223 | +/// Represents a Nomad job configuration; jobs are the core unit of execution within a Nomad cluster. |
| 224 | +open class NomadJob { |
| 225 | + /// Region where this job should run based on region pinning. |
| 226 | + region: NomadRegion? |
| 227 | + |
| 228 | + /// Group-level service block, for integration with Consul Connect. |
| 229 | + service: GroupService? |
| 230 | + |
| 231 | + /// Datacenters which this job is assigned to run in. |
| 232 | + datacenters: Listing<NomadDatacenter> = new {} |
| 233 | + |
| 234 | + /// Update strategy settings for this job. |
| 235 | + update: JobUpdateStrategy? |
| 236 | + |
| 237 | + /// A group defines a series of tasks that should be co-located on the same client (host). All tasks within a group |
| 238 | + /// will be placed on the same host; this is similar to Kubernetes' concept of "pods." |
| 239 | + groups: Mapping<GroupName, NomadTaskGroup> = new {} |
| 240 | +} |
0 commit comments