Skip to content

Commit ca2995a

Browse files
committed
fix(buildah): pass default registries.conf to native buildah
1 parent c89aff4 commit ca2995a

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

pkg/buildah/base.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import (
1212
)
1313

1414
type BaseBuildah struct {
15-
Isolation thirdparty.Isolation
16-
TmpDir string
17-
InstanceTmpDir string
18-
SignaturePolicyPath string
19-
Insecure bool
15+
Isolation thirdparty.Isolation
16+
TmpDir string
17+
InstanceTmpDir string
18+
ConfigTmpDir string
19+
SignaturePolicyPath string
20+
RegistriesConfigPath string
21+
RegistriesConfigDirPath string
22+
Insecure bool
2023
}
2124

2225
type BaseBuildahOpts struct {
@@ -41,11 +44,26 @@ func NewBaseBuildah(tmpDir string, opts BaseBuildahOpts) (*BaseBuildah, error) {
4144
return nil, fmt.Errorf("unable to create instance tmp dir: %s", err)
4245
}
4346

44-
b.SignaturePolicyPath = filepath.Join(b.InstanceTmpDir, "policy.json")
47+
b.ConfigTmpDir = filepath.Join(b.InstanceTmpDir, "config")
48+
if err := os.MkdirAll(b.ConfigTmpDir, os.ModePerm); err != nil {
49+
return nil, fmt.Errorf("unable to create dir %q: %s", b.ConfigTmpDir, err)
50+
}
51+
52+
b.SignaturePolicyPath = filepath.Join(b.ConfigTmpDir, "policy.json")
4553
if err := ioutil.WriteFile(b.SignaturePolicyPath, []byte(DefaultSignaturePolicy), os.ModePerm); err != nil {
4654
return nil, fmt.Errorf("unable to write file %q: %s", b.SignaturePolicyPath, err)
4755
}
4856

57+
b.RegistriesConfigPath = filepath.Join(b.ConfigTmpDir, "registries.conf")
58+
if err := ioutil.WriteFile(b.RegistriesConfigPath, []byte(DefaultRegistriesConfig), os.ModePerm); err != nil {
59+
return nil, fmt.Errorf("unable to write file %q: %s", b.RegistriesConfigPath, err)
60+
}
61+
62+
b.RegistriesConfigDirPath = filepath.Join(b.ConfigTmpDir, "registries.conf.d")
63+
if err := os.MkdirAll(b.RegistriesConfigDirPath, os.ModePerm); err != nil {
64+
return nil, fmt.Errorf("unable to create dir %q: %s", b.RegistriesConfigDirPath, err)
65+
}
66+
4967
return b, nil
5068
}
5169

pkg/buildah/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
const (
2020
DefaultShmSize = "65536k"
2121
DefaultSignaturePolicy = `{"default": [{"type": "insecureAcceptAnything"}], "transports": {"docker-daemon": {"": [{"type": "insecureAcceptAnything"}]}}}`
22+
DefaultRegistriesConfig = `unqualified-search-registries = ["docker.io"]`
2223
BuildahImage = "ghcr.io/werf/buildah:v1.22.3-1"
2324
BuildahStorageContainerName = "werf-buildah-storage"
2425

pkg/buildah/native_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ func NewNativeBuildah(commonOpts CommonBuildahOpts, opts NativeModeOpts) (*Nativ
8686
OCIInsecureSkipTLSVerify: b.Insecure,
8787
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
8888
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
89+
SystemRegistriesConfPath: b.RegistriesConfigPath,
90+
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
8991
},
9092
})
9193
if err != nil {
@@ -136,6 +138,8 @@ func (b *NativeBuildah) Push(ctx context.Context, ref string, opts PushOpts) err
136138
OCIInsecureSkipTLSVerify: b.Insecure,
137139
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
138140
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
141+
SystemRegistriesConfPath: b.RegistriesConfigPath,
142+
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
139143
},
140144
}
141145

@@ -167,6 +171,8 @@ func (b *NativeBuildah) BuildFromDockerfile(ctx context.Context, dockerfile []by
167171
OCIInsecureSkipTLSVerify: b.Insecure,
168172
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
169173
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
174+
SystemRegistriesConfPath: b.RegistriesConfigPath,
175+
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
170176
},
171177
Args: opts.BuildArgs,
172178
}
@@ -266,6 +272,8 @@ func (b *NativeBuildah) Pull(ctx context.Context, ref string, opts PullOpts) err
266272
OCIInsecureSkipTLSVerify: b.Insecure,
267273
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
268274
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
275+
SystemRegistriesConfPath: b.RegistriesConfigPath,
276+
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
269277
},
270278
}
271279

@@ -310,6 +318,8 @@ func (b *NativeBuildah) getImageBuilder(ctx context.Context, imgName string) (bu
310318
OCIInsecureSkipTLSVerify: b.Insecure,
311319
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
312320
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
321+
SystemRegistriesConfPath: b.RegistriesConfigPath,
322+
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
313323
},
314324
})
315325
switch {

0 commit comments

Comments
 (0)