Skip to content

Commit

Permalink
Introduce prebuild plans
Browse files Browse the repository at this point in the history
  • Loading branch information
ngrash committed Apr 5, 2021
1 parent a9e8cb8 commit cae875f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
43 changes: 2 additions & 41 deletions examples/docker/main.go
Original file line number Diff line number Diff line change
@@ -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()
}
46 changes: 46 additions & 0 deletions plans/docker/install.go
Original file line number Diff line number Diff line change
@@ -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
})
}

0 comments on commit cae875f

Please sign in to comment.