Skip to content

Commit

Permalink
fix(buildah): pass default registries.conf to native buildah
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lesikov committed Dec 9, 2021
1 parent c89aff4 commit ca2995a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pkg/buildah/base.go
Expand Up @@ -12,11 +12,14 @@ import (
)

type BaseBuildah struct {
Isolation thirdparty.Isolation
TmpDir string
InstanceTmpDir string
SignaturePolicyPath string
Insecure bool
Isolation thirdparty.Isolation
TmpDir string
InstanceTmpDir string
ConfigTmpDir string
SignaturePolicyPath string
RegistriesConfigPath string
RegistriesConfigDirPath string
Insecure bool
}

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

b.SignaturePolicyPath = filepath.Join(b.InstanceTmpDir, "policy.json")
b.ConfigTmpDir = filepath.Join(b.InstanceTmpDir, "config")
if err := os.MkdirAll(b.ConfigTmpDir, os.ModePerm); err != nil {
return nil, fmt.Errorf("unable to create dir %q: %s", b.ConfigTmpDir, err)
}

b.SignaturePolicyPath = filepath.Join(b.ConfigTmpDir, "policy.json")
if err := ioutil.WriteFile(b.SignaturePolicyPath, []byte(DefaultSignaturePolicy), os.ModePerm); err != nil {
return nil, fmt.Errorf("unable to write file %q: %s", b.SignaturePolicyPath, err)
}

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: %s", b.RegistriesConfigPath, err)
}

b.RegistriesConfigDirPath = filepath.Join(b.ConfigTmpDir, "registries.conf.d")
if err := os.MkdirAll(b.RegistriesConfigDirPath, os.ModePerm); err != nil {
return nil, fmt.Errorf("unable to create dir %q: %s", b.RegistriesConfigDirPath, err)
}

return b, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/buildah/common.go
Expand Up @@ -19,6 +19,7 @@ import (
const (
DefaultShmSize = "65536k"
DefaultSignaturePolicy = `{"default": [{"type": "insecureAcceptAnything"}], "transports": {"docker-daemon": {"": [{"type": "insecureAcceptAnything"}]}}}`
DefaultRegistriesConfig = `unqualified-search-registries = ["docker.io"]`
BuildahImage = "ghcr.io/werf/buildah:v1.22.3-1"
BuildahStorageContainerName = "werf-buildah-storage"

Expand Down
10 changes: 10 additions & 0 deletions pkg/buildah/native_linux.go
Expand Up @@ -86,6 +86,8 @@ func NewNativeBuildah(commonOpts CommonBuildahOpts, opts NativeModeOpts) (*Nativ
OCIInsecureSkipTLSVerify: b.Insecure,
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
SystemRegistriesConfPath: b.RegistriesConfigPath,
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
},
})
if err != nil {
Expand Down Expand Up @@ -136,6 +138,8 @@ func (b *NativeBuildah) Push(ctx context.Context, ref string, opts PushOpts) err
OCIInsecureSkipTLSVerify: b.Insecure,
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
SystemRegistriesConfPath: b.RegistriesConfigPath,
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
},
}

Expand Down Expand Up @@ -167,6 +171,8 @@ func (b *NativeBuildah) BuildFromDockerfile(ctx context.Context, dockerfile []by
OCIInsecureSkipTLSVerify: b.Insecure,
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
SystemRegistriesConfPath: b.RegistriesConfigPath,
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
},
Args: opts.BuildArgs,
}
Expand Down Expand Up @@ -266,6 +272,8 @@ func (b *NativeBuildah) Pull(ctx context.Context, ref string, opts PullOpts) err
OCIInsecureSkipTLSVerify: b.Insecure,
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
SystemRegistriesConfPath: b.RegistriesConfigPath,
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
},
}

Expand Down Expand Up @@ -310,6 +318,8 @@ func (b *NativeBuildah) getImageBuilder(ctx context.Context, imgName string) (bu
OCIInsecureSkipTLSVerify: b.Insecure,
DockerInsecureSkipTLSVerify: imgtypes.NewOptionalBool(b.Insecure),
DockerDaemonInsecureSkipTLSVerify: b.Insecure,
SystemRegistriesConfPath: b.RegistriesConfigPath,
SystemRegistriesConfDirPath: b.RegistriesConfigDirPath,
},
})
switch {
Expand Down

0 comments on commit ca2995a

Please sign in to comment.