-
Notifications
You must be signed in to change notification settings - Fork 34
/
commit.go
27 lines (24 loc) · 760 Bytes
/
commit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main
import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"mydocker/utils"
"os/exec"
)
var ErrImageAlreadyExists = errors.New("Image Already Exists")
func commitContainer(containerID, imageName string) error {
mntPath := utils.GetMerged(containerID)
imageTar := utils.GetImage(imageName)
exists, err := utils.PathExists(imageTar)
if err != nil {
return errors.WithMessagef(err, "check is image [%s/%s] exist failed", imageName, imageTar)
}
if exists {
return ErrImageAlreadyExists
}
log.Infof("commitContainer imageTar:%s", imageTar)
if _, err = exec.Command("tar", "-czf", imageTar, "-C", mntPath, ".").CombinedOutput(); err != nil {
return errors.WithMessagef(err, "tar folder %s failed", mntPath)
}
return nil
}