Skip to content

Commit e82cf92

Browse files
Maya Ozermx-moth
authored andcommitted
feat: Implement docker init in docker service
1 parent b78f540 commit e82cf92

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

docs/resources/service.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ Optional:
372372
- `healthcheck` (Block List, Max: 1) A test to perform to check that the container is healthy (see [below for nested schema](#nestedblock--task_spec--container_spec--healthcheck))
373373
- `hostname` (String) The hostname to use for the container, as a valid RFC 1123 hostname
374374
- `hosts` (Block Set) A list of hostname/IP mappings to add to the container's hosts file (see [below for nested schema](#nestedblock--task_spec--container_spec--hosts))
375+
- `init` (Boolean) Configured whether an init process should be injected for the container. If unset this will default to the
376+
`dockerd` defaults.
375377
- `isolation` (String) Isolation technology of the containers running the service. (Windows only). Defaults to `default`.
376378
- `labels` (Block Set) User-defined key/value metadata (see [below for nested schema](#nestedblock--task_spec--container_spec--labels))
377379
- `mounts` (Block Set) Specification for mounts to be added to containers created as part of the service (see [below for nested schema](#nestedblock--task_spec--container_spec--mounts))

internal/provider/resource_docker_service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ func resourceDockerService() *schema.Resource {
517517
Elem: &schema.Schema{Type: schema.TypeString},
518518
Description: "List of Linux capabilities to drop from the container",
519519
},
520+
"init": {
521+
Type: schema.TypeBool,
522+
Description: "Configured whether an init process should be injected for this container. If unset this will default to the `dockerd` defaults.",
523+
Optional: true,
524+
Computed: true,
525+
},
520526
},
521527
},
522528
},

internal/provider/resource_docker_service_structures.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func flattenContainerSpec(in *swarm.ContainerSpec) []interface{} {
183183
if len(in.CapabilityDrop) > 0 {
184184
m["cap_drop"] = in.CapabilityDrop
185185
}
186+
if in.Init {
187+
m["init"] = in.Init
188+
}
186189
out = append(out, m)
187190
return out
188191
}
@@ -965,6 +968,9 @@ func createContainerSpec(v interface{}) (*swarm.ContainerSpec, error) {
965968
containerSpec.CapabilityDrop = append(containerSpec.CapabilityDrop, cap.(string))
966969
}
967970
}
971+
if value, ok := rawContainerSpec["init"]; ok {
972+
containerSpec.Init = value.(bool)
973+
}
968974

969975
}
970976
}

0 commit comments

Comments
 (0)