You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/01/06 08:59:05 UTC
[camel-k] 01/02: Add network name flag.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ccaa3bc324635aa50a82f238c89f37141a350931
Author: Doru Bercea <gh...@ibm.com>
AuthorDate: Tue Jan 5 18:37:51 2021 -0500
Add network name flag.
---
pkg/cmd/local_run.go | 4 ++++
pkg/cmd/util_containerization.go | 6 ++++++
pkg/util/docker/docker.go | 2 +-
pkg/util/docker/docker_base.go | 8 +++++---
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go
index 94f6383..5ff9917 100644
--- a/pkg/cmd/local_run.go
+++ b/pkg/cmd/local_run.go
@@ -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)
@@ -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"`
@@ -115,6 +117,8 @@ func (command *localRunCmdOptions) init() error {
if err != nil {
return err
}
+
+ setDockerNetworkName(command.Network)
}
return createMavenWorkingDirectory()
diff --git a/pkg/cmd/util_containerization.go b/pkg/cmd/util_containerization.go
index 1f6a8c3..76a6fca 100644
--- a/pkg/cmd/util_containerization.go
+++ b/pkg/cmd/util_containerization.go
@@ -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()
diff --git a/pkg/util/docker/docker.go b/pkg/util/docker/docker.go
index 90ce1f3..5d4777c 100644
--- a/pkg/util/docker/docker.go
+++ b/pkg/util/docker/docker.go
@@ -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)
}
diff --git a/pkg/util/docker/docker_base.go b/pkg/util/docker/docker_base.go
index 366ad77..4967770 100644
--- a/pkg/util/docker/docker_base.go
+++ b/pkg/util/docker/docker_base.go
@@ -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 = "/"
@@ -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")
+ args = append(args, "--network="+NetworkName)
// Path to Docker image:
args = append(args, FullImageArg(imagePath)...)