Skip to content

Commit

Permalink
feat: add nydusify commit command
Browse files Browse the repository at this point in the history
add nydusify commit command to commit a nydus container into nydus image

Signed-off-by: YuQiang <y_q_email@163.com>
  • Loading branch information
PerseidMeteor committed Jan 24, 2024
1 parent 30671d2 commit 23518fd
Show file tree
Hide file tree
Showing 8 changed files with 1,112 additions and 5 deletions.
89 changes: 89 additions & 0 deletions contrib/nydusify/cmd/nydusify.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/checker"
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/checker/rule"
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/chunkdict/generator"
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/commiter"
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/converter"
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/copier"
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/packer"
Expand Down Expand Up @@ -1103,6 +1104,94 @@ func main() {
return copier.Copy(context.Background(), opt)
},
},
{
Name: "commit",
Usage: "Commit a container into nydus image based a nydus image",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "work-dir",
Value: "./tmp",
Usage: "Working directory for image conversion",
EnvVars: []string{"WORK_DIR"},
},
&cli.StringFlag{
Name: "nydus-image",
Value: "nydus-image",
Usage: "Path to the nydus-image binary, default to search in PATH",
EnvVars: []string{"NYDUS_IMAGE"},
},
&cli.StringFlag{
Name: "containerd-address",
Value: "/run/containerd/containerd.sock",
Usage: "Socket listener address of containerd",
EnvVars: []string{"CONTAINERD_ADDR"},
},
&cli.StringFlag{
Name: "container",
Required: true,
Usage: "Target container id",
EnvVars: []string{"CONTAINER"},
},
&cli.StringFlag{
Name: "target",
Required: true,
Usage: "Target nydus image reference",
EnvVars: []string{"TARGET"},
},
&cli.IntFlag{
Name: "maximum-times",
Required: false,
DefaultText: "400",
Value: 400,
Usage: "The maximum times allowed to be committed",
EnvVars: []string{"MAXIMUM_TIMES"},
},
&cli.StringSliceFlag{
Name: "with-path",
Aliases: []string{"with-mount-path"},
Required: false,
Usage: "The directory that need to be committed",
EnvVars: []string{"WITH_PATH"},
},
},
Action: func(c *cli.Context) error {
setupLogLevel(c)
parsePaths := func(c *cli.Context, paths []string) ([]string, []string) {
withPaths := []string{}
withoutPaths := []string{}

for _, path := range paths {
path = strings.TrimSpace(path)
if strings.HasPrefix(path, "!") {
path = strings.TrimLeft(path, "!")
path = strings.TrimRight(path, "/")
withoutPaths = append(withoutPaths, path)
} else {
withPaths = append(withPaths, path)
}
}

return withPaths, withoutPaths
}

withPaths, withoutPaths := parsePaths(c, c.StringSlice("with-path"))
opt := commiter.Opt {
WorkDir: c.String("work-dir"),
NydusImagePath: c.String("nydus-image"),
ContainerdAddress: c.String("containerd-address"),
ContainerID: c.String("container"),
TargetRef: c.String("target"),
MaximumTimes: c.Int("maximum-times"),
WithPaths: withPaths,
WithoutPaths: withoutPaths,
}
cm, err := commiter.NewCommiter(opt)
if err != nil {
return errors.Wrap(err, "create commiter")
}
return cm.Commit(context.Background(), opt)
},
},
}

if !utils.IsSupportedArch(runtime.GOARCH) {
Expand Down
11 changes: 6 additions & 5 deletions contrib/nydusify/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ module github.com/dragonflyoss/nydus/contrib/nydusify
go 1.21

require (
github.com/Microsoft/hcsshim v0.11.4
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/aws/aws-sdk-go-v2 v1.24.0
github.com/aws/aws-sdk-go-v2/config v1.26.2
github.com/aws/aws-sdk-go-v2/credentials v1.16.13
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.9
github.com/aws/aws-sdk-go-v2/service/s3 v1.47.7
github.com/containerd/containerd v1.7.11
github.com/containerd/continuity v0.4.3
github.com/containerd/log v0.1.0
github.com/containerd/nydus-snapshotter v0.13.4
github.com/distribution/reference v0.5.0
github.com/docker/cli v24.0.7+incompatible
Expand All @@ -18,6 +21,9 @@ require (
github.com/google/uuid v1.5.0
github.com/hashicorp/go-hclog v1.6.2
github.com/hashicorp/go-plugin v1.6.0
github.com/klauspost/compress v1.17.4
github.com/moby/buildkit v0.12.4
github.com/moby/sys/sequential v0.5.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/pkg/errors v0.9.1
Expand All @@ -35,7 +41,6 @@ require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20231105174938-2b5cbb29f3e2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect
Expand All @@ -53,9 +58,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/containerd/fifo v1.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/stargz-snapshotter v0.15.1 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/containerd/ttrpc v1.2.2 // indirect
Expand All @@ -77,7 +80,6 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -86,7 +88,6 @@ require (
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/runc v1.1.11 // indirect
Expand Down
2 changes: 2 additions & 0 deletions contrib/nydusify/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU=
github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/moby/buildkit v0.12.4 h1:yKZDsObXLKarXqUx7YMnaB+TKv810bBhq0XLFWbkjT0=
github.com/moby/buildkit v0.12.4/go.mod h1:XG74uz06nPWQpnxYwgCryrVidvor0+ElUxGosbZPQG4=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g=
Expand Down
Loading

0 comments on commit 23518fd

Please sign in to comment.