diff options
author | maride <maride@darknebu.la> | 2018-09-07 14:04:58 +0200 |
---|---|---|
committer | maride <maride@darknebu.la> | 2018-09-07 14:04:58 +0200 |
commit | 5dde5e766c0178a80416e3ec8f3ffc55a2691ed2 (patch) | |
tree | 0f38dcfa29ce4205a8204880247594f97119793f /src/container.go | |
parent | 2f94d8b6cdf325f23a0e40db1097ebbcd7f7c0e1 (diff) |
Cleanup, react to signals (\^C), tidy up and sort code
Diffstat (limited to 'src/container.go')
-rw-r--r-- | src/container.go | 19 |
1 files changed, 11 insertions, 8 deletions
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 |