Skip to content

Commit

Permalink
Allow callers to replace the ContainerPrefix
Browse files Browse the repository at this point in the history
This idea of this PR is to allow Podman to add a Podman
prefix to containers. This would allow it to keep track
of containers created by Podman and make it easier to remove
them when it wants to remove all.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Dec 14, 2021
1 parent 857ba5a commit d5f3a23
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions define/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type CommonBuildOptions struct {

// BuildOptions can be used to alter how an image is built.
type BuildOptions struct {
// ContainerPrefix it the name to prefix containers with
ContainerPrefix string
// ContextDirectory is the default source location for COPY and ADD
// commands.
ContextDirectory string
Expand Down
2 changes: 2 additions & 0 deletions imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var builtinAllowedBuildArgs = map[string]bool{
// interface. It coordinates the entire build by using one or more
// StageExecutors to handle each stage of the build.
type Executor struct {
containerPrefix string
logger *logrus.Logger
stages map[string]*StageExecutor
store storage.Store
Expand Down Expand Up @@ -205,6 +206,7 @@ func newExecutor(logger *logrus.Logger, logPrefix string, store storage.Store, o
}

exec := Executor{
containerPrefix: options.ContainerPrefix,
logger: logger,
stages: make(map[string]*StageExecutor),
store: store,
Expand Down
1 change: 1 addition & 0 deletions imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func (s *StageExecutor) prepare(ctx context.Context, from string, initializeIBCo
Args: ib.Args,
FromImage: from,
PullPolicy: pullPolicy,
Container: s.executor.containerPrefix,
Registry: s.executor.registry,
BlobDirectory: s.executor.blobDirectory,
SignaturePolicyPath: s.executor.signaturePolicyPath,
Expand Down
10 changes: 4 additions & 6 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,11 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions
}
var container *storage.Container
tmpName := name
if options.Container == "" {
containers, err := store.Containers()
if err != nil {
return nil, errors.Wrapf(err, "unable to check for container names")
}
tmpName = findUnusedContainer(tmpName, containers)
containers, err := store.Containers()
if err != nil {
return nil, errors.Wrapf(err, "unable to check for container names")
}
tmpName = findUnusedContainer(tmpName, containers)

conflict := 100
for {
Expand Down

0 comments on commit d5f3a23

Please sign in to comment.