Skip to content

Commit

Permalink
Merge pull request #43 from harbur/issue-42-lint-all-the-files
Browse files Browse the repository at this point in the history
Lint all go files - close #42
  • Loading branch information
dgil committed May 19, 2016
2 parents 9824a9e + dfe9c34 commit 6d4d2d1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 67 deletions.
50 changes: 31 additions & 19 deletions captain.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func Post(config Config, app App) {
}

type BuildOptions struct {
Config Config
Force bool
Config Config
Force bool
All_branches bool
Long_sha bool
Branch_tags bool
Commit_tags bool
Long_sha bool
Branch_tags bool
Commit_tags bool
}

// Build function compiles the Containers of the project
Expand Down Expand Up @@ -77,7 +77,7 @@ func Build(opts BuildOptions) {
tagImage(app, rev, "latest")

// Tag branch image
for _,branch := range getBranches(opts.All_branches) {
for _, branch := range getBranches(opts.All_branches) {
res := tagImage(app, rev, branch)
if res != nil {
os.Exit(TagFailed)
Expand All @@ -102,7 +102,7 @@ func Build(opts BuildOptions) {
tagImage(app, "latest", rev)

// Tag branch image
for _,branch := range getBranches(opts.All_branches) {
for _, branch := range getBranches(opts.All_branches) {
res := tagImage(app, "latest", branch)
if res != nil {
os.Exit(TagFailed)
Expand Down Expand Up @@ -147,7 +147,7 @@ func Push(opts BuildOptions) {
}

for _, app := range config.GetApps() {
for _,branch := range getBranches(opts.All_branches) {
for _, branch := range getBranches(opts.All_branches) {
info("Pushing image %s:%s", app.Image, "latest")
execute("docker", "push", app.Image+":"+"latest")
if opts.Branch_tags {
Expand All @@ -168,7 +168,7 @@ func Pull(opts BuildOptions) {
config := opts.Config

for _, app := range config.GetApps() {
for _,branch := range getBranches(opts.All_branches) {
for _, branch := range getBranches(opts.All_branches) {
info("Pulling image %s:%s", app.Image, "latest")
execute("docker", "pull", app.Image+":"+"latest")
if opts.Branch_tags {
Expand All @@ -190,29 +190,41 @@ func Purge(opts BuildOptions) {

// For each App
for _, app := range config.GetApps() {
var tags =[]string{}
var tags = []string{}

// Retrieve the list of the existing Image tags
for _,img := range getImages(app) {
tags=append(tags,img.RepoTags...)
for _, img := range getImages(app) {
tags = append(tags, img.RepoTags...)
}

// Remove from the list: The latest image
for key,tag := range tags { if (tag == app.Image+":latest") { tags=append(tags[:key], tags[key+1:]...) } }
for key, tag := range tags {
if tag == app.Image+":latest" {
tags = append(tags[:key], tags[key+1:]...)
}
}

// Remove from the list: The current commit-id
for key,tag := range tags { if (tag == app.Image+":"+getRevision(opts.Long_sha)) { tags=append(tags[:key], tags[key+1:]...) } }
for key, tag := range tags {
if tag == app.Image+":"+getRevision(opts.Long_sha) {
tags = append(tags[:key], tags[key+1:]...)
}
}

// Remove from the list: The working-dir git branches
for _,branch := range getBranches(opts.All_branches) {
for key,tag := range tags { if (tag == app.Image+":"+branch) { tags=append(tags[:key], tags[key+1:]...) } }
for _, branch := range getBranches(opts.All_branches) {
for key, tag := range tags {
if tag == app.Image+":"+branch {
tags = append(tags[:key], tags[key+1:]...)
}
}
}

// Proceed with deletion of Images
for _,tag := range tags {
info ("Deleting image %s", tag)
for _, tag := range tags {
info("Deleting image %s", tag)
res := removeImage(tag)
if (res != nil) {
if res != nil {
err("Deleting image failed: %s", res)
os.Exit(DeleteImageFailed)
}
Expand Down
72 changes: 36 additions & 36 deletions cmd/captain/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (

// Options that are passed by CLI are mapped here for consumption
type Options struct {
debug bool
force bool
long_sha bool
namespace string
config string
images []string
debug bool
force bool
long_sha bool
namespace string
config string
images []string

// Options to define the docker tags context
all_branches bool
branch_tags bool
commit_tags bool
branch_tags bool
commit_tags bool
}

var options Options
Expand All @@ -40,12 +40,12 @@ func handleCmd() {
}

buildOpts := captain.BuildOptions{
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
}

captain.Build(buildOpts)
Expand All @@ -64,12 +64,12 @@ func handleCmd() {
}

buildOpts := captain.BuildOptions{
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
}

// Build everything before testing
Expand All @@ -90,12 +90,12 @@ func handleCmd() {
}

buildOpts := captain.BuildOptions{
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
}

// Build everything before pushing
Expand All @@ -116,12 +116,12 @@ func handleCmd() {
}

buildOpts := captain.BuildOptions{
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Branch_tags: options.branch_tags,
Commit_tags: options.commit_tags,
}

captain.Pull(buildOpts)
Expand All @@ -140,10 +140,10 @@ func handleCmd() {
}

buildOpts := captain.BuildOptions{
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
Config: config,
Force: options.force,
All_branches: options.all_branches,
Long_sha: options.long_sha,
}

captain.Purge(buildOpts)
Expand Down
6 changes: 3 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func removeImage(name string) error {
/**
* Retrieves a list of existing Images for the specific App.
*/
func getImages(app App) ([]docker.APIImages) {
func getImages(app App) []docker.APIImages {
debug("Getting images %s", app.Image)
imgs, _ := client.ListImages(docker.ListImagesOptions{All: false, Filter: app.Image})
imgs, _ := client.ListImages(docker.ListImagesOptions{All: false, Filter: app.Image})
return imgs
}

Expand All @@ -83,4 +83,4 @@ func imageExist(app App, tag string) bool {
return true
}
return false
}
}
18 changes: 9 additions & 9 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ func getRevision(long_sha bool) string {

func getBranches(all_branches bool) []string {
// Labels (branches + tags)
var labels =[]string{}
var labels = []string{}

branches_str, _ := oneliner("git", "name-rev", "--name-only", "HEAD")
if (all_branches) {
branches_str,_ = oneliner("git", "branch", "--no-column", "--contains", "HEAD")
if all_branches {
branches_str, _ = oneliner("git", "branch", "--no-column", "--contains", "HEAD")
}

var branches = make([]string, 5)
if (branches_str != "") {
if branches_str != "" {
// Remove asterisk from branches list
r := regexp.MustCompile("[\\* ] ")
branches_str = r.ReplaceAllString(branches_str, "")
branches = strings.Split(branches_str, "\n")

// Branches list is separated by spaces. Let's put it in an array
labels=append(labels,branches...)
labels = append(labels, branches...)
}

tags_str, _ := oneliner("git", "tag", "--points-at", "HEAD")

if (tags_str != "") {
if tags_str != "" {
tags := strings.Split(tags_str, "\n")
debug("Active branches %s and tags %s", branches, tags)
// Git tag list is separated by multi-lines. Let's put it in an array
labels=append(labels,tags...)
labels = append(labels, tags...)
}

for key := range labels {
Expand All @@ -60,7 +60,7 @@ func getBranches(all_branches bool) []string {
// Replace all "~" with "."
labels[key] = strings.Replace(labels[key], "~", ".", -1)
}

return labels
}

Expand Down

0 comments on commit 6d4d2d1

Please sign in to comment.