Skip to content

Conversation

@nalind
Copy link
Member

@nalind nalind commented Mar 29, 2017

Add a build-using-dockerfile command which uses openshift/imagebuilder to wrap parsing and handle most of the dispatching, and the logic behind the other subcommands to implement assorted instructions.

@nalind
Copy link
Member Author

nalind commented Mar 29, 2017

@@ -0,0 +1,136 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Should we call this build-using-dockerfile.go for consistency?
Or bud.go?

Copy link
Member Author

Choose a reason for hiding this comment

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

bud's a lot less typing, so I'll rename it to that.

var (
buildFlags = []cli.Flag{
cli.BoolFlag{
Name: "quiet",
Copy link
Member

Choose a reason for hiding this comment

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

quiet, q

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Usage: "prefix to prepend to the image name in order to pull the image",
Value: DefaultRegistry,
},
cli.BoolTFlag{
Copy link
Member

Choose a reason for hiding this comment

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

Docker does this by default. I don't think we need an alternative.

Name: "pull",
Usage: "pull the image if not present",
},
cli.BoolFlag{
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should do this either, just do what docker does.

Copy link
Member Author

Choose a reason for hiding this comment

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

This defaults to true, and --pull-always defaults to false, like "buildah from" does. I'll note that "docker build"'s --pull is equivalent to --pull-always, so maybe we need to drop --pull from both, and rename --pull-always to --pull?

},
cli.StringSliceFlag{
Name: "arg",
Usage: "`argument=value` to supply to the builder",
Copy link
Member

Choose a reason for hiding this comment

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

What is an example of this?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is used to supply a value for a variable named by an ARG instruction in a Dockerfile, after which the variable's value can be referred to in other instructions, and will be added to the environment list we get when we're told to process a RUN instruction. Renaming this to --build-arg.

Output: output,
}

return imagebuildah.BuildDockerfileFromFile(store, options, dockerfiles...)
Copy link
Member

Choose a reason for hiding this comment

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

Should this just be BuildDockerfile(...)

Copy link
Member

Choose a reason for hiding this comment

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

👍

systemContext *types.SystemContext
}

func getSystemContext(signaturePolicyPath string) *types.SystemContext {
Copy link
Member

Choose a reason for hiding this comment

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

Should this function be just
systemContext(...)

Copy link
Member

Choose a reason for hiding this comment

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

fwiw, I prefer keeping the get in the name here.

Copy link
Member

Choose a reason for hiding this comment

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

I am fine with get, but I think @mrunalp pointed out that there is some kind of GOLANG standard that says this is discouraged. I think golint and goverify used in CRI-O and runc give you errors when you start functions with get.

Copy link

Choose a reason for hiding this comment

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

Here is the suggested style reference: https://golang.org/doc/effective_go.html#Getters

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that's focused more on wrappers for reading and writing object members, but in terms of what it does, it probably makes more sense to call it makeSystemContext().

return sc
}

func (b *buildahExecutor) Preserve(path string) error {
Copy link
Member

Choose a reason for hiding this comment

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

We need to add comments to all externally defined functions. We need to start running golint and govalidate against our code. I have no idea what Preserve does and it seems to be not implemented yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #62 for adding formatting and style checking to CI. The Preserve method is used to signal the Executor that the path has been marked as part of a volume, which means we need to keep instructions other than an explicit ADD or COPY from modifying anything below that point. The imagebuilder dockerclient implementation uses caching/restoring around its handling of RUN instructions to accomplish this. Adding that.

return nil
}

func (b *buildahExecutor) Copy(excludes []string, copies ...imagebuilder.Copy) error {
Copy link
Member

Choose a reason for hiding this comment

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

Comment.

return nil
}

func (b *buildahExecutor) Run(run imagebuilder.Run, config docker.Config) error {
Copy link
Member

Choose a reason for hiding this comment

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

Comment

@rhatdan
Copy link
Member

rhatdan commented Mar 29, 2017

BTW This is pretty awesome.

}

// BuildDockerfile builds an image using instructions from the named file.
func BuildDockerfileFromFile(store storage.Store, options BuildDockerfileOptions, dockerfile ...string) error {
Copy link
Member

Choose a reason for hiding this comment

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

If you change the name to BuildDockerfileFromFile in build.go, you probably want to do the same here.

@nalind nalind force-pushed the imagebuildah branch 10 times, most recently from dda9371 to d664cbf Compare April 5, 2017 14:10
@nalind
Copy link
Member Author

nalind commented Apr 5, 2017

Updated:

  • rebased
  • golint clean
  • tests no longer fail without Broaden what "rmi" can accept, and add tests #61
  • Preserve() is now implemented, so handling of volumes during bud should be more in line with expectations
  • the bud command's --arg flag is now named --build-arg
  • the bud command's -t, -f, and -q flags now also have long names --tag, --file, and --quiet
  • Dockerfiles can be specified using http/https URLs
  • context directories can be specified as "git://" URLs, "github.com/..." repositories, or as http/https URLs of archives
  • handling of multiple Dockerfiles is more in line with how openshift/imagebuildah uses them (in order, only the first FROM: counts)
  • renamed getSystemContext() to makeSystemContext()
  • more tests

@rhatdan
Copy link
Member

rhatdan commented Apr 8, 2017

LGTM

Do we eventually want to turn ImageBuilder to use Buildah? Might want to move this code out of ImageBuilder into Buildah at that point.

@nalind
Copy link
Member Author

nalind commented Apr 10, 2017

Moving the tell-Travis-to-stop-using-1.6 patch to #65 and rebasing before merging.

@nalind
Copy link
Member Author

nalind commented Apr 10, 2017

I think the imagebuilder CLI could be taught to toggle between its current dockerclient Executor and the one we implement here, as @smarterclayton suggested in openshift/imagebuilder#33. We don't yet support all of the options and hooks that the imagebuilder CLI tool wants to be able to specify, but that's fixable.

@smarterclayton
Copy link

You should also be able to snip more of the dependency tree that we pull in - let me know if there are changes that need to be done to make the core imagebuilder code not depend on docker dependencies.

@nalind nalind force-pushed the imagebuildah branch 3 times, most recently from 91dbef9 to 2202a41 Compare April 12, 2017 21:24
budFlags = []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "refrain from announcing build instructions",
Copy link
Member

Choose a reason for hiding this comment

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

Should we reverse this and change it to verbose, and then default it to value so we don't announce build instructions?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not strongly opposed to it, but docker build and imagebuilder output this info by default.

@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably e67d2e7) made this pull request unmergeable. Please resolve the merge conflicts.

@rhatdan
Copy link
Member

rhatdan commented Apr 12, 2017

man pages and bash completions?

nalind added 3 commits April 12, 2017 17:32
Vendor openshift/imagebuilder and its dependencies, and pick up new
dependencies on golang.org/x/text and github.com/opencontainers/selinux.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Add a build-using-dockerfile command (alias: bud) which uses
openshift/imagebuilder to wrap parsing and dispatching, and runc (or
another OCI runtime) to handle RUN instructions.

Signed-off-by: Nalin Dahyabhai <[email protected]>
It's nowhere near exhaustive, but it's a start.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Signed-off-by: Nalin Dahyabhai <[email protected]>
Add completion for build-using-dockerfile and our renaming of the
containers/images --no-truncate flag to --notruncate during the CLI
overhaul.

Signed-off-by: Nalin Dahyabhai <[email protected]>
@nalind
Copy link
Member Author

nalind commented Apr 13, 2017

Added a man page and updated the bash-completion script.

buildah bud - Build an image using instructions from Dockerfiles.

## SYNOPSIS
**buildah** **bud | build-using-dockerfile** [*options* [...]] [**context**]
Copy link
Member

Choose a reason for hiding this comment

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

Is the context directory optional?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it is if you specify a Dockerfile.

Copy link
Member Author

Choose a reason for hiding this comment

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

If at least one of the Dockerfiles is a local file, we assume the directory that it's in is the context directory.

@rhatdan
Copy link
Member

rhatdan commented Apr 13, 2017

@rh-atomic-bot r+ 390defd

@rh-atomic-bot
Copy link
Collaborator

⌛ Testing commit 390defd with merge d410ce9...

rh-atomic-bot pushed a commit that referenced this pull request Apr 13, 2017
Vendor openshift/imagebuilder and its dependencies, and pick up new
dependencies on golang.org/x/text and github.com/opencontainers/selinux.

Signed-off-by: Nalin Dahyabhai <[email protected]>

Closes: #59
Approved by: rhatdan
rh-atomic-bot pushed a commit that referenced this pull request Apr 13, 2017
Add a build-using-dockerfile command (alias: bud) which uses
openshift/imagebuilder to wrap parsing and dispatching, and runc (or
another OCI runtime) to handle RUN instructions.

Signed-off-by: Nalin Dahyabhai <[email protected]>

Closes: #59
Approved by: rhatdan
rh-atomic-bot pushed a commit that referenced this pull request Apr 13, 2017
It's nowhere near exhaustive, but it's a start.

Signed-off-by: Nalin Dahyabhai <[email protected]>

Closes: #59
Approved by: rhatdan
rh-atomic-bot pushed a commit that referenced this pull request Apr 13, 2017
Signed-off-by: Nalin Dahyabhai <[email protected]>

Closes: #59
Approved by: rhatdan
rh-atomic-bot pushed a commit that referenced this pull request Apr 13, 2017
Add completion for build-using-dockerfile and our renaming of the
containers/images --no-truncate flag to --notruncate during the CLI
overhaul.

Signed-off-by: Nalin Dahyabhai <[email protected]>

Closes: #59
Approved by: rhatdan
@rh-atomic-bot
Copy link
Collaborator

☀️ Test successful - status-redhatci
Approved by: rhatdan
Pushing d410ce9 to master...

@nalind nalind deleted the imagebuildah branch May 11, 2017 19:09
nalind pushed a commit that referenced this pull request Nov 28, 2017
Signed-off-by: Urvashi Mohnani <[email protected]>

Closes: #59
Approved by: rhatdan
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants