@@ -87,9 +87,10 @@ type builder struct {
8787 hostname string
8888 dns []string
8989 dnsSearch []string
90+ hosts string
9091}
9192
92- func NewBuilder (ctx context.Context , workdir , imgTag , disk string , size uint64 , osRelease OSRelease , format string , cmdLineExtra string , splitBoot bool , bootFS BootFS , bootSize uint64 , luksPassword string , bootLoader string , platform , hostname string , dns , dnsSearch []string ) (Builder , error ) {
93+ func NewBuilder (ctx context.Context , workdir , imgTag , disk string , size uint64 , osRelease OSRelease , format string , cmdLineExtra string , splitBoot bool , bootFS BootFS , bootSize uint64 , luksPassword string , bootLoader string , platform , hostname string , dns , dnsSearch []string , extraHosts map [ string ] string ) (Builder , error ) {
9394 var arch string
9495 switch platform {
9596 case "linux/amd64" :
@@ -189,6 +190,10 @@ func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size uint64,
189190 if len (dns ) == 0 {
190191 dns = []string {"8.8.8.8" }
191192 }
193+ hosts := hosts
194+ for k , v := range extraHosts {
195+ hosts += fmt .Sprintf ("%s %s\n " , v , k )
196+ }
192197 b := & builder {
193198 osRelease : osRelease ,
194199 config : config ,
@@ -208,6 +213,7 @@ func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size uint64,
208213 hostname : hostname ,
209214 dns : dns ,
210215 dnsSearch : dnsSearch ,
216+ hosts : hosts ,
211217 }
212218 if err := b .checkDependencies (); err != nil {
213219 return nil , err
@@ -428,7 +434,7 @@ func (b *builder) setupRootFS(ctx context.Context) (err error) {
428434 if err := b .chWriteFile ("/etc/hostname" , b .hostname + "\n " , perm ); err != nil {
429435 return err
430436 }
431- if err := b .chWriteFileIfNotExist ("/etc/hosts" , hosts , perm ); err != nil {
437+ if err := b .chWriteFile ("/etc/hosts" , b . hosts , perm ); err != nil {
432438 return err
433439 }
434440 // TODO(adphi): is it the righ fix ?
0 commit comments