diff --git a/examples/docker/main.go b/examples/docker/main.go index 3bc98c5..30319d6 100644 --- a/examples/docker/main.go +++ b/examples/docker/main.go @@ -1,46 +1,7 @@ package main -import ( - "fmt" - - "github.com/ftlops/ftl" - "github.com/ftlops/ftl/ops" -) +import "github.com/ftlops/ftl/plans/docker" func main() { - ftl.Step("install docker", func() ftl.State { - if !ops.MissingPackage("docker-ce") { - return ftl.StateUnchanged - } - - ftl.Step("install prereqs", func() ftl.State { - prereqs := []string{ - "apt-transport-https", - "ca-certificates", - "gnupg", - "lsb-release", - } - missing := ops.MissingPackages(prereqs...) - if len(missing) == 0 { - return ftl.StateUnchanged - } - - ops.UpdateRepos() - ops.Install(missing...) - return ftl.StateChanged - }) - - ftl.Step("add repo", func() ftl.State { - codename := ops.DistroCodename() - repo := fmt.Sprintf("deb [arch=amd64] https://download.docker.com/linux/ubuntu %s stable", codename) - if !ops.MissingRepo(repo) { - return ftl.StateUnchanged - } - ops.AddRepo(repo, "https://download.docker.com/linux/ubuntu/gpg") - return ftl.StateChanged - }) - - ops.Install("docker-ce") - return ftl.StateChanged - }) + docker.Install() } diff --git a/plans/docker/install.go b/plans/docker/install.go new file mode 100644 index 0000000..a146058 --- /dev/null +++ b/plans/docker/install.go @@ -0,0 +1,46 @@ +package docker + +import ( + "fmt" + + "github.com/ftlops/ftl" + "github.com/ftlops/ftl/ops" +) + +func Install() { + ftl.Step("install docker", func() ftl.State { + if !ops.MissingPackage("docker-ce") { + return ftl.StateUnchanged + } + + ftl.Step("install prereqs", func() ftl.State { + prereqs := []string{ + "apt-transport-https", + "ca-certificates", + "gnupg", + "lsb-release", + } + missing := ops.MissingPackages(prereqs...) + if len(missing) == 0 { + return ftl.StateUnchanged + } + + ops.UpdateRepos() + ops.Install(missing...) + return ftl.StateChanged + }) + + ftl.Step("add repo", func() ftl.State { + codename := ops.DistroCodename() + repo := fmt.Sprintf("deb [arch=amd64] https://download.docker.com/linux/ubuntu %s stable", codename) + if !ops.MissingRepo(repo) { + return ftl.StateUnchanged + } + ops.AddRepo(repo, "https://download.docker.com/linux/ubuntu/gpg") + return ftl.StateChanged + }) + + ops.Install("docker-ce") + return ftl.StateChanged + }) +}