fix: add current timestamp for file upload to container (#259)

This commit is contained in:
Manuel Vogel 2021-08-10 11:28:36 +02:00 committed by GitHub
parent 3f93984d9c
commit 6be43d114e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -455,9 +455,10 @@ func resourceDockerContainerCreate(ctx context.Context, d *schema.ResourceData,
mode = 0o644
}
hdr := &tar.Header{
Name: file,
Mode: mode,
Size: int64(len(contentToUpload)),
Name: file,
Mode: mode,
Size: int64(len(contentToUpload)),
ModTime: time.Now(),
}
if err := tw.WriteHeader(hdr); err != nil {
return diag.Errorf("Error creating tar archive: %s", err)

View file

@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
@ -776,6 +777,22 @@ func TestAccDockerContainer_uploadSource(t *testing.T) {
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
}