From 58b1f908237e07e80a2a2f4166d7af6ffe249d87 Mon Sep 17 00:00:00 2001 From: Muhammadali Nazarov Date: Tue, 24 Oct 2023 15:46:43 +0500 Subject: [PATCH] create .docker folder --- cmd/imagePushToRegistry.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/imagePushToRegistry.go b/cmd/imagePushToRegistry.go index 07c8bd363a..2e1d63c214 100644 --- a/cmd/imagePushToRegistry.go +++ b/cmd/imagePushToRegistry.go @@ -62,8 +62,12 @@ func imagePushToRegistry(config imagePushToRegistryOptions, telemetryData *telem } func runImagePushToRegistry(config *imagePushToRegistryOptions, telemetryData *telemetry.CustomData, utils imagePushToRegistryUtils, fileUtils piperutils.FileUtils) error { + err := fileUtils.MkdirAll(".docker", 0750) + if err != nil { + return errors.Wrap(err, "unable to create docker config dir") + } - err := handleCredentialsForPrivateRegistries(config.DockerConfigJSON, config.SourceRegistryURL, config.SourceRegistryUser, config.SourceRegistryPassword, fileUtils) + err = handleCredentialsForPrivateRegistries(config.DockerConfigJSON, config.SourceRegistryURL, config.SourceRegistryUser, config.SourceRegistryPassword, fileUtils) if err != nil { return fmt.Errorf("failed to handle registry credentials for source registry: %w", err) } @@ -128,19 +132,19 @@ func handleCredentialsForPrivateRegistries(dockerConfigJsonPath string, registry return errors.Wrapf(err, "failed to read enhanced file '%v'", dockerConfigJsonPath) } } else if len(dockerConfigJsonPath) == 0 && len(registryURL) > 0 && len(password) > 0 && len(username) > 0 { - targetConfigJson, err := docker.CreateDockerConfigJSON(registryURL, username, password, "", "~/.docker/config.json", fileUtils) + targetConfigJson, err := docker.CreateDockerConfigJSON(registryURL, username, password, "", ".docker/config.json", fileUtils) if err != nil { - return errors.Wrap(err, "failed to create new docker config json at ~/.docker/config.json") + return errors.Wrap(err, "failed to create new docker config json at .docker/config.json") } dockerConfig, err = fileUtils.FileRead(targetConfigJson) if err != nil { - return errors.Wrapf(err, "failed to read new docker config file at ~/.docker/config.json") + return errors.Wrapf(err, "failed to read new docker config file at .docker/config.json") } } - if err := fileUtils.FileWrite("~/.docker/config.json", dockerConfig, 0644); err != nil { - return errors.Wrap(err, "failed to write file '~/.docker/config.json'") + if err := fileUtils.FileWrite(".docker/config.json", dockerConfig, 0644); err != nil { + return errors.Wrap(err, "failed to write file "+dockerConfigFile) } return nil }