diff options
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/generate/types.go | 2 | ||||
-rw-r--r-- | pkg/bindings/generate/types_systemd_options.go | 15 | ||||
-rw-r--r-- | pkg/bindings/images/build.go | 59 | ||||
-rw-r--r-- | pkg/bindings/test/attach_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/auth_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/common_test.go | 4 | ||||
-rw-r--r-- | pkg/bindings/test/connection_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/containers_test.go | 3 | ||||
-rw-r--r-- | pkg/bindings/test/create_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/exec_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/generator_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/images_test.go | 13 | ||||
-rw-r--r-- | pkg/bindings/test/info_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/manifests_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/networks_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/pods_test.go | 6 | ||||
-rw-r--r-- | pkg/bindings/test/resource_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/secrets_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/system_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/test_suite_test.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/volumes_test.go | 2 |
21 files changed, 111 insertions, 19 deletions
diff --git a/pkg/bindings/generate/types.go b/pkg/bindings/generate/types.go index 092474e4a..ce560c547 100644 --- a/pkg/bindings/generate/types.go +++ b/pkg/bindings/generate/types.go @@ -20,6 +20,8 @@ type SystemdOptions struct { TemplateUnitFile *bool // RestartPolicy - systemd restart policy. RestartPolicy *string + // RestartSec - systemd service restartsec. Configures the time to sleep before restarting a service. + RestartSec *uint // StartTimeout - time when starting the container. StartTimeout *uint // StopTimeout - time when stopping the container. diff --git a/pkg/bindings/generate/types_systemd_options.go b/pkg/bindings/generate/types_systemd_options.go index d60f1d70e..504d4da7f 100644 --- a/pkg/bindings/generate/types_systemd_options.go +++ b/pkg/bindings/generate/types_systemd_options.go @@ -92,6 +92,21 @@ func (o *SystemdOptions) GetRestartPolicy() string { return *o.RestartPolicy } +// WithRestartSec set field RestartSec to given value +func (o *SystemdOptions) WithRestartSec(value uint) *SystemdOptions { + o.RestartSec = &value + return o +} + +// GetRestartSec returns value of field RestartSec +func (o *SystemdOptions) GetRestartSec() uint { + if o.RestartSec == nil { + var z uint + return z + } + return *o.RestartSec +} + // WithStartTimeout set field StartTimeout to given value func (o *SystemdOptions) WithStartTimeout(value uint) *SystemdOptions { o.StartTimeout = &value diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 3b0bebe9f..be6e5ab55 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "context" "encoding/json" + "fmt" "io" "io/ioutil" "net/http" @@ -345,6 +346,11 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } c = tmpFile.Name() } + cfDir := filepath.Dir(c) + if absDir, err := filepath.EvalSymlinks(cfDir); err == nil { + name := filepath.ToSlash(strings.TrimPrefix(c, cfDir+string(filepath.Separator))) + c = filepath.Join(absDir, name) + } containerfile, err := filepath.Abs(c) if err != nil { logrus.Errorf("Cannot find absolute path of %v: %v", c, err) @@ -377,6 +383,59 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } params.Set("dockerfile", string(cFileJSON)) } + + // build secrets are usually absolute host path or relative to context dir on host + // in any case move secret to current context and ship the tar. + if secrets := options.CommonBuildOpts.Secrets; len(secrets) > 0 { + secretsForRemote := []string{} + + for _, secret := range secrets { + secretOpt := strings.Split(secret, ",") + if len(secretOpt) > 0 { + modifiedOpt := []string{} + for _, token := range secretOpt { + arr := strings.SplitN(token, "=", 2) + if len(arr) > 1 { + if arr[0] == "src" { + // read specified secret into a tmp file + // move tmp file to tar and change secret source to relative tmp file + tmpSecretFile, err := ioutil.TempFile(options.ContextDirectory, "podman-build-secret") + if err != nil { + return nil, err + } + defer os.Remove(tmpSecretFile.Name()) // clean up + defer tmpSecretFile.Close() + srcSecretFile, err := os.Open(arr[1]) + if err != nil { + return nil, err + } + defer srcSecretFile.Close() + _, err = io.Copy(tmpSecretFile, srcSecretFile) + if err != nil { + return nil, err + } + + //add tmp file to context dir + tarContent = append(tarContent, tmpSecretFile.Name()) + + modifiedSrc := fmt.Sprintf("src=%s", filepath.Base(tmpSecretFile.Name())) + modifiedOpt = append(modifiedOpt, modifiedSrc) + } else { + modifiedOpt = append(modifiedOpt, token) + } + } + } + secretsForRemote = append(secretsForRemote, strings.Join(modifiedOpt[:], ",")) + } + } + + c, err := jsoniter.MarshalToString(secretsForRemote) + if err != nil { + return nil, err + } + params.Add("secrets", c) + } + tarfile, err := nTar(append(excludes, dontexcludes...), tarContent...) if err != nil { logrus.Errorf("Cannot tar container entries %v error: %v", tarContent, err) diff --git a/pkg/bindings/test/attach_test.go b/pkg/bindings/test/attach_test.go index 5c3ec48e4..c78836cb3 100644 --- a/pkg/bindings/test/attach_test.go +++ b/pkg/bindings/test/attach_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "bytes" diff --git a/pkg/bindings/test/auth_test.go b/pkg/bindings/test/auth_test.go index d48a3eff7..26690c46a 100644 --- a/pkg/bindings/test/auth_test.go +++ b/pkg/bindings/test/auth_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "io/ioutil" diff --git a/pkg/bindings/test/common_test.go b/pkg/bindings/test/common_test.go index 233666a48..76649f628 100644 --- a/pkg/bindings/test/common_test.go +++ b/pkg/bindings/test/common_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "context" @@ -51,7 +51,7 @@ var ( shortName: "busybox", tarballName: "busybox.tar", } - CACHE_IMAGES = []testImage{alpine, busybox} + CACHE_IMAGES = []testImage{alpine, busybox} //nolint:golint,stylecheck ) type bindingTest struct { diff --git a/pkg/bindings/test/connection_test.go b/pkg/bindings/test/connection_test.go index 561cf32b5..84a047bc9 100644 --- a/pkg/bindings/test/connection_test.go +++ b/pkg/bindings/test/connection_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "context" diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go index 0f535bc31..b6c06756b 100644 --- a/pkg/bindings/test/containers_test.go +++ b/pkg/bindings/test/containers_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "net/http" @@ -103,6 +103,7 @@ var _ = Describe("Podman containers ", func() { Expect(err).To(BeNil()) // Pause by name err = containers.Pause(bt.conn, name, nil) + Expect(err).To(BeNil(), "error from containers.Pause()") //paused := "paused" //_, err = containers.Wait(bt.conn, cid, &paused) //Expect(err).To(BeNil()) diff --git a/pkg/bindings/test/create_test.go b/pkg/bindings/test/create_test.go index 3c83aac02..f70ba7248 100644 --- a/pkg/bindings/test/create_test.go +++ b/pkg/bindings/test/create_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "time" diff --git a/pkg/bindings/test/exec_test.go b/pkg/bindings/test/exec_test.go index c10452eaf..d2f9b121a 100644 --- a/pkg/bindings/test/exec_test.go +++ b/pkg/bindings/test/exec_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "time" diff --git a/pkg/bindings/test/generator_test.go b/pkg/bindings/test/generator_test.go index d04cc10f9..ab0c49713 100644 --- a/pkg/bindings/test/generator_test.go +++ b/pkg/bindings/test/generator_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "github.com/containers/podman/v3/pkg/bindings/containers" diff --git a/pkg/bindings/test/images_test.go b/pkg/bindings/test/images_test.go index aa8ff0537..8489e6ff1 100644 --- a/pkg/bindings/test/images_test.go +++ b/pkg/bindings/test/images_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "net/http" @@ -89,6 +89,10 @@ var _ = Describe("Podman images", func() { response, errs := images.Remove(bt.conn, []string{"foobar5000"}, nil) Expect(len(errs)).To(BeNumerically(">", 0)) code, _ := bindings.CheckResponseCode(errs[0]) + // FIXME FIXME FIXME: #12441: THIS IS BROKEN + // FIXME FIXME FIXME: we get msg: "foobar5000: image not known" + // FIXME FIXME FIXME: ...with no ResponseCode + Expect(code).To(BeNumerically("==", -1)) // Remove an image by name, validate image is removed and error is nil inspectData, err := images.GetImage(bt.conn, busybox.shortName, nil) @@ -99,6 +103,7 @@ var _ = Describe("Podman images", func() { Expect(inspectData.ID).To(Equal(response.Deleted[0])) inspectData, err = images.GetImage(bt.conn, busybox.shortName, nil) code, _ = bindings.CheckResponseCode(err) + Expect(code).To(BeNumerically("==", http.StatusNotFound)) // Start a container with alpine image var top string = "top" @@ -113,6 +118,9 @@ var _ = Describe("Podman images", func() { // deleting hence image cannot be deleted until the container is deleted. response, errs = images.Remove(bt.conn, []string{alpine.shortName}, nil) code, _ = bindings.CheckResponseCode(errs[0]) + // FIXME FIXME FIXME: #12441: another invalid error + // FIXME FIXME FIXME: this time msg="Image used by SHA: ..." + Expect(code).To(BeNumerically("==", -1)) // Removing the image "alpine" where force = true options := new(images.RemoveOptions).WithForce(true) @@ -122,10 +130,12 @@ var _ = Describe("Podman images", func() { // is gone as well. _, err = containers.Inspect(bt.conn, "top", nil) code, _ = bindings.CheckResponseCode(err) + Expect(code).To(BeNumerically("==", http.StatusNotFound)) // Now make sure both images are gone. inspectData, err = images.GetImage(bt.conn, busybox.shortName, nil) code, _ = bindings.CheckResponseCode(err) + Expect(code).To(BeNumerically("==", http.StatusNotFound)) inspectData, err = images.GetImage(bt.conn, alpine.shortName, nil) code, _ = bindings.CheckResponseCode(err) @@ -339,6 +349,7 @@ var _ = Describe("Podman images", func() { // Search with a fqdn reports, err = images.Search(bt.conn, "quay.io/libpod/alpine_nginx", nil) + Expect(err).To(BeNil(), "Error in images.Search()") Expect(len(reports)).To(BeNumerically(">=", 1)) }) diff --git a/pkg/bindings/test/info_test.go b/pkg/bindings/test/info_test.go index f61e8c370..f643a2c28 100644 --- a/pkg/bindings/test/info_test.go +++ b/pkg/bindings/test/info_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "runtime" diff --git a/pkg/bindings/test/manifests_test.go b/pkg/bindings/test/manifests_test.go index 4d8ca74bf..e65632057 100644 --- a/pkg/bindings/test/manifests_test.go +++ b/pkg/bindings/test/manifests_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "net/http" diff --git a/pkg/bindings/test/networks_test.go b/pkg/bindings/test/networks_test.go index 85ceeb998..d95862f6f 100644 --- a/pkg/bindings/test/networks_test.go +++ b/pkg/bindings/test/networks_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "context" diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go index 879d4d00d..0a4261ea2 100644 --- a/pkg/bindings/test/pods_test.go +++ b/pkg/bindings/test/pods_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "fmt" @@ -79,6 +79,7 @@ var _ = Describe("Podman pods", func() { var newpod2 string = "newpod2" bt.Podcreate(&newpod2) podSummary, err = pods.List(bt.conn, nil) + Expect(err).To(BeNil(), "Error from pods.List") Expect(len(podSummary)).To(Equal(2)) var names []string for _, i := range podSummary { @@ -106,6 +107,7 @@ var _ = Describe("Podman pods", func() { options := new(pods.ListOptions).WithFilters(filters) filteredPods, err := pods.List(bt.conn, options) Expect(err).ToNot(BeNil()) + Expect(len(filteredPods)).To(Equal(0), "len(filteredPods)") code, _ := bindings.CheckResponseCode(err) Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) @@ -301,6 +303,7 @@ var _ = Describe("Podman pods", func() { // No pods pruned since no pod in exited state pruneResponse, err := pods.Prune(bt.conn, nil) Expect(err).To(BeNil()) + Expect(len(pruneResponse)).To(Equal(0), "len(pruneResponse)") podSummary, err := pods.List(bt.conn, nil) Expect(err).To(BeNil()) Expect(len(podSummary)).To(Equal(2)) @@ -317,6 +320,7 @@ var _ = Describe("Podman pods", func() { Expect(response.State).To(Equal(define.PodStateExited)) pruneResponse, err = pods.Prune(bt.conn, nil) Expect(err).To(BeNil()) + Expect(len(pruneResponse)).To(Equal(1), "len(pruneResponse)") // Validate status and record pod id of pod to be pruned Expect(response.State).To(Equal(define.PodStateExited)) podID := response.ID diff --git a/pkg/bindings/test/resource_test.go b/pkg/bindings/test/resource_test.go index b12d1ccd6..19ac33eb2 100644 --- a/pkg/bindings/test/resource_test.go +++ b/pkg/bindings/test/resource_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "context" diff --git a/pkg/bindings/test/secrets_test.go b/pkg/bindings/test/secrets_test.go index 5edb37f18..52c964556 100644 --- a/pkg/bindings/test/secrets_test.go +++ b/pkg/bindings/test/secrets_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "context" diff --git a/pkg/bindings/test/system_test.go b/pkg/bindings/test/system_test.go index aecc5db81..4549a14c9 100644 --- a/pkg/bindings/test/system_test.go +++ b/pkg/bindings/test/system_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "sync" diff --git a/pkg/bindings/test/test_suite_test.go b/pkg/bindings/test/test_suite_test.go index d2c2c7838..8fb46c205 100644 --- a/pkg/bindings/test/test_suite_test.go +++ b/pkg/bindings/test/test_suite_test.go @@ -1,4 +1,4 @@ -package test_bindings_test +package bindings_test import ( "testing" diff --git a/pkg/bindings/test/volumes_test.go b/pkg/bindings/test/volumes_test.go index 14bda114e..43ef54889 100644 --- a/pkg/bindings/test/volumes_test.go +++ b/pkg/bindings/test/volumes_test.go @@ -1,4 +1,4 @@ -package test_bindings +package bindings_test import ( "context" |