Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
make lint && satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Bogdanov committed Sep 17, 2015
1 parent f63d9e1 commit 9f05fa5
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 209 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ gocyclo:
@ go get github.com/fzipp/gocyclo
gocyclo -over 25 ./src

test: testdeps fmtcheck
test: testdeps fmtcheck lint
gb test compose/... $(TESTARGS)

version:
Expand Down
29 changes: 18 additions & 11 deletions src/cmd/rocker-compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ import (
)

var (
Version = "built locally"
// Version that is passed on compile time through -ldflags
Version = "built locally"

// GitCommit that is passed on compile time through -ldflags
GitCommit = "none"

// GitBranch that is passed on compile time through -ldflags
GitBranch = "none"

// BuildTime that is passed on compile time through -ldflags
BuildTime = "none"
)

Expand Down Expand Up @@ -241,7 +248,7 @@ func runCommand(ctx *cli.Context) {
config := initComposeConfig(ctx, dockerCli)
auth := initAuthConfig(ctx)

compose, err := compose.New(&compose.ComposeConfig{
compose, err := compose.New(&compose.Config{
Manifest: config,
Docker: dockerCli,
Global: ctx.Bool("global"),
Expand Down Expand Up @@ -290,7 +297,7 @@ func pullCommand(ctx *cli.Context) {
config := initComposeConfig(ctx, dockerCli)
auth := initAuthConfig(ctx)

compose, err := compose.New(&compose.ComposeConfig{
compose, err := compose.New(&compose.Config{
Manifest: config,
Docker: dockerCli,
DryRun: ctx.Bool("dry"),
Expand Down Expand Up @@ -338,7 +345,7 @@ func cleanCommand(ctx *cli.Context) {
config := initComposeConfig(ctx, dockerCli)
auth := initAuthConfig(ctx)

compose, err := compose.New(&compose.ComposeConfig{
compose, err := compose.New(&compose.Config{
Manifest: config,
Docker: dockerCli,
DryRun: ctx.Bool("dry"),
Expand Down Expand Up @@ -366,7 +373,7 @@ func recoverCommand(ctx *cli.Context) {
dockerCli := initDockerClient(ctx)
auth := initAuthConfig(ctx)

compose, err := compose.New(&compose.ComposeConfig{
compose, err := compose.New(&compose.Config{
Docker: dockerCli,
DryRun: ctx.Bool("dry"),
Wait: ctx.Duration("wait"),
Expand Down Expand Up @@ -464,20 +471,20 @@ func initComposeConfig(ctx *cli.Context, dockerCli *docker.Client) *config.Confi

vars := pairsFromStrings(ctx.StringSlice("var"), "=")

var bridgeIp *string
var bridgeIP *string

// TODO: find better place for providing this helper
funcs := map[string]interface{}{
// lazy get bridge ip
"bridgeIp": func() (ip string, err error) {
if bridgeIp == nil {
ip, err = compose.GetBridgeIp(dockerCli)
if bridgeIP == nil {
ip, err = compose.GetBridgeIP(dockerCli)
if err != nil {
return "", err
}
bridgeIp = &ip
bridgeIP = &ip
}
return *bridgeIp, nil
return *bridgeIP, nil
},
}

Expand Down Expand Up @@ -550,7 +557,7 @@ func initAnsubleResp(ctx *cli.Context) (ansibleResp *ansible.Response) {
}

func doRemove(ctx *cli.Context, config *config.Config, dockerCli *docker.Client, auth *compose.AuthConfig) error {
compose, err := compose.New(&compose.ComposeConfig{
compose, err := compose.New(&compose.Config{
Manifest: config,
Docker: dockerCli,
DryRun: ctx.Bool("dry"),
Expand Down
52 changes: 26 additions & 26 deletions src/compose/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ func NewRemoveContainerAction(c *Container) Action {
}

// Execute runs the step
func (s *stepAction) Execute(client Client) (err error) {
if s.async {
err = s.executeAsync(client)
func (a *stepAction) Execute(client Client) (err error) {
if a.async {
err = a.executeAsync(client)
} else {
err = s.executeSync(client)
err = a.executeSync(client)
}
return
}

func (s *stepAction) executeAsync(client Client) (err error) {
func (a *stepAction) executeAsync(client Client) (err error) {
var wg sync.WaitGroup
len := len(s.actions)
len := len(a.actions)
errors := make(chan error, len)
wg.Add(len)
for _, a := range s.actions {
for _, a := range a.actions {
go func(action Action) {
defer wg.Done()
if err := action.Execute(client); err != nil {
Expand All @@ -129,8 +129,8 @@ func (s *stepAction) executeAsync(client Client) (err error) {
return
}

func (s *stepAction) executeSync(client Client) (err error) {
for _, a := range s.actions {
func (a *stepAction) executeSync(client Client) (err error) {
for _, a := range a.actions {
if err = a.Execute(client); err != nil {
return
}
Expand All @@ -139,54 +139,54 @@ func (s *stepAction) executeSync(client Client) (err error) {
}

// String returns the printable string representation of the step.
func (c *stepAction) String() string {
func (a *stepAction) String() string {
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("Running in concurrency mode = %t:\n", c.async))
for _, a := range c.actions {
buffer.WriteString(fmt.Sprintf("Running in concurrency mode = %t:\n", a.async))
for _, a := range a.actions {
buffer.WriteString(fmt.Sprintf(" - %s\n", a))
}
return buffer.String()
}

// Execute runs a container
func (c *runContainer) Execute(client Client) (err error) {
err = client.RunContainer(c.container)
func (a *runContainer) Execute(client Client) (err error) {
err = client.RunContainer(a.container)
return
}

// String returns the printable string representation of the runContainer action.
func (c *runContainer) String() string {
return fmt.Sprintf("Creating container '%s'", c.container.Name)
func (a *runContainer) String() string {
return fmt.Sprintf("Creating container '%s'", a.container.Name)
}

// Execute removes a container
func (r *removeContainer) Execute(client Client) (err error) {
err = client.RemoveContainer(r.container)
func (a *removeContainer) Execute(client Client) (err error) {
err = client.RemoveContainer(a.container)
return
}

// String returns the printable string representation of the removeContainer action.
func (c *removeContainer) String() string {
return fmt.Sprintf("Removing container '%s'", c.container.Name)
func (a *removeContainer) String() string {
return fmt.Sprintf("Removing container '%s'", a.container.Name)
}

// Execute waits for a container
func (r *waitContainerAction) Execute(client Client) (err error) {
return client.WaitForContainer(r.container)
func (a *waitContainerAction) Execute(client Client) (err error) {
return client.WaitForContainer(a.container)
}

// String returns the printable string representation of the waitContainer action.
func (c *waitContainerAction) String() string {
return fmt.Sprintf("Waiting for container '%s'", c.container.Name)
func (a *waitContainerAction) String() string {
return fmt.Sprintf("Waiting for container '%s'", a.container.Name)
}

// Execute does nothing
func (n *noAction) Execute(client Client) (err error) {
func (a *noAction) Execute(client Client) (err error) {
return
}

// String returns "noop"
func (c *noAction) String() string {
func (a *noAction) String() string {
return "noop"
}

Expand Down
2 changes: 1 addition & 1 deletion src/compose/ansible/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Response struct {

// ResponseContainer describes added or removed container
type ResponseContainer struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}

Expand Down
32 changes: 16 additions & 16 deletions src/compose/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ type AuthConfig struct {
ServerAddress string
}

// ToDockerApi converts AuthConfig to be eatable by go-dockerclient
func (a *AuthConfig) ToDockerApi() *docker.AuthConfiguration {
// ToDockerAPI converts AuthConfig to be eatable by go-dockerclient
func (a *AuthConfig) ToDockerAPI() *docker.AuthConfiguration {
if a == nil {
return &docker.AuthConfiguration{}
}
Expand Down Expand Up @@ -188,16 +188,16 @@ func (client *DockerClient) GetContainers() ([]*Container, error) {

// RemoveContainer implements removing a container
func (client *DockerClient) RemoveContainer(container *Container) error {
log.Infof("Removing container %s id:%s", container.Name, util.TruncateID(container.Id))
log.Infof("Removing container %s id:%.12s", container.Name, container.ID)

if container.Config.KillTimeout != nil && *container.Config.KillTimeout > 0 {
if err := client.Docker.StopContainer(container.Id, *container.Config.KillTimeout); err != nil {
if err := client.Docker.StopContainer(container.ID, *container.Config.KillTimeout); err != nil {
return fmt.Errorf("Failed to stop container, error: %s", err)
}
}
keepVolumes := container.Config.KeepVolumes != nil && *container.Config.KeepVolumes
removeOptions := docker.RemoveContainerOptions{
ID: container.Id,
ID: container.ID,
RemoveVolumes: !keepVolumes,
Force: true,
}
Expand All @@ -223,7 +223,7 @@ func (client *DockerClient) RunContainer(container *Container) error {
if err != nil {
return fmt.Errorf("Failed to create container, error: %s", err)
}
container.Id = apiContainer.ID
container.ID = apiContainer.ID

if container.State.Running || container.Config.State.IsRan() {
if client.Attach {
Expand All @@ -245,11 +245,11 @@ func (client *DockerClient) RunContainer(container *Container) error {
// otherwise it waits for configurable '--wait' seconds interval and ensures container
// not exited.
func (client *DockerClient) StartContainer(container *Container) error {
log.Infof("Starting container %s id:%s from image %s", container.Name, util.TruncateID(container.Id), container.Image)
log.Infof("Starting container %s id:%.12s from image %s", container.Name, container.ID, container.Image)

// TODO: HostConfig may be changed without re-creation of containers
// so of Volumes or Links are changed, we just need to restart container
if err := client.Docker.StartContainer(container.Id, container.Config.GetApiHostConfig()); err != nil {
if err := client.Docker.StartContainer(container.ID, container.Config.GetAPIHostConfig()); err != nil {
if !client.Attach {
client.flushContainerLogs(container)
}
Expand Down Expand Up @@ -508,7 +508,7 @@ func (client *DockerClient) WaitForContainer(container *Container) (err error) {
return nil
}

// FetchImages
// FetchImages fetches the missing images for all containers in the manifest
func (client *DockerClient) FetchImages(containers []*Container) error {
type message struct {
container *Container
Expand Down Expand Up @@ -562,7 +562,7 @@ func (client *DockerClient) FetchImages(containers []*Container) error {
wg.Done(err)
return
}
container.ImageId = image.ID
container.ImageID = image.ID
wg.Done(nil)
}(container)
}
Expand All @@ -589,7 +589,7 @@ func (client *DockerClient) pullImageForContainer(container *Container) error {

log.Infof("Pulling image: %s for %s", container.Image, container.Name)

if err := PullDockerImage(client.Docker, container.Image, client.Auth.ToDockerApi()); err != nil {
if err := PullDockerImage(client.Docker, container.Image, client.Auth.ToDockerAPI()); err != nil {
return fmt.Errorf("Failed to pull image %s for container %s, error: %s", container.Image, container.Name, err)
}

Expand Down Expand Up @@ -626,14 +626,14 @@ func (client *DockerClient) listenReAttach(containers []*Container) {
// Filter out events which we are not interested in
var container *Container
for _, c := range containers {
if c.Id == event.ID {
if c.ID == event.ID {
container = c
break
}
}

if container != nil {
log.Infof("Container %s (%.12s) - %s", container.Name, container.Id, event.Status)
log.Infof("Container %s (%.12s) - %s", container.Name, container.ID, event.Status)
}

// We are interested only in "start" events here
Expand All @@ -660,22 +660,22 @@ func (client *DockerClient) listenReAttach(containers []*Container) {
for _, c := range containers {
if c.IsSameKind(eventContainer) {
container = c
container.Id = eventContainer.Id
container.ID = eventContainer.ID
break
}
}
if container == nil {
return
}

log.Infof("Container %s (%.12s) - %s", container.Name, container.Id, event.Status)
log.Infof("Container %s (%.12s) - %s", container.Name, container.ID, event.Status)

// For running containers, in case it is started or restarted, we want to re-attach
if !container.State.Running {
return
}
if err := client.AttachToContainer(container); err != nil {
log.Errorf("Failed to re-attach to the container %s (%.12s), error %s", container.Name, container.Id, err)
log.Errorf("Failed to re-attach to the container %s (%.12s), error %s", container.Name, container.ID, err)
return
}

Expand Down
Loading

0 comments on commit 9f05fa5

Please sign in to comment.