API cleanup: PullPolicy and TerminalPolicy should be types
Make the PullPolicy field in BuilderOptions structures and the the Terminal field in RunOptions their own types. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> Closes: #705 Approved by: rhatdan
This commit is contained in:
parent
a855573b92
commit
1254c5bf5e
21
buildah.go
21
buildah.go
|
@ -3,6 +3,7 @@ package buildah
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -35,11 +36,14 @@ const (
|
|||
stateFile = Package + ".json"
|
||||
)
|
||||
|
||||
// PullPolicy takes the value PullIfMissing, PullAlways, or PullNever.
|
||||
type PullPolicy int
|
||||
|
||||
const (
|
||||
// PullIfMissing is one of the values that BuilderOptions.PullPolicy
|
||||
// can take, signalling that the source image should be pulled from a
|
||||
// registry if a local copy of it is not already present.
|
||||
PullIfMissing = iota
|
||||
PullIfMissing PullPolicy = iota
|
||||
// PullAlways is one of the values that BuilderOptions.PullPolicy can
|
||||
// take, signalling that a fresh, possibly updated, copy of the image
|
||||
// should be pulled from a registry before the build proceeds.
|
||||
|
@ -50,6 +54,19 @@ const (
|
|||
PullNever
|
||||
)
|
||||
|
||||
// String converts a PullPolicy into a string.
|
||||
func (p PullPolicy) String() string {
|
||||
switch p {
|
||||
case PullIfMissing:
|
||||
return "PullIfMissing"
|
||||
case PullAlways:
|
||||
return "PullAlways"
|
||||
case PullNever:
|
||||
return "PullNever"
|
||||
}
|
||||
return fmt.Sprintf("unrecognized policy %d", p)
|
||||
}
|
||||
|
||||
// Builder objects are used to represent containers which are being used to
|
||||
// build images. They also carry potential updates which will be applied to
|
||||
// the image's configuration when the container's contents are used to build an
|
||||
|
@ -184,7 +201,7 @@ type BuilderOptions struct {
|
|||
// PullPolicy decides whether or not we should pull the image that
|
||||
// we're using as a base image. It should be PullIfMissing,
|
||||
// PullAlways, or PullNever.
|
||||
PullPolicy int
|
||||
PullPolicy PullPolicy
|
||||
// Registry is a value which is prepended to the image's name, if it
|
||||
// needs to be pulled and the image name alone can not be resolved to a
|
||||
// reference to a source image. No separator is implicitly added.
|
||||
|
|
|
@ -51,7 +51,7 @@ type BuildOptions struct {
|
|||
ContextDirectory string
|
||||
// PullPolicy controls whether or not we pull images. It should be one
|
||||
// of PullIfMissing, PullAlways, or PullNever.
|
||||
PullPolicy int
|
||||
PullPolicy buildah.PullPolicy
|
||||
// Registry is a value which is prepended to the image's name, if it
|
||||
// needs to be pulled and the image name alone can not be resolved to a
|
||||
// reference to a source image. No separator is implicitly added.
|
||||
|
@ -126,7 +126,7 @@ type Executor struct {
|
|||
store storage.Store
|
||||
contextDir string
|
||||
builder *buildah.Builder
|
||||
pullPolicy int
|
||||
pullPolicy buildah.PullPolicy
|
||||
registry string
|
||||
transport string
|
||||
ignoreUnrecognizedInstructions bool
|
||||
|
|
20
run.go
20
run.go
|
@ -31,10 +31,13 @@ const (
|
|||
DefaultRuntime = "runc"
|
||||
)
|
||||
|
||||
// TerminalPolicy takes the value DefaultTerminal, WithoutTerminal, or WithTerminal.
|
||||
type TerminalPolicy int
|
||||
|
||||
const (
|
||||
// DefaultTerminal indicates that this Run invocation should be
|
||||
// connected to a pseudoterminal if we're connected to a terminal.
|
||||
DefaultTerminal = iota
|
||||
DefaultTerminal TerminalPolicy = iota
|
||||
// WithoutTerminal indicates that this Run invocation should NOT be
|
||||
// connected to a pseudoterminal.
|
||||
WithoutTerminal
|
||||
|
@ -43,6 +46,19 @@ const (
|
|||
WithTerminal
|
||||
)
|
||||
|
||||
// String converts a TerminalPoliicy into a string.
|
||||
func (t TerminalPolicy) String() string {
|
||||
switch t {
|
||||
case DefaultTerminal:
|
||||
return "DefaultTerminal"
|
||||
case WithoutTerminal:
|
||||
return "WithoutTerminal"
|
||||
case WithTerminal:
|
||||
return "WithTerminal"
|
||||
}
|
||||
return fmt.Sprintf("unrecognized terminal setting %d", t)
|
||||
}
|
||||
|
||||
// RunOptions can be used to alter how a command is run in the container.
|
||||
type RunOptions struct {
|
||||
// Hostname is the hostname we set for the running container.
|
||||
|
@ -72,7 +88,7 @@ type RunOptions struct {
|
|||
// terminal is used if os.Stdout is connected to a terminal, but that
|
||||
// decision can be overridden by specifying either WithTerminal or
|
||||
// WithoutTerminal.
|
||||
Terminal int
|
||||
Terminal TerminalPolicy
|
||||
// Quiet tells the run to turn off output to stdout.
|
||||
Quiet bool
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue