Skip to content

Commit

Permalink
create .docker folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jk1484 authored and Egor Balakin committed Nov 15, 2023
1 parent 4c1fbd2 commit 58b1f90
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/imagePushToRegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 58b1f90

Please sign in to comment.