Created
August 9, 2024 20:10
-
-
Save ry4nz/7f0963e714967f07e5a7a68692c9f783 to your computer and use it in GitHub Desktop.
image pull code path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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