grim/convey

More golint cleanups

2018-01-13, Gary Kramlich
5950f37a050a
Parents f92879e96f9e
Children b9977ab51bfe
More golint cleanups
--- a/docker/build.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/build.go Sat Jan 13 00:31:17 2018 -0600
@@ -29,6 +29,7 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Build defines the options for building a docker image.
type Build struct {
Dockerfile string `yaml:"dockerfile"`
Files yaml.StringOrSlice `yaml:"files"`
@@ -47,6 +48,7 @@
{{if .Target}} --target {{.Target}}{{end}}
{{.buildContext}}`
+// Execute runs the docker build command
func (b *Build) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -121,10 +123,12 @@
return Docker(name, buildTemplate, params, st)
}
+// New creates a new docker build task.
func (b *Build) New() tasks.Task {
return &Build{}
}
+// Valid checks that the build task is valid.
func (b *Build) Valid() error {
if b.Dockerfile == "" {
return errNoDockerFile
--- a/docker/docker.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/docker.go Sat Jan 13 00:31:17 2018 -0600
@@ -24,6 +24,7 @@
)
var (
+ // Tasks is a map of all docker tasks.
Tasks = map[string]tasks.Task{
"build": &Build{},
"export": &Export{},
@@ -41,6 +42,7 @@
dockerTemplate = `docker {{if .DockerConfig}}--config {{.DockerConfig}} {{end}}`
)
+// Docker runs a docker command.
func Docker(name, template string, params map[string]interface{}, st *state.State) error {
fullTemplate := dockerTemplate + template
params["DockerConfig"] = st.DockerConfig
@@ -48,6 +50,8 @@
return command.Run(name, fullTemplate, params, st.PlanTimeout)
}
+// DockerOutput runs a docker command but returns the output rather than
+// outputting to the logger.
func DockerOutput(name, template string, params map[string]interface{}, st *state.State) (string, string, error) {
fullTemplate := dockerTemplate + template
params["DockerConfig"] = st.DockerConfig
--- a/docker/environment.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/environment.go Sat Jan 13 00:31:17 2018 -0600
@@ -31,12 +31,15 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Environment contains options for loading environment variables from a file
+// in the workspace.
type Environment struct {
File string `yaml:"from-file"`
Files yaml.StringOrSlice `yaml:"from-files"`
Prefix string `yaml:"prefix"`
}
+// Execute runs the environment plan.
func (e *Environment) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -129,10 +132,12 @@
return entries, nil
}
+// New creates a new environment command.
func (e *Environment) New() tasks.Task {
return &Environment{}
}
+// Valid validate the environment command.
func (e *Environment) Valid() error {
if e.File != "" {
e.Files = append([]string{e.File}, e.Files...)
--- a/docker/export.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/export.go Sat Jan 13 00:31:17 2018 -0600
@@ -31,6 +31,8 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Export represents an export task which exports files from the workspace to
+// the host.
type Export struct {
Files yaml.StringOrSlice `yaml:"files"`
}
@@ -83,6 +85,7 @@
return nil
}
+// Execute runs the export task.
func (e *Export) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -125,10 +128,12 @@
return nil
}
+// New creates a new Export task.
func (e *Export) New() tasks.Task {
return &Export{}
}
+// Valid validates the export task.
func (e *Export) Valid() error {
if len(e.Files) == 0 {
return errNoFiles
--- a/docker/healthcheck.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/healthcheck.go Sat Jan 13 00:31:17 2018 -0600
@@ -25,6 +25,7 @@
"bitbucket.org/rw_grim/convey/state"
)
+// HealthCheck represents a docker health check.
type HealthCheck struct {
Command string `yaml:"command"`
Interval time.Duration `yaml:"interval"`
--- a/docker/import.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/import.go Sat Jan 13 00:31:17 2018 -0600
@@ -26,12 +26,15 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Import represents an import task which imports files from the host to the
+// workspace.
type Import struct {
Files yaml.StringOrSlice `yaml:"files"`
}
const importTemplate = `cp {{.source}} {{.workspaceID}}:/workspace/{{.destination}}`
+// Execute runs the import task.
func (i *Import) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -68,10 +71,12 @@
return nil
}
+// New creates a new import task.
func (i *Import) New() tasks.Task {
return &Import{}
}
+// Valid validates the import task.
func (i *Import) Valid() error {
if len(i.Files) == 0 {
return errNoFiles
--- a/docker/login.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/login.go Sat Jan 13 00:31:17 2018 -0600
@@ -24,6 +24,7 @@
"bitbucket.org/rw_grim/convey/tasks"
)
+// Login represents an login task for logging into a docker registry.
type Login struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
@@ -32,6 +33,7 @@
const loginTemplate = `login -u {{.username}} -p {{.password}}{{if .server}} {{.server}}{{end}}`
+// Execute runs the login task.
func (l *Login) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -59,10 +61,12 @@
return Docker(name, loginTemplate, params, st)
}
+// New creates a new login task.
func (l *Login) New() tasks.Task {
return &Login{}
}
+// Valid validate the login task.
func (l *Login) Valid() error {
if l.Server == "" {
return errNoServer
--- a/docker/logout.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/logout.go Sat Jan 13 00:31:17 2018 -0600
@@ -24,12 +24,14 @@
"bitbucket.org/rw_grim/convey/tasks"
)
+// Logout represents a logout task which logs out of a docker registry.
type Logout struct {
Server string `yaml:"server"`
}
const logoutTemplate = `logout{{if .server}} {{.server}}{{end}}`
+// Execute runs the logout task.
func (l *Logout) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -45,10 +47,12 @@
return Docker(name, logoutTemplate, params, st)
}
+// New creates a new logout task.
func (l *Logout) New() tasks.Task {
return &Logout{}
}
+// Valid validates the logout task.
func (l *Logout) Valid() error {
if l.Server == "" {
return errNoServer
--- a/docker/network.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/network.go Sat Jan 13 00:31:17 2018 -0600
@@ -24,6 +24,7 @@
"bitbucket.org/rw_grim/convey/util"
)
+// Network represents a docker network.
type Network struct {
name string
@@ -37,6 +38,7 @@
networkDestroyTemplate = `network rm {{.Name}}`
)
+// NewNetwork creates a new docker network.
func NewNetwork(st *state.State) (*Network, error) {
network := &Network{
name: util.ID(),
@@ -58,10 +60,12 @@
return network, nil
}
+// Name returns the name of the network.
func (network *Network) Name() string {
return network.name
}
+// Destroy tears down the docker network.
func (network *Network) Destroy() error {
for _, name := range network.state.GetRunning() {
params := map[string]interface{}{
--- a/docker/pull.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/pull.go Sat Jan 13 00:31:17 2018 -0600
@@ -25,6 +25,8 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Pull represents a docker pull task which pulls an image from a docker
+// registry.
type Pull struct {
Image string `yaml:"image"`
Images yaml.StringOrSlice `yaml:"images"`
@@ -32,6 +34,7 @@
const pullTemplate = `pull {{.image}}`
+// Execute runs the pull task.
func (p *Pull) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -53,10 +56,12 @@
return nil
}
+// New creates a new pull task.
func (p *Pull) New() tasks.Task {
return &Pull{}
}
+// Valid validates the pull task.
func (p *Pull) Valid() error {
if p.Image != "" {
p.Images = append([]string{p.Image}, p.Images...)
--- a/docker/push.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/push.go Sat Jan 13 00:31:17 2018 -0600
@@ -25,6 +25,7 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Push represents a docker push task which push an image to a docker registry.
type Push struct {
Image string `yaml:"image"`
Images yaml.StringOrSlice `yaml:"images"`
@@ -32,6 +33,7 @@
const pushTemplate = `push {{.image}}`
+// Execute runs the push task.
func (p *Push) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -53,10 +55,12 @@
return nil
}
+// New creates a new push task.
func (p *Push) New() tasks.Task {
return &Push{}
}
+// Valid validates the push task.
func (p *Push) Valid() error {
if p.Image != "" {
p.Images = append([]string{p.Image}, p.Images...)
--- a/docker/remove.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/remove.go Sat Jan 13 00:31:17 2018 -0600
@@ -27,6 +27,7 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Remove represents a docker rm task which deletes a local docker image.
type Remove struct {
Image string `yaml:"image"`
Images yaml.StringOrSlice `yaml:"images"`
@@ -35,6 +36,7 @@
const removeTemplate = `rmi {{.image}}`
+// Execute runs the remove task.
func (r *Remove) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -60,10 +62,12 @@
return nil
}
+// New creates a new remove task.
func (r *Remove) New() tasks.Task {
return &Remove{}
}
+// Valid validates the remove task.
func (r *Remove) Valid() error {
if r.Image != "" {
r.Images = append([]string{r.Image}, r.Images...)
--- a/docker/run.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/run.go Sat Jan 13 00:31:17 2018 -0600
@@ -35,6 +35,7 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Run represents a docker run task which will run a container.
type Run struct {
Command string `yaml:"command"`
Detach bool `yaml:"detach"`
@@ -51,6 +52,7 @@
HealthCheck HealthCheck `yaml:"healthcheck"`
}
+// UnmarshalYAML is a custom yaml unmarshaller for run tasks.
func (r *Run) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawRun Run
raw := rawRun{Shell: "/bin/sh", HealthCheck: HealthCheck{}}
@@ -126,6 +128,7 @@
return scriptFile, entryPoint, commandArg, nil
}
+// Execute runs the run task.
func (r *Run) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, r.Environment)
fullEnv = environment.Merge(fullEnv, st.GetEnv())
@@ -337,10 +340,12 @@
return Docker(name, runTemplate, params, st)
}
+// New creates a new run task.
func (r *Run) New() tasks.Task {
return &Run{}
}
+// Valid validates the run task.
func (r *Run) Valid() error {
if r.Image == "" {
return errNoImage
--- a/docker/tag.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/tag.go Sat Jan 13 00:31:17 2018 -0600
@@ -25,6 +25,7 @@
"bitbucket.org/rw_grim/convey/yaml"
)
+// Tag represents a docker tag command.
type Tag struct {
Source string `yaml:"source"`
Destination string `yaml:"destination"`
@@ -33,6 +34,7 @@
const tagTemplate = `tag {{.source}} {{.destination}}`
+// Execute runs the execute task.
func (t *Tag) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error {
fullEnv := environment.Merge(env, st.GetEnv())
@@ -60,10 +62,12 @@
return nil
}
+// New creates a new docker tag task.
func (t *Tag) New() tasks.Task {
return &Tag{}
}
+// Valid validates the tag task.
func (t *Tag) Valid() error {
if t.Source == "" {
return errNoSourceTag
--- a/docker/workspace.go Sat Jan 13 00:00:58 2018 -0600
+++ b/docker/workspace.go Sat Jan 13 00:31:17 2018 -0600
@@ -26,6 +26,7 @@
"bitbucket.org/rw_grim/convey/util"
)
+// Workspace represents a docker workspace.
type Workspace struct {
name string
volumeName string
@@ -60,6 +61,7 @@
return nil
}
+// NewWorkspace creates a new docker workspace.
func NewWorkspace(st *state.State) (*Workspace, error) {
ws := &Workspace{
name: util.ID(),
@@ -88,10 +90,12 @@
return ws, nil
}
+// Name returns the name of the docker workspace.
func (ws *Workspace) Name() string {
return ws.name
}
+// Destroy removes the docker workspace.
func (ws *Workspace) Destroy() error {
params := map[string]interface{}{
"Name": ws.name,