mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-20 22:59:42 -05:00
fix: add current timestamp for file upload to container (#259)
This commit is contained in:
parent
3f93984d9c
commit
6be43d114e
2 changed files with 21 additions and 3 deletions
|
|
@ -458,6 +458,7 @@ func resourceDockerContainerCreate(ctx context.Context, d *schema.ResourceData,
|
||||||
Name: file,
|
Name: file,
|
||||||
Mode: mode,
|
Mode: mode,
|
||||||
Size: int64(len(contentToUpload)),
|
Size: int64(len(contentToUpload)),
|
||||||
|
ModTime: time.Now(),
|
||||||
}
|
}
|
||||||
if err := tw.WriteHeader(hdr); err != nil {
|
if err := tw.WriteHeader(hdr); err != nil {
|
||||||
return diag.Errorf("Error creating tar archive: %s", err)
|
return diag.Errorf("Error creating tar archive: %s", err)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -776,6 +777,22 @@ func TestAccDockerContainer_uploadSource(t *testing.T) {
|
||||||
return fmt.Errorf("file content is invalid")
|
return fmt.Errorf("file content is invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we directly exec the container and print the creation timestamp
|
||||||
|
// which is easier to use the native docker sdk, by creating, running and attaching a reader to the command.
|
||||||
|
execReponse, err := exec.Command("docker", "exec", "-t", "tf-test", "find", "/terraform", "-maxdepth", "1", "-name", "test.txt", "-printf", "%CY-%Cm-%Cd").Output()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable to exec command: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileCreationTime, err := time.Parse("2006-01-02", string(execReponse))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable to parse file creation time into format: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileCreationTime.IsZero() {
|
||||||
|
return fmt.Errorf("file creation time is zero: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue