From 5dde5e766c0178a80416e3ec8f3ffc55a2691ed2 Mon Sep 17 00:00:00 2001 From: maride Date: Fri, 7 Sep 2018 14:04:58 +0200 Subject: Cleanup, react to signals (\^C), tidy up and sort code --- src/container.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/container.go') diff --git a/src/container.go b/src/container.go index c9a918f..29046e2 100644 --- a/src/container.go +++ b/src/container.go @@ -9,7 +9,7 @@ import ( ) const ( - VPNNetworkName = "circus-vpnnet" + containerNetworkName = "circus-vpnnet" ) type ChallengeContainer struct { @@ -23,11 +23,14 @@ func (cc ChallengeContainer) startContainer() (address string, containerID strin // Set up our context and Docker CLI connection setupContext() setupDockerCLI() - // Set up network - err = setupNetwork() - if err != nil { - return "", "", err + // Set up container network + if containerNetworkID == "" { + id, err := setupNetwork(containerNetworkName, true) + if (err != nil) { + return "", "", err + } + containerNetworkID = id } // Create container @@ -37,8 +40,8 @@ func (cc ChallengeContainer) startContainer() (address string, containerID strin Tty: false, }, nil, &network.NetworkingConfig{ EndpointsConfig: map[string]*network.EndpointSettings{ - VPNNetworkName: { - NetworkID: vpnNetworkID, + containerNetworkName: { + NetworkID: containerNetworkID, }, }, }, "") @@ -60,7 +63,7 @@ func (cc ChallengeContainer) startContainer() (address string, containerID strin } // Return IP, Container ID and error - return inspectJSON.NetworkSettings.Networks[VPNNetworkName].IPAddress, resp.ID,nil + return inspectJSON.NetworkSettings.Networks[containerNetworkName].IPAddress, resp.ID,nil } // Stops the container with a timeout of one second -- cgit 1.4.1