Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

allowing docker to use cached base image in build #110

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ _testmain.go

coverage.out
drone-docker

# IDE/Editor related files
**.swp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you revert this file? You can add editor specific files to .git/info/exclude

6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func main() {
Usage: "squash the layers at build time",
EnvVar: "PLUGIN_SQUASH",
},
cli.BoolTFlag{
Name: "cache",
Usage: "don't attempt to re-build layers of the image that already exist",
EnvVar: "PLUGIN_USE_CACHE",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend change to:

cli.BoolTFlag{
  Name: "pull_image",
  Usage: "pull a newer version of the image on build",
  EnvVar: "PLUGIN_PULL_IMAGE",
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that we cannot use pull here. This is a reserved keywork in the yaml and will not get passed to the plugin. So instead we use pull_image

},
cli.BoolFlag{
Name: "compress",
Usage: "compress the build context using gzip",
Expand Down Expand Up @@ -172,6 +177,7 @@ func run(c *cli.Context) error {
Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"),
Squash: c.Bool("squash"),
Cache: c.Bool("cache"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend change to:

c.BoolT("pull-image")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also note we need to use c.BoolT here

Compress: c.Bool("compress"),
Repo: c.String("repo"),
},
Expand Down
7 changes: 6 additions & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type (
Tags []string // Docker build tags
Args []string // Docker build args
Squash bool // Docker build squash
Cache bool // Docker build without pulling
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend change to Pull

Compress bool // Docker build compress
Repo string // Docker build repository
}
Expand Down Expand Up @@ -187,7 +188,6 @@ func commandInfo() *exec.Cmd {
func commandBuild(build Build) *exec.Cmd {
args := []string {
"build",
"--pull=true",
"--rm=true",
"-f", build.Dockerfile,
"-t", build.Name,
Expand All @@ -200,6 +200,11 @@ func commandBuild(build Build) *exec.Cmd {
if build.Compress {
args = append(args, "--compress")
}
if build.Cache {
args = append(args, "--pull=false")
} else {
args = append(args, "--pull=true")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be condensed to a single line:

if build.Pull {
  args = append(args, "--pull=true")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also make sure to run gofmt on your changes. This will ensure the codebase conforms to the official Go style guidelines (in this case tags for indentation)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doooh.. now I feel silly! I knew there was a way of doing this without negating the option, thanks!

for _, arg := range build.Args {
args = append(args, "--build-arg", arg)
}
Expand Down