Skip to content

Instantly share code, notes, and snippets.

@ry4nz
Created August 9, 2024 20:10
Show Gist options
  • Save ry4nz/7f0963e714967f07e5a7a68692c9f783 to your computer and use it in GitHub Desktop.
Save ry4nz/7f0963e714967f07e5a7a68692c9f783 to your computer and use it in GitHub Desktop.
image pull code path
func GetAdminHTTPClient(serverURL string) (*http.Client, error) {
// Authenticate with admin user through TLS
tlsConfig, err := GetUserTLSConfig(serverURL, GetAdminUser(), GetAdminPassword())
if err != nil {
return nil, err
}
tlsConfig.InsecureSkipVerify = true
tr := &http.Transport{
TLSClientConfig: tlsConfig,
DisableKeepAlives: true,
MaxIdleConnsPerHost: 0,
}
return &http.Client{
Timeout: TIMEOUT,
Transport: tr,
}, nil
}
httpClient, err := GetAdminHTTPClient(serverURL)
remoteClient, err := client.NewClientWithOpts(
client.WithHost(host),
client.WithHTTPClient(httpClient),
)
remoteClient.NegotiateAPIVersion(context.TODO())
authConfig := types.AuthConfig{ // this actually change to registry.AuthConfig with the new version of docker
Username: username,
Password: password,
ServerAddress: serverAddress,
}
options := types.ImagePullOptions{}
encodedJSON, err := json.Marshal(authConfig)
options.RegistryAuth = base64.URLEncoding.EncodeToString(encodedJSON)
progress, err := remoteClient.ImagePull(context.TODO(), imageName, options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment