Skip to content

Commit

Permalink
Include more detailed container names (#323)
Browse files Browse the repository at this point in the history
include more detailed container names

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Aug 26, 2024
1 parent 2b4caf5 commit 9d3468b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ func (a *analyzeCommand) createTempRuleSet(path string, name string) error {
}

func (a *analyzeCommand) createContainerNetwork() (string, error) {
networkName := container.RandomName()
networkName := fmt.Sprintf("network-%v", container.RandomName())
args := []string{
"network",
"create",
Expand All @@ -1143,7 +1143,7 @@ func (a *analyzeCommand) createContainerNetwork() (string, error) {

// TODO: create for each source input once accepting multiple apps is completed
func (a *analyzeCommand) createContainerVolume() (string, error) {
volName := container.RandomName()
volName := fmt.Sprintf("volume-%v", container.RandomName())
input, err := filepath.Abs(a.input)
if err != nil {
return "", err
Expand Down Expand Up @@ -1233,6 +1233,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v
container.WithEntrypointArgs(args...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
container.WithName(fmt.Sprintf("provider-%v", container.RandomName())),
container.WithNetwork(networkName),
)
if err != nil {
Expand All @@ -1257,6 +1258,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v
container.WithEntrypointArgs(args...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
container.WithName(fmt.Sprintf("provider-%v", container.RandomName())),
container.WithNetwork(fmt.Sprintf("container:%v", a.providerContainerNames[0])),
)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cmd/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func (a *analyzeCommand) RmNetwork(ctx context.Context) error {
if a.networkName == "" {
return nil
}
a.log.V(1).Info("removing container network",
"network", a.networkName)
cmd := exec.CommandContext(
ctx,
Settings.ContainerBinary,
Expand Down
5 changes: 4 additions & 1 deletion pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func NewContainer() *container {
stdout: []io.Writer{os.Stdout},
env: map[string]string{},
stderr: []io.Writer{os.Stderr},
Name: RandomName(),
Name: "",
NetworkName: "",
// by default, remove the container after run()
cleanup: true,
Expand Down Expand Up @@ -191,6 +191,9 @@ func (c *container) Run(ctx context.Context, opts ...Option) error {
if c.Name != "" {
args = append(args, "--name")
args = append(args, c.Name)
} else {
args = append(args, "--name")
args = append(args, RandomName())
}
if c.NetworkName != "" {
args = append(args, "--network")
Expand Down

0 comments on commit 9d3468b

Please sign in to comment.