about summary refs log tree commit diff
path: root/src/docker.go
blob: 405afd36127c405affccdbd2f805f932fc2ef1a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main

import (
	"context"
	"fmt"
	"github.com/docker/docker/client"
)

const (
	fixedDockerVersion = "1.38"
)

var (
	compiledContainerNetworkName string
	compiledChallengeNetworkName string
)

var (
	dockerCtx context.Context
	dockerCli *client.Client
)

func setupContext() {
	if dockerCtx == nil {
		dockerCtx = context.Background()
	}
}

func setupDockerCLI() (err error) {
	if dockerCli == nil {
		dockerCli, err = client.NewClientWithOpts(client.WithVersion(fixedDockerVersion))
	}

	return err
}

// Returns the network name for the companion<=>vpn network
func getVPNNetworkName() (string) {
	if compiledContainerNetworkName == "" {
		compiledContainerNetworkName = fmt.Sprintf("circus-vpnnet-%s", getUsernameHash())
	}

	return compiledContainerNetworkName
}

func getChallengeNetworkName() (string) {
	if compiledChallengeNetworkName == "" {
		compiledChallengeNetworkName = fmt.Sprintf("circus-vpnhostnet-%s", getUsernameHash())
	}

	return compiledChallengeNetworkName
}