mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-02-03 20:29:30 -05:00
Add ability to upload executable files (#55)
* Add ability to upload executable files
This commit is contained in:
parent
46d1fc59eb
commit
97599ecb3d
4 changed files with 27 additions and 2 deletions
|
|
@ -405,6 +405,12 @@ func resourceDockerContainer() *schema.Resource {
|
|||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"executable": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -210,15 +210,23 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
|
|||
}
|
||||
|
||||
if v, ok := d.GetOk("upload"); ok {
|
||||
|
||||
var mode int64
|
||||
for _, upload := range v.(*schema.Set).List() {
|
||||
content := upload.(map[string]interface{})["content"].(string)
|
||||
file := upload.(map[string]interface{})["file"].(string)
|
||||
executable := upload.(map[string]interface{})["executable"].(bool)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buf)
|
||||
if executable {
|
||||
mode = 0744
|
||||
} else {
|
||||
mode = 0644
|
||||
}
|
||||
hdr := &tar.Header{
|
||||
Name: file,
|
||||
Mode: 0644,
|
||||
Mode: mode,
|
||||
Size: int64(len(content)),
|
||||
}
|
||||
if err := tw.WriteHeader(hdr); err != nil {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
dc "github.com/fsouza/go-dockerclient"
|
||||
|
|
@ -245,8 +247,13 @@ func TestAccDockerContainer_upload(t *testing.T) {
|
|||
r := bytes.NewReader(buf.Bytes())
|
||||
tr := tar.NewReader(r)
|
||||
|
||||
if _, err := tr.Next(); err != nil {
|
||||
if header, err := tr.Next(); err != nil {
|
||||
return fmt.Errorf("Unable to read content of tar archive: %s", err)
|
||||
} else {
|
||||
mode := strconv.FormatInt(header.Mode, 8)
|
||||
if !strings.HasSuffix(mode, "744") {
|
||||
return fmt.Errorf("File permissions are incorrect: %s", mode)
|
||||
}
|
||||
}
|
||||
|
||||
fbuf := new(bytes.Buffer)
|
||||
|
|
@ -479,6 +486,7 @@ resource "docker_container" "foo" {
|
|||
upload {
|
||||
content = "foo"
|
||||
file = "/terraform/test.txt"
|
||||
executable = true
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
|
|||
|
|
@ -161,6 +161,9 @@ Each `upload` supports the following
|
|||
|
||||
* `content` - (Required, string) A content of a file to upload.
|
||||
* `file` - (Required, string) path to a file in the container.
|
||||
* `executable` - (Optional, bool) If true, the file will be uploaded with user
|
||||
executable permission.
|
||||
Defaults to false.
|
||||
|
||||
<a id="devices"></a>
|
||||
### Devices
|
||||
|
|
|
|||
Loading…
Reference in a new issue