-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker provider additions #3761
Changes from 7 commits
0ded14f
17d1858
6842c32
4531866
72c86a6
1f739d3
b5ae355
4fc60c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,10 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err | |
createOpts.Config.Cmd = stringListToStringSlice(v.([]interface{})) | ||
} | ||
|
||
if v, ok := d.GetOk("entrypoint"); ok { | ||
createOpts.Config.Entrypoint = stringListToStringSlice(v.([]interface{})) | ||
} | ||
|
||
exposedPorts := map[dc.Port]struct{}{} | ||
portBindings := map[dc.Port][]dc.PortBinding{} | ||
|
||
|
@@ -78,19 +82,20 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err | |
createOpts.Config.Volumes = volumes | ||
} | ||
|
||
var retContainer *dc.Container | ||
if retContainer, err = client.CreateContainer(createOpts); err != nil { | ||
return fmt.Errorf("Unable to create container: %s", err) | ||
if v, ok := d.GetOk("labels"); ok { | ||
createOpts.Config.Labels = mapTypeMapValsToString(v.(map[string]interface{})) | ||
} | ||
if retContainer == nil { | ||
return fmt.Errorf("Returned container is nil") | ||
} | ||
|
||
d.SetId(retContainer.ID) | ||
|
||
hostConfig := &dc.HostConfig{ | ||
Privileged: d.Get("privileged").(bool), | ||
PublishAllPorts: d.Get("publish_all_ports").(bool), | ||
RestartPolicy: dc.RestartPolicy{ | ||
Name: d.Get("restart").(string), | ||
MaximumRetryCount: d.Get("max_retry_count").(int), | ||
}, | ||
LogConfig: dc.LogConfig{ | ||
Type: d.Get("log_driver").(string), | ||
}, | ||
} | ||
|
||
if len(portBindings) != 0 { | ||
|
@@ -112,6 +117,46 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err | |
hostConfig.Links = stringSetToStringSlice(v.(*schema.Set)) | ||
} | ||
|
||
if v, ok := d.GetOk("memory"); ok { | ||
memory := int64(v.(int)) | ||
if memory > 0 { | ||
hostConfig.Memory = memory * 1024 * 1024 | ||
} | ||
} | ||
|
||
if v, ok := d.GetOk("memory_swap"); ok { | ||
swap := int64(v.(int)) | ||
if swap != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same applies to this check as to the one for |
||
if swap > 0 { // only convert positive #s to bytes | ||
swap = swap * 1024 * 1024 | ||
} | ||
hostConfig.MemorySwap = swap | ||
} | ||
} | ||
|
||
if v, ok := d.GetOk("cpu_shares"); ok { | ||
shares := int64(v.(int)) | ||
if shares > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same applies as for |
||
hostConfig.CPUShares = shares | ||
} | ||
} | ||
|
||
if v, ok := d.GetOk("log_opts"); ok { | ||
hostConfig.LogConfig.Config = mapTypeMapValsToString(v.(map[string]interface{})) | ||
} | ||
|
||
createOpts.HostConfig = hostConfig | ||
|
||
var retContainer *dc.Container | ||
if retContainer, err = client.CreateContainer(createOpts); err != nil { | ||
return fmt.Errorf("Unable to create container: %s", err) | ||
} | ||
if retContainer == nil { | ||
return fmt.Errorf("Returned container is nil") | ||
} | ||
|
||
d.SetId(retContainer.ID) | ||
|
||
creationTime = time.Now() | ||
if err := client.StartContainer(retContainer.ID, hostConfig); err != nil { | ||
return fmt.Errorf("Unable to start container: %s", err) | ||
|
@@ -223,6 +268,14 @@ func stringSetToStringSlice(stringSet *schema.Set) []string { | |
return ret | ||
} | ||
|
||
func mapTypeMapValsToString(typeMap map[string]interface{}) map[string]string { | ||
mapped := make(map[string]string, len(typeMap)) | ||
for k, v := range typeMap { | ||
mapped[k] = v.(string) | ||
} | ||
return mapped | ||
} | ||
|
||
func fetchDockerContainer(name string, client *dc.Client) (*dc.APIContainers, error) { | ||
apiContainers, err := client.ListContainers(dc.ListContainersOptions{All: true}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this check, we should be able to trust that
d.GetOk("memory")
will return a non-zero value, and instead put in a check for negative values into theValidateFunc
for this schema such that obviously bad values are raised to the user.