Skip to content

Commit b476781

Browse files
Merge pull request containers#10774 from vrothberg/registries
remove `pkg/registries`
2 parents 2d19196 + f95b099 commit b476781

File tree

12 files changed

+52
-181
lines changed

12 files changed

+52
-181
lines changed

cmd/podman/common/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"strings"
99

1010
"github.com/containers/common/pkg/config"
11+
"github.com/containers/image/v5/pkg/sysregistriesv2"
1112
"github.com/containers/podman/v3/cmd/podman/registry"
1213
"github.com/containers/podman/v3/libpod/define"
1314
"github.com/containers/podman/v3/pkg/domain/entities"
1415
"github.com/containers/podman/v3/pkg/network"
15-
"github.com/containers/podman/v3/pkg/registries"
1616
"github.com/containers/podman/v3/pkg/rootless"
1717
systemdDefine "github.com/containers/podman/v3/pkg/systemd/define"
1818
"github.com/containers/podman/v3/pkg/util"
@@ -236,7 +236,7 @@ func getSecrets(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellCom
236236
}
237237

238238
func getRegistries() ([]string, cobra.ShellCompDirective) {
239-
regs, err := registries.GetRegistries()
239+
regs, err := sysregistriesv2.UnqualifiedSearchRegistries(nil)
240240
if err != nil {
241241
cobra.CompErrorln(err.Error())
242242
return nil, cobra.ShellCompDirectiveNoFileComp

cmd/podman/login.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/containers/image/v5/types"
1010
"github.com/containers/podman/v3/cmd/podman/common"
1111
"github.com/containers/podman/v3/cmd/podman/registry"
12-
"github.com/containers/podman/v3/pkg/registries"
1312
"github.com/spf13/cobra"
1413
)
1514

@@ -63,12 +62,29 @@ func login(cmd *cobra.Command, args []string) error {
6362
skipTLS = types.NewOptionalBool(!loginOptions.tlsVerify)
6463
}
6564

66-
sysCtx := types.SystemContext{
65+
sysCtx := &types.SystemContext{
6766
AuthFilePath: loginOptions.AuthFile,
6867
DockerCertPath: loginOptions.CertDir,
6968
DockerInsecureSkipTLSVerify: skipTLS,
70-
SystemRegistriesConfPath: registries.SystemRegistriesConfPath(),
7169
}
70+
setRegistriesConfPath(sysCtx)
7271
loginOptions.GetLoginSet = cmd.Flag("get-login").Changed
73-
return auth.Login(context.Background(), &sysCtx, &loginOptions.LoginOptions, args)
72+
return auth.Login(context.Background(), sysCtx, &loginOptions.LoginOptions, args)
73+
}
74+
75+
// setRegistriesConfPath sets the registries.conf path for the specified context.
76+
// NOTE: this is a verbatim copy from c/common/libimage which we're not using
77+
// to prevent leaking c/storage into this file. Maybe this should go into c/image?
78+
func setRegistriesConfPath(systemContext *types.SystemContext) {
79+
if systemContext.SystemRegistriesConfPath != "" {
80+
return
81+
}
82+
if envOverride, ok := os.LookupEnv("CONTAINERS_REGISTRIES_CONF"); ok {
83+
systemContext.SystemRegistriesConfPath = envOverride
84+
return
85+
}
86+
if envOverride, ok := os.LookupEnv("REGISTRIES_CONFIG_PATH"); ok {
87+
systemContext.SystemRegistriesConfPath = envOverride
88+
return
89+
}
7490
}

cmd/podman/logout.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/containers/image/v5/types"
99
"github.com/containers/podman/v3/cmd/podman/common"
1010
"github.com/containers/podman/v3/cmd/podman/registry"
11-
"github.com/containers/podman/v3/pkg/registries"
1211
"github.com/spf13/cobra"
1312
)
1413

@@ -48,9 +47,9 @@ func init() {
4847

4948
// Implementation of podman-logout.
5049
func logout(cmd *cobra.Command, args []string) error {
51-
sysCtx := types.SystemContext{
52-
AuthFilePath: logoutOptions.AuthFile,
53-
SystemRegistriesConfPath: registries.SystemRegistriesConfPath(),
50+
sysCtx := &types.SystemContext{
51+
AuthFilePath: logoutOptions.AuthFile,
5452
}
55-
return auth.Logout(&sysCtx, &logoutOptions, args)
53+
setRegistriesConfPath(sysCtx)
54+
return auth.Logout(sysCtx, &logoutOptions, args)
5655
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/containernetworking/cni v0.8.1
1313
github.com/containernetworking/plugins v0.9.1
1414
github.com/containers/buildah v1.21.1
15-
github.com/containers/common v0.40.2-0.20210623133759-d13a31743aec
15+
github.com/containers/common v0.40.2-0.20210624120009-b1d3c4dc2515
1616
github.com/containers/conmon v2.0.20+incompatible
1717
github.com/containers/image/v5 v5.13.2
1818
github.com/containers/ocicrypt v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRD
221221
github.com/containers/buildah v1.21.1 h1:e9LmTCUKUBLg72v5DnIOT/wc8ffkfB7LbpQBywLZo20=
222222
github.com/containers/buildah v1.21.1/go.mod h1:yPdlpVd93T+i91yGxrJbW1YOWrqN64j5ZhHOZmHUejs=
223223
github.com/containers/common v0.38.4/go.mod h1:egfpX/Y3+19Dz4Wa1eRZDdgzoEOeneieF9CQppKzLBg=
224-
github.com/containers/common v0.40.2-0.20210623133759-d13a31743aec h1:ZcteA2klZSZAZgVonwJAqezF6hdO9SMKUy49ZHXZd38=
225-
github.com/containers/common v0.40.2-0.20210623133759-d13a31743aec/go.mod h1:J23CfuhN1fAg85q5HxS6SKYhKbGqmqieKQqoHaQbEI8=
224+
github.com/containers/common v0.40.2-0.20210624120009-b1d3c4dc2515 h1:ih6akqzrwgKFRxLzdoRBFRUlIGbDWPoDYxhn5GihfXM=
225+
github.com/containers/common v0.40.2-0.20210624120009-b1d3c4dc2515/go.mod h1:J23CfuhN1fAg85q5HxS6SKYhKbGqmqieKQqoHaQbEI8=
226226
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
227227
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
228228
github.com/containers/image/v5 v5.12.0/go.mod h1:VasTuHmOw+uD0oHCfApQcMO2+36SfyncoSahU7513Xs=

libpod/info.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"github.com/containers/buildah"
1616
"github.com/containers/common/pkg/apparmor"
1717
"github.com/containers/common/pkg/seccomp"
18+
"github.com/containers/image/v5/pkg/sysregistriesv2"
1819
"github.com/containers/podman/v3/libpod/define"
1920
"github.com/containers/podman/v3/libpod/linkmode"
2021
"github.com/containers/podman/v3/pkg/cgroups"
21-
registries2 "github.com/containers/podman/v3/pkg/registries"
2222
"github.com/containers/podman/v3/pkg/rootless"
2323
"github.com/containers/storage"
2424
"github.com/containers/storage/pkg/system"
@@ -49,14 +49,16 @@ func (r *Runtime) info() (*define.Info, error) {
4949
}
5050
info.Store = storeInfo
5151
registries := make(map[string]interface{})
52-
data, err := registries2.GetRegistriesData()
52+
53+
sys := r.SystemContext()
54+
data, err := sysregistriesv2.GetRegistries(sys)
5355
if err != nil {
5456
return nil, errors.Wrapf(err, "error getting registries")
5557
}
5658
for _, reg := range data {
5759
registries[reg.Prefix] = reg
5860
}
59-
regs, err := registries2.GetRegistries()
61+
regs, err := sysregistriesv2.UnqualifiedSearchRegistries(sys)
6062
if err != nil {
6163
return nil, errors.Wrapf(err, "error getting registries")
6264
}

libpod/runtime.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/containers/podman/v3/libpod/plugin"
3030
"github.com/containers/podman/v3/libpod/shutdown"
3131
"github.com/containers/podman/v3/pkg/cgroups"
32-
"github.com/containers/podman/v3/pkg/registries"
3332
"github.com/containers/podman/v3/pkg/rootless"
3433
"github.com/containers/podman/v3/pkg/util"
3534
"github.com/containers/storage"
@@ -932,7 +931,9 @@ func (r *Runtime) LibimageRuntime() *libimage.Runtime {
932931

933932
// SystemContext returns the imagecontext
934933
func (r *Runtime) SystemContext() *types.SystemContext {
935-
return r.imageContext
934+
// Return the context from the libimage runtime. libimage is sensitive
935+
// to a number of env vars.
936+
return r.libimageRuntime.SystemContext()
936937
}
937938

938939
// GetOCIRuntimePath retrieves the path of the default OCI runtime.
@@ -1042,9 +1043,9 @@ func (r *Runtime) Reload() error {
10421043
if err := r.reloadStorageConf(); err != nil {
10431044
return err
10441045
}
1045-
if err := reloadRegistriesConf(); err != nil {
1046-
return err
1047-
}
1046+
// Invalidate the registries.conf cache. The next invocation will
1047+
// reload all data.
1048+
sysregistriesv2.InvalidateCache()
10481049
return nil
10491050
}
10501051

@@ -1059,17 +1060,6 @@ func (r *Runtime) reloadContainersConf() error {
10591060
return nil
10601061
}
10611062

1062-
// reloadRegistries reloads the registries.conf
1063-
func reloadRegistriesConf() error {
1064-
sysregistriesv2.InvalidateCache()
1065-
registries, err := sysregistriesv2.GetRegistries(&types.SystemContext{SystemRegistriesConfPath: registries.SystemRegistriesConfPath()})
1066-
if err != nil {
1067-
return err
1068-
}
1069-
logrus.Infof("applied new registry configuration: %+v", registries)
1070-
return nil
1071-
}
1072-
10731063
// reloadStorageConf reloads the storage.conf
10741064
func (r *Runtime) reloadStorageConf() error {
10751065
configFile, err := storage.DefaultConfigFile(rootless.IsRootless())

libpod/runtime_img_test.go

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

pkg/api/handlers/compat/auth.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
DockerClient "github.com/containers/image/v5/docker"
1111
"github.com/containers/image/v5/types"
12+
"github.com/containers/podman/v3/libpod"
1213
"github.com/containers/podman/v3/pkg/api/handlers/utils"
1314
"github.com/containers/podman/v3/pkg/domain/entities"
14-
"github.com/containers/podman/v3/pkg/registries"
1515
docker "github.com/docker/docker/api/types"
1616
"github.com/pkg/errors"
1717
)
@@ -37,15 +37,13 @@ func Auth(w http.ResponseWriter, r *http.Request) {
3737
skipTLS = types.NewOptionalBool(true)
3838
}
3939

40+
runtime := r.Context().Value("runtime").(*libpod.Runtime)
41+
sysCtx := runtime.SystemContext()
42+
sysCtx.DockerInsecureSkipTLSVerify = skipTLS
43+
4044
fmt.Println("Authenticating with existing credentials...")
41-
sysCtx := types.SystemContext{
42-
AuthFilePath: "",
43-
DockerCertPath: "",
44-
DockerInsecureSkipTLSVerify: skipTLS,
45-
SystemRegistriesConfPath: registries.SystemRegistriesConfPath(),
46-
}
4745
registry := stripAddressOfScheme(authConfig.ServerAddress)
48-
if err := DockerClient.CheckAuth(context.Background(), &sysCtx, authConfig.Username, authConfig.Password, registry); err == nil {
46+
if err := DockerClient.CheckAuth(context.Background(), sysCtx, authConfig.Username, authConfig.Password, registry); err == nil {
4947
utils.WriteResponse(w, http.StatusOK, entities.AuthReport{
5048
IdentityToken: "",
5149
Status: "Login Succeeded",

pkg/registries/registries.go

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

0 commit comments

Comments
 (0)