Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit 0f36dd1

Browse files
committed
fixed machine-id when building new images
1 parent 9407e59 commit 0f36dd1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

build.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

8+
"code.google.com/p/go-uuid/uuid"
79
"github.com/giantswarm/conair/btrfs"
810
"github.com/giantswarm/conair/nspawn"
911
"github.com/giantswarm/conair/parser"
@@ -55,6 +57,11 @@ func runBuild(args []string) (exit int) {
5557

5658
c := nspawn.Init(container, fmt.Sprintf("%s/%s", getContainerPath(), container))
5759

60+
if err := c.ReplaceMachineId(strings.Replace(uuid.New(), "-", "", -1)); err != nil {
61+
fmt.Fprintln(os.Stderr, "Couldn't set machine-id for temporary build container.", err)
62+
return 1
63+
}
64+
5865
for _, cmd := range f.Commands {
5966
if cmd.Verb == "PKG" {
6067
if err := c.Build("RUN", "pacman -Sy --noconfirm"); err != nil {
@@ -75,8 +82,8 @@ func runBuild(args []string) (exit int) {
7582
}
7683
}
7784
// remove machine id at the end
78-
if err := c.ReplaceMachineId(); err != nil {
79-
fmt.Fprintln(os.Stderr, "Couldn't remove machine-id for new image.", err)
85+
if err := c.ReplaceMachineId("REPLACE_ME"); err != nil {
86+
fmt.Fprintln(os.Stderr, "Couldn't set machine-id placeholder for image.", err)
8087
return 1
8188
}
8289

nspawn/nspawn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ WantedBy=multi-user.target
3131
const nspawnConfigTemplate string = `[Service]
3232
Environment="MACHINE_ID={{.MachineId}}"
3333
`
34-
const nspawnMachineIdTemplate string = `REPLACE_ME
34+
const nspawnMachineIdTemplate string = `{{.MachineId}}
3535
`
3636
const buildstepTemplate string = `#!/bin/sh
3737
mkdir -p /run/systemd/resolve
@@ -283,9 +283,9 @@ func (c *Container) pkg(payload string) (*exec.Cmd, error) {
283283
return c.run(fmt.Sprintf("pacman -S --noconfirm %s", payload))
284284
}
285285

286-
func (c *Container) ReplaceMachineId() error {
286+
func (c *Container) ReplaceMachineId(machineId string) error {
287287
conf := config{
288-
MachineId: strings.Replace(uuid.New(), "-", "", -1),
288+
MachineId: machineId,
289289
}
290290

291291
f, err := os.Create(fmt.Sprintf("%s/etc/machine-id", c.Path))

0 commit comments

Comments
 (0)