Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add network name flag to local run. #1879

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions pkg/cmd/local_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localRunCm

cmd.Flags().Bool("containerize", false, "Run integration in a local container.")
cmd.Flags().String("image", "", "Full path to integration image including registry.")
cmd.Flags().String("network", "", "Custom network name to be used by the underlying Docker command.")
cmd.Flags().StringArray("property-file", nil, "Add a property file to the integration.")
cmd.Flags().StringArrayP("property", "p", nil, "Add a Camel property to the integration.")
cmd.Flags().StringArrayP("dependency", "d", nil, additionalDependencyUsageMessage)
Expand All @@ -69,6 +70,7 @@ type localRunCmdOptions struct {
*RootCmdOptions
Containerize bool `mapstructure:"containerize"`
Image string `mapstructure:"image"`
Network string `mapstructure:"network"`
PropertyFiles []string `mapstructure:"property-files"`
Properties []string `mapstructure:"properties"`
AdditionalDependencies []string `mapstructure:"dependencies"`
Expand Down Expand Up @@ -115,6 +117,8 @@ func (command *localRunCmdOptions) init() error {
if err != nil {
return err
}

setDockerNetworkName(command.Network)
}

return createMavenWorkingDirectory()
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/util_containerization.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func deleteDockerWorkingDirectory() error {
return nil
}

func setDockerNetworkName(networkName string) {
if networkName != "" {
docker.NetworkName = networkName
}
}

func createAndBuildBaseImage(ctx context.Context, containerRegistry string) error {
// Create the base image Docker file.
err := docker.CreateBaseImageDockerFile()
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func BuildIntegrationImageArgs(imagePath string) []string {
func RunIntegrationImageArgs(imagePath string) []string {
// Construct the docker command:
//
// docker run --network="host" <dockerRegistry>/<ImageName>
// docker run --network=<network-name> <dockerRegistry>/<ImageName>
//
return RunImageArgs(imagePath, latestTag)
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/util/docker/docker_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var BaseWorkingDirectory string = ""
// IntegrationWorkingDirectory -- directory used by Docker to construct the integration image.
var IntegrationWorkingDirectory string = ""

// NetworkName -- network used by Docker when running the image.
var NetworkName string = "host"

// Internal variables.
var (
dockerEndpointSeparator = "/"
Expand Down Expand Up @@ -68,14 +71,13 @@ func BuildImageArgs(dockerFileDir string, imageName string, sourceDir string) []
func RunImageArgs(imagePath string, imageTag string) []string {
// Construct the docker command:
//
// docker run --network="host" <image-name>:<tag>
// docker run --network=<network-name> <image-name>:<tag>
//
// TODO: support other types of network connections.
args := make([]string, 0)
args = append(args, "run")

// TODO: support other networks.
args = append(args, "--network=host")
// Add network flag.
args = append(args, "--network="+NetworkName)

// Path to Docker image:
args = append(args, FullImageArg(imagePath)...)
Expand Down