grim/convey

7a65a06a16c3
Parents 69f1af8c771f
Children 18b7a8f77329
Add a docker/tag task that wrap the podman/tag task
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docker/tag.go Mon Oct 11 02:09:05 2021 -0500
@@ -0,0 +1,49 @@
+package docker
+
+import (
+ "fmt"
+
+ log "github.com/sirupsen/logrus"
+
+ "keep.imfreedom.org/grim/convey/environment"
+ "keep.imfreedom.org/grim/convey/podman"
+ "keep.imfreedom.org/grim/convey/runtime"
+ "keep.imfreedom.org/grim/convey/tasks"
+ "keep.imfreedom.org/grim/convey/yaml"
+)
+
+type Tag struct {
+ Source string `yaml:"source"`
+ Destination string `yaml:"destination"`
+ Destinations yaml.StringOrSlice `yaml:"destinations"`
+
+ realTag *podman.Tag
+}
+
+// New creates a new Tag task.
+func (t *Tag) New() tasks.Task {
+ return &Tag{}
+}
+
+// Valid validates the Tag task.
+func (t *Tag) Valid() error {
+ if t.Destination != "" {
+ t.Destinations = append([]string{t.Destination}, t.Destinations...)
+ }
+
+ t.realTag = &podman.Tag{
+ Image: t.Source,
+ Targets: t.Destinations,
+ }
+
+ return t.realTag.Valid()
+}
+
+// Executes the task
+func (t *Tag) Execute(name string, logger *log.Entry, env environment.Environment, rt *runtime.Runtime) error {
+ return t.realTag.Execute(name, logger, env, rt)
+}
+
+func (t *Tag) Deprecated() error {
+ return fmt.Errorf("docker/tag has been deprecated in favor of podman/tag since 0.15.0")
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docker/tag_test.go Mon Oct 11 02:09:05 2021 -0500
@@ -0,0 +1,66 @@
+package docker
+
+import (
+ "testing"
+
+ . "github.com/onsi/gomega"
+
+ "keep.imfreedom.org/grim/convey/podman"
+ "keep.imfreedom.org/grim/convey/yaml"
+)
+
+func TestTagSingleDestination(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ tag := Tag{
+ Source: "foo",
+ Destination: "bar",
+ }
+
+ g.Expect(tag.Valid()).To(BeNil())
+ g.Expect(tag.Destinations).To(Equal(yaml.StringOrSlice{"bar"}))
+}
+
+func TestTagMultipleDestinations(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ tag := Tag{
+ Source: "foo",
+ Destinations: []string{"bar", "baz"},
+ }
+
+ g.Expect(tag.Valid()).To(BeNil())
+}
+
+func TestTagMergedDestinations(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ tag := Tag{
+ Source: "foo",
+ Destination: "bar",
+ Destinations: []string{"baz"},
+ }
+
+ g.Expect(tag.Valid()).To(BeNil())
+ g.Expect(tag.Destinations).To(Equal(yaml.StringOrSlice{"bar", "baz"}))
+}
+
+func TestTagSourceRequired(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ tag := Tag{
+ Destination: "bar",
+ }
+
+ g.Expect(tag.Valid()).To(MatchError(podman.ErrNoImage))
+}
+
+func TestTagDestinationsRequired(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ tag := Tag{
+ Source: "foo",
+ }
+
+ g.Expect(tag.Valid()).To(MatchError(podman.ErrNoTargets))
+}
--- a/docker/tasks.go Mon Oct 11 01:58:18 2021 -0500
+++ b/docker/tasks.go Mon Oct 11 02:09:05 2021 -0500
@@ -14,6 +14,6 @@
"docker/pull": &Pull{},
"docker/push": &Push{},
"docker/remove": &Remove{},
- // "docker/run": &Run{},
+ "docker/tag": &Tag{},
}
)