aboutsummaryrefslogtreecommitdiff
path: root/libpod/options.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-05-01 12:08:52 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-03 12:23:12 +0000
commitab7e2a695633dbe45b0af3332b813b0efdfbf203 (patch)
tree74de1a9b76fbc3ab628f083561ed60c2576836be /libpod/options.go
parent16c997de624be049dda5d2182ec70d979194b002 (diff)
downloadpodman-ab7e2a695633dbe45b0af3332b813b0efdfbf203.tar.gz
podman-ab7e2a695633dbe45b0af3332b813b0efdfbf203.tar.bz2
podman-ab7e2a695633dbe45b0af3332b813b0efdfbf203.zip
Store user Volumes, Entrypoint, Command in database
We need these for commit, and they cannot be properly deduced from just the OCI spec, so save them in the database so we can retrieve them for commit. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #700 Approved by: rhatdan
Diffstat (limited to 'libpod/options.go')
-rw-r--r--libpod/options.go62
1 files changed, 57 insertions, 5 deletions
diff --git a/libpod/options.go b/libpod/options.go
index 968507906..101ff9833 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -821,15 +821,67 @@ func WithGroups(groups []string) CtrCreateOption {
}
}
-// WithUserVolumes informs libpod that the container has user-added volumes.
-// It is used to for triggering hooks that check for the presence of volume
-// mounts.
-func WithUserVolumes() CtrCreateOption {
+// WithUserVolumes sets the user-added volumes of the container.
+// These are not added to the container's spec, but will instead be used during
+// commit to populate the volumes of the new image, and to trigger some OCI
+// hooks that are only added if volume mounts are present.
+// Unless explicitly set, committed images will have no volumes.
+// The given volumes slice must not be nil.
+func WithUserVolumes(volumes []string) CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
return ErrCtrFinalized
}
- ctr.config.UserVolumes = true
+
+ if volumes == nil {
+ return ErrInvalidArg
+ }
+
+ ctr.config.UserVolumes = make([]string, 0, len(volumes))
+ for _, vol := range volumes {
+ ctr.config.UserVolumes = append(ctr.config.UserVolumes, vol)
+ }
+
+ return nil
+ }
+}
+
+// WithEntrypoint sets the entrypoint of the container.
+// This is not used to change the container's spec, but will instead be used
+// during commit to populate the entrypoint of the new image.
+// If not explicitly set it will default to the image's entrypoint.
+// A nil entrypoint is allowed, and will clear entrypoint on the created image.
+func WithEntrypoint(entrypoint []string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ ctr.config.Entrypoint = make([]string, 0, len(entrypoint))
+ for _, str := range entrypoint {
+ ctr.config.Entrypoint = append(ctr.config.Entrypoint, str)
+ }
+
+ return nil
+ }
+}
+
+// WithCommand sets the command of the container.
+// This is not used to change the container's spec, but will instead be used
+// during commit to populate the command of the new image.
+// If not explicitly set it will default to the image's command.
+// A nil command is allowed, and will clear command on the created image.
+func WithCommand(command []string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+
+ ctr.config.Command = make([]string, 0, len(command))
+ for _, str := range command {
+ ctr.config.Command = append(ctr.config.Command, str)
+ }
+
return nil
}
}