Skip to content

Commit 84f1c71

Browse files
committed
Add support to pull idocker images and URLs by configuring appropriate proxy variables
1 parent b8d4c1f commit 84f1c71

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hook-bootkit/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type tinkConfig struct {
4040

4141
// tinkServerTLS is whether or not to use TLS for tink-server communication.
4242
tinkServerTLS string
43+
httpProxy string
44+
httpsProxy string
45+
noProxy string
4346
}
4447

4548
const maxRetryAttempts = 20
@@ -83,6 +86,9 @@ func main() {
8386
fmt.Sprintf("TINKERBELL_TLS=%s", cfg.tinkServerTLS),
8487
fmt.Sprintf("WORKER_ID=%s", cfg.workerID),
8588
fmt.Sprintf("ID=%s", cfg.workerID),
89+
fmt.Sprintf("HTTP_PROXY=%s", cfg.httpProxy),
90+
fmt.Sprintf("HTTPS_PROXY=%s", cfg.httpsProxy),
91+
fmt.Sprintf("NO_PROXY=%s", cfg.noProxy),
8692
},
8793
AttachStdout: true,
8894
AttachStderr: true,
@@ -126,6 +132,10 @@ func main() {
126132
time.Sleep(time.Second * 3)
127133
fmt.Println("Starting Communication with Docker Engine")
128134

135+
os.Setenv("HTTP_PROXY", cfg.httpProxy)
136+
os.Setenv("HTTPS_PROXY", cfg.httpsProxy)
137+
os.Setenv("NO_PROXY", cfg.noProxy)
138+
129139
// Create Docker client with API (socket)
130140
ctx := context.Background()
131141
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
@@ -204,6 +214,12 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
204214
cfg.tinkWorkerImage = cmdLine[1]
205215
case "tinkerbell_tls":
206216
cfg.tinkServerTLS = cmdLine[1]
217+
case "HTTP_PROXY":
218+
cfg.httpProxy = cmdLine[1]
219+
case "HTTPS_PROXY":
220+
cfg.httpsProxy = cmdLine[1]
221+
case "NO_PROXY":
222+
cfg.noProxy = cmdLine[1]
207223
}
208224
}
209225
return cfg

hook-docker/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
type tinkConfig struct {
1414
syslogHost string
1515
insecureRegistries []string
16+
httpProxy string
17+
httpsProxy string
18+
noProxy string
1619
}
1720

1821
type dockerConfig struct {
@@ -58,6 +61,14 @@ func main() {
5861
cmd := exec.Command("/usr/local/bin/docker-init", "/usr/local/bin/dockerd")
5962
cmd.Stdout = os.Stdout
6063
cmd.Stderr = os.Stderr
64+
65+
myEnvs := make([]string, 0, 3)
66+
myEnvs = append(myEnvs, fmt.Sprintf("HTTP_PROXY=%s", cfg.httpProxy))
67+
myEnvs = append(myEnvs, fmt.Sprintf("HTTPS_PROXY=%s", cfg.httpsProxy))
68+
myEnvs = append(myEnvs, fmt.Sprintf("NO_PROXY=%s", cfg.noProxy))
69+
70+
cmd.Env = append(os.Environ(), myEnvs...)
71+
6172
err = cmd.Run()
6273
if err != nil {
6374
panic(err)
@@ -90,6 +101,12 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
90101
cfg.syslogHost = cmdLine[1]
91102
case "insecure_registries":
92103
cfg.insecureRegistries = strings.Split(cmdLine[1], ",")
104+
case "HTTP_PROXY":
105+
cfg.httpProxy = cmdLine[1]
106+
case "HTTPS_PROXY":
107+
cfg.httpsProxy = cmdLine[1]
108+
case "NO_PROXY":
109+
cfg.noProxy = cmdLine[1]
93110
}
94111
}
95112
return cfg

0 commit comments

Comments
 (0)