Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comprehensive support for mirror container registries #5977

Open
1 task done
alexey-igrychev opened this issue Feb 15, 2024 · 2 comments
Open
1 task done

Comprehensive support for mirror container registries #5977

alexey-igrychev opened this issue Feb 15, 2024 · 2 comments

Comments

@alexey-igrychev
Copy link
Member

alexey-igrychev commented Feb 15, 2024

Before proceeding

  • I didn't find a similar issue

Problem

Currently, users can utilize mirror container registries by configuring the Docker daemon. However, equivalent functionality is lacking for the Buildah backend, limiting flexibility and efficiency in registry management.

Solution (if you have one)

Support for mirrors in werf should be done on two levels: when interacting with the container registry via API, and for the build backend directly at build time.

In the case of the Docker backend, the configuration is not werf's responsibility and the user needs to configure mirrors and restart the daemon him/herself. With Buildah the story is different — it is fully compiled into werf and all its configuration is created by werf in the process.

To solve the issue we suggest adding support for --container-registry-mirror option and using it when initializing API and Buildah backend.

Initializing API

The current support in the API is as follows:

func (api *genericApi) getOrCreateRegistryMirrors(ctx context.Context) ([]string, error) {
api.mutex.Lock()
defer api.mutex.Unlock()
if api.mirrors == nil {
var mirrors []string
// init registry mirrors if docker cli initialized in context
if docker.IsEnabled() && docker.IsContext(ctx) {
info, err := docker.Info(ctx)
if err != nil {
return nil, fmt.Errorf("unable to get docker system info: %w", err)
}
if info.RegistryConfig != nil {
mirrors = info.RegistryConfig.Mirrors
}
}
api.mirrors = &mirrors
}
return *api.mirrors, nil
}

For the Docker backend, you need to add validation and an error with an instruction if the specified mirrors are missing. In case of the Buildah backend, mirrors are simply added as is.

Initializing Buildah backend

When initializing the backend, you need to add mirrors to the configuration (documentation and an example are available in the Buildah repository).

b.RegistriesConfigPath = filepath.Join(b.ConfigTmpDir, "registries.conf")
if err := ioutil.WriteFile(b.RegistriesConfigPath, []byte(DefaultRegistriesConfig), os.ModePerm); err != nil {
return nil, fmt.Errorf("unable to write file %q: %w", b.RegistriesConfigPath, err)
}

Additional information

No response

@ulascansenturk
Copy link

Hello @alexey-igrychev I'm interested in contributing to Werf and would like to help with this particular issue. Could you please assign it to me?

@alexey-igrychev
Copy link
Member Author

That's great! Feel free to contact me about anything 🙌🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants