Skip to content

Commit

Permalink
Pull image before starting backup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Apr 5, 2016
1 parent 086bf74 commit 8de25e6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions conplicity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

type Conplicity struct {
*docker.Client
Hostname string
*docker.Client
Image string
}

func main() {
Expand All @@ -30,6 +31,12 @@ func main() {
vols, err := c.ListVolumes(docker.ListVolumesOptions{})
checkErr(err, "Failed to list Docker volumes: %v", 1)

// TODO: Make it variable
c.Image = "camptocamp/duplicity"

err = c.pullImage()
checkErr(err, "Failed to pull image: %v", 1)

for _, vol := range vols {
err = c.backupVolume(vol)
checkErr(err, "Failed to process volume "+vol.Name+": %v", -1)
Expand All @@ -38,7 +45,6 @@ func main() {
log.Infof("End backup...")
}


func (c *Conplicity) backupVolume(vol docker.Volume) (err error) {
if utf8.RuneCountInString(vol.Name) == 64 {
log.Infof("Ignoring volume "+vol.Name)
Expand Down Expand Up @@ -71,7 +77,7 @@ func (c *Conplicity) backupVolume(vol docker.Volume) (err error) {
"SWIFT_REGIONNAME="+os.Getenv("SWIFT_REGIONNAME"),
"SWIFT_AUTHVERSION=2",
},
Image: "camptocamp/duplicity",
Image: c.Image,
OpenStdin: true,
StdinOnce: true,
AttachStdin: true,
Expand Down Expand Up @@ -102,6 +108,16 @@ func (c *Conplicity) backupVolume(vol docker.Volume) (err error) {
return
}

func (c *Conplicity) pullImage() (err error) {
// TODO: output pull to logs
log.Infof("Pulling image %v", c.Image)
err = c.PullImage(docker.PullImageOptions{
Repository: c.Image,
}, docker.AuthConfiguration{})

return err
}

func checkErr(err error, msg string, exit int) {
if err != nil {
log.Errorf(msg, err)
Expand Down

0 comments on commit 8de25e6

Please sign in to comment.