Skip to content

Commit cbaa5f4

Browse files
authored
Merge pull request #773 from Luap99/registries-conf
image: port registries.conf to pkg/configfile
2 parents 6c03f2d + 79cd110 commit cbaa5f4

14 files changed

Lines changed: 625 additions & 463 deletions

common/libimage/runtime.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,6 @@ type RuntimeOptions struct {
4848
SystemContext *types.SystemContext
4949
}
5050

51-
// setRegistriesConfPath sets the registries.conf path for the specified context.
52-
func setRegistriesConfPath(systemContext *types.SystemContext) {
53-
if systemContext.SystemRegistriesConfPath != "" {
54-
return
55-
}
56-
if envOverride, ok := os.LookupEnv("CONTAINERS_REGISTRIES_CONF"); ok {
57-
systemContext.SystemRegistriesConfPath = envOverride
58-
return
59-
}
60-
if envOverride, ok := os.LookupEnv("REGISTRIES_CONFIG_PATH"); ok {
61-
systemContext.SystemRegistriesConfPath = envOverride
62-
return
63-
}
64-
}
65-
6651
// Runtime is responsible for image management and storing them in a containers
6752
// storage.
6853
type Runtime struct {
@@ -119,8 +104,6 @@ func RuntimeFromStore(store storage.Store, options *RuntimeOptions) (*Runtime, e
119104
systemContext.BigFilesTemporaryDir = tmpdir
120105
}
121106

122-
setRegistriesConfPath(&systemContext)
123-
124107
return &Runtime{
125108
store: store,
126109
systemContext: systemContext,

common/libimage/runtime_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func testNewRuntime(t *testing.T, options ...testNewRuntimeOptions) *Runtime {
3939
// Make sure that the tests do not use the host's registries.conf.
4040
systemContext := &types.SystemContext{
4141
SystemRegistriesConfPath: "testdata/registries.conf",
42-
SystemRegistriesConfDirPath: "/dev/null",
42+
SystemRegistriesConfDirPath: t.TempDir(),
4343
}
4444

4545
if len(options) == 1 {

common/pkg/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri
393393
func defaultRegistryWhenUnspecified(systemContext *types.SystemContext) (string, error) {
394394
registriesFromFile, err := sysregistriesv2.UnqualifiedSearchRegistries(systemContext)
395395
if err != nil {
396-
return "", fmt.Errorf("getting registry from registry.conf, please specify a registry: %w", err)
396+
return "", fmt.Errorf("getting registry from registries.conf, please specify a registry: %w", err)
397397
}
398398
if len(registriesFromFile) == 0 {
399399
return "", errors.New("no registries found in registries.conf, a registry must be provided")

image/docs/containers-registries.conf.5.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,46 @@ containers-registries.conf - Syntax of System Registry Configuration File
99
The CONTAINERS-REGISTRIES configuration file is a system-wide configuration
1010
file for container image registries. The file format is TOML.
1111

12-
Container engines will use the `$HOME/.config/containers/registries.conf` if it exists, otherwise they will use `/etc/containers/registries.conf`
12+
By default, the configuration is read from `$XDG_CONFIG_HOME/containers/registries.conf` (or from `$HOME/.config/containers/registries.conf` if `$XDG_CONFIG_HOME` is unset), if it exists; otherwise from `/etc/containers/registries.conf`; otherwise from `/usr/share/containers/registries.conf`. Applications may allow using a different configuration path instead.
13+
14+
If `CONTAINERS_REGISTRIES_CONF` is set, it specifies the configuration file to use,
15+
unless overridden by application-specific configuration. If the environment variable
16+
is set then the following drop-in directories will not be read.
17+
18+
In addition to registries.conf, drop-in files using the same format from the following directories are also read:
19+
- `$XDG_CONFIG_HOME/containers/registries.conf.d` (or from `$HOME/.config/containers/registries.conf.d` if `$XDG_CONFIG_HOME` is unset)
20+
- `/etc/containers/registries.conf.d`
21+
- `/etc/containers/registries.rootful.conf.d` (only when running as uid 0)
22+
- `/etc/containers/registries.rootless.conf.d` (only when running as uid > 0)
23+
- `/etc/containers/registries.rootless.conf.d/$UID` (only when running as uid > 0)
24+
- `/usr/share/containers/registries.rootful.conf.d` (only when running as uid 0)
25+
- `/usr/share/containers/registries.rootless.conf.d` (only when running as uid > 0)
26+
- `/usr/share/containers/registries.rootless.conf.d/$UID` (only when running as uid > 0)
27+
28+
The files must be using the `.conf` suffix, directories or files with other suffixes will be ignored.
29+
All files from these paths will be first collected and then sorted in alpha-numerical order.
30+
If the same filename is used twice then only the first match from the directory list above is
31+
being used. Then the files will be parsed in the sorted order.
32+
33+
For example consider these files:
34+
35+
- `/usr/share/containers/registries.rootless.conf.d/50-middle.conf`
36+
- `/etc/containers/registries.rootless.conf.d/20-first.conf`
37+
- `/etc/containers/registries.rootless.conf.d/70-last.conf`
38+
39+
They will be read in the order of `20-first.conf`, `50-middle.conf`, `70-last.conf`,
40+
the directory path itself does not matter for the order, only the basename.
41+
42+
Specified fields in a conf file will overwrite any previous setting.
43+
For instance, setting the `unqualified-search-registries` in
44+
`/etc/containers/registries.conf.d/myregistries.conf` will overwrite previous
45+
settings in `/etc/containers/registries.conf`. The `[[registry]]` tables merged
46+
by overwriting existing items if the prefixes are identical while new ones are
47+
added.
48+
49+
If `CONTAINERS_REGISTRIES_CONF_OVERRIDE` is set, it specifies an additional path that is being read last,
50+
unless overridden by application-specific configuration.
51+
1352

1453
### GLOBAL SETTINGS
1554

@@ -284,24 +323,6 @@ The format of `$image_reference` is `$repo{:$tag|@$digest}`.
284323

285324
Additional Layer Stores can use this helper binary to access the private registry.
286325

287-
## VERSION 1 FORMAT - DEPRECATED
288-
VERSION 1 format is still supported but it does not support
289-
using registry mirrors, longest-prefix matches, or location rewriting.
290-
291-
The TOML format is used to build a simple list of registries under three
292-
categories: `registries.search`, `registries.insecure`, and `registries.block`.
293-
You can list multiple registries using a comma separated list.
294-
295-
Search registries are used when the caller of a container runtime does not fully specify the
296-
container image that they want to execute. These registries are prepended onto the front
297-
of the specified container image until the named image is found at a registry.
298-
299-
Note that insecure registries can be used for any registry, not just the registries listed
300-
under search.
301-
302-
The `registries.insecure` and `registries.block` lists have the same meaning as the
303-
`insecure` and `blocked` fields in the current version.
304-
305326
### EXAMPLE
306327
The following example configuration defines two searchable registries, one
307328
insecure registry, and two blocked registries.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.so man5/containers-registries.conf.5

image/docs/containers-registries.conf.d.5.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

image/pkg/cli/environment/environment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111
// context, unless already set. Possible values are, in priority and only if
1212
// set, the CONTAINERS_REGISTRIES_CONF or REGISTRIES_CONFIG_PATH environment
1313
// variable.
14+
//
15+
// Deprecated: The registries.conf parsing code in pkg/sysregistriesv2 already
16+
// reads CONTAINERS_REGISTRIES_CONF. REGISTRIES_CONFIG_PATH should not be used
17+
// anymore.
1418
func UpdateRegistriesConf(sys *types.SystemContext) error {
1519
if sys == nil {
1620
return errors.New("internal error: UpdateRegistriesConf: nil argument")

image/pkg/sysregistriesv2/paths_common.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

image/pkg/sysregistriesv2/paths_freebsd.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

image/pkg/sysregistriesv2/shortnames_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestResolveShortNameAlias(t *testing.T) {
117117
}
118118

119119
InvalidateCache()
120-
conf, err := tryUpdatingCache(sys, newConfigWrapper(sys))
120+
conf, err := tryUpdatingCache(newConfigWrapper(sys))
121121
require.NoError(t, err)
122122
assert.Len(t, conf.aliasCache.namedAliases, 4)
123123
assert.Len(t, conf.partialV2.Aliases, 0) // This is an implementation detail, not an API guarantee.
@@ -172,7 +172,7 @@ func TestAliasesWithDropInConfigs(t *testing.T) {
172172
}
173173

174174
InvalidateCache()
175-
conf, err := tryUpdatingCache(sys, newConfigWrapper(sys))
175+
conf, err := tryUpdatingCache(newConfigWrapper(sys))
176176
require.NoError(t, err)
177177
assert.Len(t, conf.aliasCache.namedAliases, 8)
178178
assert.Len(t, conf.partialV2.Aliases, 0) // This is an implementation detail, not an API guarantee.

0 commit comments

Comments
 (0)