2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2025-06-23 22:02:25 +00:00

feat: add --raw image creation support

refactor: use Option func pattern
fix: build respect the --force flag
fix: compute correct in-docker input and outpout mount paths

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2022-09-06 18:43:24 +02:00
parent eb36d45c35
commit 480cae12cf
6 changed files with 199 additions and 35 deletions

View File

@ -62,6 +62,19 @@ func Build(ctx context.Context, tag, dockerfile, dir string, buildArgs ...string
return Cmd(ctx, args...)
}
func Tag(ctx context.Context, img string, tags ...string) error {
if len(tags) == 0 {
return fmt.Errorf("no tags specified")
}
args := []string{"image", "tag"}
for _, tag := range tags {
if err := Cmd(ctx, append(args, img, tag)...); err != nil {
return err
}
}
return nil
}
func Remove(ctx context.Context, tag string) error {
return Cmd(ctx, "image", "rm", tag)
}
@ -97,11 +110,17 @@ func RunAndRemove(ctx context.Context, args ...string) error {
return Cmd(ctx, append([]string{"run", "--rm"}, args...)...)
}
func RunD2VM(ctx context.Context, image, version, cmd string, args ...string) error {
func RunD2VM(ctx context.Context, image, version, in, out, cmd string, args ...string) error {
pwd, err := os.Getwd()
if err != nil {
return err
}
if in == "" {
in = pwd
}
if out == "" {
out = pwd
}
if image == "" {
image = "linkacloud/d2vm"
}
@ -113,7 +132,9 @@ func RunD2VM(ctx context.Context, image, version, cmd string, args ...string) er
"-v",
fmt.Sprintf("%s:/var/run/docker.sock", dockerSocket()),
"-v",
fmt.Sprintf("%s:/d2vm", pwd),
fmt.Sprintf("%s:/in", in),
"-v",
fmt.Sprintf("%s:/out", out),
"-w",
"/d2vm",
fmt.Sprintf("%s:%s", image, version),