@@ -15,6 +15,7 @@ import (
1515 "strconv"
1616 "strings"
1717 "syscall"
18+ "text/template"
1819 "time"
1920
2021 "github.com/containerd/containerd/platforms"
@@ -43,6 +44,7 @@ import (
4344
4445 "github.com/werf/werf/v2/pkg/buildah/thirdparty"
4546 "github.com/werf/werf/v2/pkg/image"
47+ "github.com/werf/werf/v2/pkg/util"
4648)
4749
4850const (
@@ -121,8 +123,14 @@ func NewNativeBuildah(commonOpts CommonBuildahOpts, opts NativeModeOpts) (*Nativ
121123 return nil , fmt .Errorf ("unable to set env var CONTAINERS_CONF: %w" , err )
122124 }
123125
126+ mirrorsFromEnv := util .PredefinedValuesByEnvNamePrefix ("WERF_CONTAINER_REGISTRY_MIRROR_" )
127+ registriesConfig , err := generateRegistriesConfig (mirrorsFromEnv )
128+ if err != nil {
129+ return nil , fmt .Errorf ("unable to generate registries config: %w" , err )
130+ }
131+
124132 b .RegistriesConfigPath = filepath .Join (b .ConfigTmpDir , "registries.conf" )
125- if err := ioutil .WriteFile (b .RegistriesConfigPath , []byte (DefaultRegistriesConfig ), os .ModePerm ); err != nil {
133+ if err := ioutil .WriteFile (b .RegistriesConfigPath , []byte (registriesConfig ), os .ModePerm ); err != nil {
126134 return nil , fmt .Errorf ("unable to write file %q: %w" , b .RegistriesConfigPath , err )
127135 }
128136
@@ -210,6 +218,30 @@ func (b *NativeBuildah) getSystemContext(targetPlatform string) (*imgtypes.Syste
210218 return systemContext , nil
211219}
212220
221+ func generateRegistriesConfig (mirrors []string ) (string , error ) {
222+ tpl := `
223+ unqualified-search-registries = ["docker.io"]
224+
225+ {{ range . -}}
226+ [[registry.mirror]]
227+ location = "{{ . }}"
228+
229+ {{ end -}}
230+ `
231+ tmpl , err := template .New ("tmp" ).Parse (tpl )
232+ if err != nil {
233+ return "" , err
234+ }
235+
236+ var result bytes.Buffer
237+ err = tmpl .Execute (& result , mirrors )
238+ if err != nil {
239+ return "" , err
240+ }
241+
242+ return result .String (), nil
243+ }
244+
213245func (b * NativeBuildah ) getRuntime (systemContext * imgtypes.SystemContext ) (* libimage.Runtime , error ) {
214246 return libimage .RuntimeFromStore (b .Store , & libimage.RuntimeOptions {
215247 SystemContext : systemContext ,
0 commit comments