-
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
provider/docker: Docker upload #4921
Changes from all commits
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 |
---|---|---|
|
@@ -2,10 +2,14 @@ package docker | |
|
||
import ( | ||
"bytes" | ||
"crypto/sha1" | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"io" | ||
"os" | ||
"regexp" | ||
|
||
"github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/archive" | ||
"github.com/hashicorp/terraform/helper/hashcode" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
@@ -348,6 +352,54 @@ func resourceDockerContainer() *schema.Resource { | |
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
}, | ||
|
||
"uploads": &schema.Schema{ | ||
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. Could be renamed if necessary |
||
Type: schema.TypeSet, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"local_path": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) { | ||
path := v.(string) | ||
if _, err := os.Stat(path); err != nil { | ||
es = append(es, fmt.Errorf( | ||
"%q must be valid path: %s", path, err)) | ||
} | ||
return | ||
}, | ||
StateFunc: func(v interface{}) string { | ||
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. I'm not sure why but during my tests, it turns out that the generated state file leaves the path here but while doing a plan, the checksum is generated. This leads to changes such as
Could this be related to the many issues related to |
||
switch v.(type) { | ||
case string: | ||
reader, err := archive.Tar(v.(string), archive.Uncompressed) | ||
if err != nil { | ||
return "invalid" | ||
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. There is no nice error management in |
||
} | ||
|
||
hash := sha1.New() | ||
if _, err := io.Copy(hash, reader); err != nil { | ||
return "invalid" | ||
} | ||
|
||
return hex.EncodeToString(hash.Sum(nil)[:]) | ||
default: | ||
return "" | ||
} | ||
}, | ||
}, | ||
|
||
"remote_path": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
}, | ||
Set: resourceDockerUploadsHash, | ||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -414,3 +466,18 @@ func resourceDockerVolumesHash(v interface{}) int { | |
|
||
return hashcode.String(buf.String()) | ||
} | ||
|
||
func resourceDockerUploadsHash(v interface{}) int { | ||
var buf bytes.Buffer | ||
m := v.(map[string]interface{}) | ||
|
||
if v, ok := m["local_path"]; ok { | ||
buf.WriteString(fmt.Sprintf("%v-", v.(string))) | ||
} | ||
|
||
if v, ok := m["remote_path"]; ok { | ||
buf.WriteString(fmt.Sprintf("%v-", v.(string))) | ||
} | ||
|
||
return hashcode.String(buf.String()) | ||
} |
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.
Not sure whether transitive dependencies are the way to go here. Any suggestions?