Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
patch expose feature and permernant delete feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jason committed May 19, 2020
1 parent b636ee6 commit b6e12ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020050315
2020051916
36 changes: 28 additions & 8 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ func DockerCreate(name string, container_name string, volume_map string) *Error
return err
}

func DockerDelete(name string) *Error {
func DockerDelete(name string, permernant bool) *Error {
currdir, err := GetCurrDir()
if err != nil {
return err
Expand All @@ -2100,7 +2100,6 @@ func DockerDelete(name string) *Error {
for key, value := range sys.Containers {
if vval, vok := value.(map[string]interface{}); vok {
config_path := vval["ConfigPath"].(string)

var con Container
err = unmarshalObj(config_path, &con)
if err != nil {
Expand All @@ -2126,6 +2125,27 @@ func DockerDelete(name string) *Error {
if err == nil {
if val, ok := doc.Images[name]; ok {
if vval, vok := val.(map[string]interface{}); vok {
if permernant {
//we need to delete image files and folder info
image_dir := vval["image"].(string)
base_dir := vval["base"].(string)
layer_order := vval["layer_order"].(string)
for _, layer := range strings.Split(layer_order, ":") {
layer_name := filepath.Base(layer)
LOGGER.WithFields(logrus.Fields{
"folder to delete": fmt.Sprintf("%s/%s", base_dir, layer_name),
"file to delete": fmt.Sprintf("%s/%s", image_dir, layer_name),
}).Debug("Docker delete info")
_, rerr := RemoveAll(fmt.Sprintf("%s/%s", image_dir, layer_name))
if rerr != nil {
return rerr
}
_, rerr = RemoveAll(fmt.Sprintf("%s/%s", base_dir, layer_name))
if rerr != nil {
return rerr
}
}
}
dir, _ := vval["rootdir"].(string)
rok, rerr := RemoveAll(dir)
if rok {
Expand All @@ -2147,7 +2167,7 @@ func DockerDelete(name string) *Error {
return err
}

func Expose(id string, name string) *Error {
func Expose(id string, path string, name string) *Error {
currdir, err := GetCurrDir()
if err != nil {
return err
Expand All @@ -2168,11 +2188,11 @@ func Expose(id string, name string) *Error {
if err != nil {
return err
}
if !strings.Contains(con.ExposeExe, name) {
if !strings.Contains(con.ExposeExe, path) {
if con.ExposeExe == "" {
con.ExposeExe = name
con.ExposeExe = path
} else {
con.ExposeExe = fmt.Sprintf("%s:%s", con.ExposeExe, name)
con.ExposeExe = fmt.Sprintf("%s:%s", con.ExposeExe, path)
}
}

Expand All @@ -2184,7 +2204,7 @@ func Expose(id string, name string) *Error {
}
}

bname := filepath.Base(name)
bname := name
bdir := fmt.Sprintf("%s/%s", bindir, bname)
if FileExist(bdir) {
RemoveFile(bdir)
Expand All @@ -2195,7 +2215,7 @@ func Expose(id string, name string) *Error {
return cerr
}
code := "#!/bin/bash\n" + os.Args[0] +
" resume " + id + " \"" + name + " " + "$@\"" +
" resume " + id + " \"" + path + " " + "$@\"" +
"\n"

fmt.Fprintf(f, code)
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

const (
VERSION = "alpha-1.4"
VERSION = "alpha-1.5"
)

func checkCompleteness() *Error {
Expand Down Expand Up @@ -469,6 +469,7 @@ func main() {
}
dockerRunCmd.Flags().StringVarP(&DockerRunVolume, "volume", "v", "", "optional")

var DockerDeletePermernant bool
var dockerDeleteCmd = &cobra.Command{
Use: "delete",
Short: "delete the local docker images",
Expand All @@ -482,7 +483,7 @@ func main() {
}
},
Run: func(cmd *cobra.Command, args []string) {
err := DockerDelete(args[0])
err := DockerDelete(args[0], DockerDeletePermernant)
if err != nil {
LOGGER.Fatal(err.Error())
return
Expand All @@ -492,6 +493,7 @@ func main() {
}
},
}
dockerDeleteCmd.Flags().BoolVarP(&DockerDeletePermernant, "permernant", "p", false, "permernantly delete all layers of the target image(optional)")

var dockerSearchCmd = &cobra.Command{
Use: "search",
Expand Down Expand Up @@ -629,6 +631,7 @@ func main() {
dockerCmd.AddCommand(dockerCreateCmd, dockerSearchCmd, dockerListCmd, dockerDeleteCmd, dockerDownloadCmd, dockerResetCmd, dockerPackageCmd, dockerAddCmd, dockerCommitCmd, dockerLoadCmd, dockerRunCmd)

var ExposeId string
var ExposePath string
var ExposeName string
var exposeCmd = &cobra.Command{
Use: "expose",
Expand All @@ -643,7 +646,7 @@ func main() {
}
},
Run: func(cmd *cobra.Command, args []string) {
err := Expose(ExposeId, ExposeName)
err := Expose(ExposeId, ExposePath, ExposeName)
if err != nil {
LOGGER.Fatal(err.Error())
return
Expand All @@ -655,6 +658,8 @@ func main() {
}
exposeCmd.Flags().StringVarP(&ExposeId, "id", "i", "", "required")
exposeCmd.MarkFlagRequired("id")
exposeCmd.Flags().StringVarP(&ExposePath, "path", "p", "", "required")
exposeCmd.MarkFlagRequired("path")
exposeCmd.Flags().StringVarP(&ExposeName, "name", "n", "", "required")
exposeCmd.MarkFlagRequired("name")

Expand Down

0 comments on commit b6e12ef

Please sign in to comment.