Skip to content

Commit d794f97

Browse files
committed
Use os-installer comming with metal-hammer instead from metal-images
1 parent 1d4f470 commit d794f97

File tree

9 files changed

+104
-162
lines changed

9 files changed

+104
-162
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ RUN mkdir -p /work/etc/lvm /work/etc/ssl/certs /work/lib/firmware/intel/ice/ddp/
5656
&& cp /usr/share/zoneinfo/Etc/UTC /work/etc/localtime
5757
COPY lvmlocal.conf metal.key metal.key.pub passwd varrun Makefile .git /work/
5858
COPY --from=r.metal-stack.io/metal/supermicro:2.14.0 /usr/bin/sum /work/
59+
COPY --from=ghcr.io/metal-stack/os-installer:v0.1.0 /os-installer /work/os-installer
5960
COPY --from=builder /work/ice.pkg /work/ice.pkg
6061
COPY --from=builder /work/bin/metal-hammer /work/bin/
6162
RUN make ramdisk

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ramdisk:
6565
-format=cpio -build=bb \
6666
-defaultsh=/bin/bash \
6767
-files="bin/metal-hammer:bbin/uinit" \
68+
-files="os-installer:bin/os-installer" \
6869
-files="/bin/bash:bin/bash" \
6970
-files="/bin/netstat:bin/netstat" \
7071
-files="/etc/localtime:etc/localtime" \

cmd/install.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/metal-stack/metal-hammer/cmd/utils"
15-
"github.com/metal-stack/metal-hammer/pkg/api"
15+
apiv1 "github.com/metal-stack/os-installer/api/v1"
1616

1717
"github.com/metal-stack/metal-go/api/models"
1818
img "github.com/metal-stack/metal-hammer/cmd/image"
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
// Install a given image to the disk by using genuinetools/img
25-
func (h *hammer) Install(machine *models.V1MachineResponse) (*api.Bootinfo, error) {
25+
func (h *hammer) Install(machine *models.V1MachineResponse) (*apiv1.Bootinfo, error) {
2626
s := storage.New(h.log, h.chrootPrefix, *h.filesystemLayout)
2727
err := s.Run()
2828
if err != nil {
@@ -60,7 +60,7 @@ func (h *hammer) Install(machine *models.V1MachineResponse) (*api.Bootinfo, erro
6060

6161
// install will execute /install.sh in the pulled docker image which was extracted onto disk
6262
// to finish installation e.g. install mbr, grub, write network and filesystem config
63-
func (h *hammer) install(prefix string, machine *models.V1MachineResponse, rootUUID string) (*api.Bootinfo, error) {
63+
func (h *hammer) install(prefix string, machine *models.V1MachineResponse, rootUUID string) (*apiv1.Bootinfo, error) {
6464
h.log.Info("install", "image", machine.Allocation.Image.URL)
6565

6666
err := h.writeInstallerConfig(machine, rootUUID)
@@ -78,9 +78,13 @@ func (h *hammer) install(prefix string, machine *models.V1MachineResponse, rootU
7878
return nil, err
7979
}
8080

81-
installBinary := "/install.sh"
82-
if fileExists(path.Join(prefix, "install-go")) {
83-
installBinary = "/install-go"
81+
// TODO we still run the binary instead of calling it as a library because it needs to run in a chroot env
82+
// Can be done once we figure out howto fork itself in the chroot.
83+
installBinary := "/bin/os-installer"
84+
85+
_, err = utils.Copy(installBinary, path.Join(prefix, installBinary))
86+
if err != nil {
87+
return nil, fmt.Errorf("unable to copy %s to %s", installBinary, prefix)
8488
}
8589

8690
h.log.Info("running install", "binary", installBinary, "prefix", prefix)
@@ -109,11 +113,6 @@ func (h *hammer) install(prefix string, machine *models.V1MachineResponse, rootU
109113
}
110114
h.log.Info("finish running", "binary", installBinary)
111115

112-
err = os.Remove(path.Join(prefix, installBinary))
113-
if err != nil {
114-
h.log.Warn("unable to remove, ignoring", "binary", installBinary, "error", err)
115-
}
116-
117116
info, err := kernel.ReadBootinfo(path.Join(prefix, "etc", "metal", "boot-info.yaml"))
118117
if err != nil {
119118
return info, fmt.Errorf("unable to read boot-info.yaml %w", err)
@@ -219,7 +218,7 @@ func (h *hammer) writeInstallerConfig(machine *models.V1MachineResponse, rootUUi
219218
raidEnabled = true
220219
}
221220

222-
y := &api.InstallerConfig{
221+
y := &apiv1.InstallerConfig{
223222
Hostname: *alloc.Hostname,
224223
SSHPublicKey: sshPubkeys,
225224
Networks: alloc.Networks,

cmd/reinstall.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"time"
66

77
v1 "github.com/metal-stack/metal-api/pkg/api/v1"
8-
kernelapi "github.com/metal-stack/metal-hammer/pkg/api"
8+
apiv1 "github.com/metal-stack/os-installer/api/v1"
99
"github.com/metal-stack/metal-hammer/pkg/kernel"
1010
)
1111

1212
func (h *hammer) abortReinstall(reason error, machineID string, primaryDiskWiped bool) error {
1313
h.log.Error("reinstall cancelled => boot into existing OS...", "reason", reason)
1414

15-
var bootInfo *kernelapi.Bootinfo
15+
var bootInfo *apiv1.Bootinfo
1616

1717
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1818
defer cancel()
@@ -23,7 +23,7 @@ func (h *hammer) abortReinstall(reason error, machineID string, primaryDiskWiped
2323
}
2424

2525
if resp != nil && resp.BootInfo != nil {
26-
bootInfo = &kernelapi.Bootinfo{
26+
bootInfo = &apiv1.Bootinfo{
2727
Initrd: resp.BootInfo.Initrd,
2828
Cmdline: resp.BootInfo.Cmdline,
2929
Kernel: resp.BootInfo.Kernel,

cmd/storage/filesystem.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/u-root/u-root/pkg/mount/block"
1717

1818
"github.com/metal-stack/metal-go/api/models"
19-
"github.com/metal-stack/metal-hammer/pkg/api"
19+
apiv1 "github.com/metal-stack/os-installer/api/v1"
2020
"github.com/metal-stack/metal-hammer/pkg/os"
2121
"github.com/metal-stack/metal-hammer/pkg/os/command"
2222
"github.com/metal-stack/v"
@@ -31,7 +31,7 @@ type Filesystem struct {
3131
fstabEntries fstabEntries
3232
// disk is the legacy disk.json representatio
3333
// TODO remove once old images are gone
34-
disk api.Disk
34+
disk apiv1.Disk
3535
log *slog.Logger
3636
RootUUID string
3737
}
@@ -53,7 +53,7 @@ func New(log *slog.Logger, chroot string, config models.V1FilesystemLayoutRespon
5353
config: config,
5454
chroot: chroot,
5555
fstabEntries: fstabEntries{},
56-
disk: api.Disk{Device: "legacy", Partitions: []api.Partition{}},
56+
disk: apiv1.Disk{Device: "legacy", Partitions: []apiv1.Partition{}},
5757
log: log,
5858
}
5959
}
@@ -396,7 +396,7 @@ func (f *Filesystem) mountFilesystems() error {
396396
if fs.Label == "root" {
397397
f.RootUUID = partUUID
398398
}
399-
part := api.Partition{
399+
part := apiv1.Partition{
400400
Label: fs.Label,
401401
Filesystem: *fs.Format,
402402
Properties: map[string]string{"UUID": properties["UUID"]},

go.mod

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/metal-stack/go-lldpd v0.4.11
1414
github.com/metal-stack/metal-api v0.43.0
1515
github.com/metal-stack/metal-go v0.43.0
16+
github.com/metal-stack/os-installer v0.1.0
1617
github.com/metal-stack/pixie v0.3.7
1718
github.com/metal-stack/v v1.0.3
1819
// archiver must stay in version v2.1.0, see replace below
@@ -44,6 +45,8 @@ require (
4445
github.com/avast/retry-go/v4 v4.7.0 // indirect
4546
github.com/beorn7/perks v1.0.1 // indirect
4647
github.com/cespare/xxhash/v2 v2.3.0 // indirect
48+
github.com/clipperhouse/stringish v0.1.1 // indirect
49+
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
4750
github.com/coreos/go-oidc/v3 v3.17.0 // indirect
4851
github.com/creack/pty v1.1.24 // indirect
4952
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
@@ -59,28 +62,28 @@ require (
5962
github.com/go-logr/logr v1.4.3 // indirect
6063
github.com/go-logr/stdr v1.2.2 // indirect
6164
github.com/go-ole/go-ole v1.3.0 // indirect
62-
github.com/go-openapi/analysis v0.24.1 // indirect
63-
github.com/go-openapi/errors v0.22.5 // indirect
64-
github.com/go-openapi/jsonpointer v0.22.3 // indirect
65-
github.com/go-openapi/jsonreference v0.21.3 // indirect
65+
github.com/go-openapi/analysis v0.24.2 // indirect
66+
github.com/go-openapi/errors v0.22.6 // indirect
67+
github.com/go-openapi/jsonpointer v0.22.5 // indirect
68+
github.com/go-openapi/jsonreference v0.21.5 // indirect
6669
github.com/go-openapi/loads v0.23.2 // indirect
6770
github.com/go-openapi/runtime v0.29.2 // indirect
68-
github.com/go-openapi/spec v0.22.1 // indirect
71+
github.com/go-openapi/spec v0.22.4 // indirect
6972
github.com/go-openapi/strfmt v0.25.0 // indirect
70-
github.com/go-openapi/swag v0.24.1 // indirect
71-
github.com/go-openapi/swag/cmdutils v0.24.0 // indirect
72-
github.com/go-openapi/swag/conv v0.25.4 // indirect
73-
github.com/go-openapi/swag/fileutils v0.25.4 // indirect
74-
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
75-
github.com/go-openapi/swag/jsonutils v0.25.4 // indirect
76-
github.com/go-openapi/swag/loading v0.25.4 // indirect
77-
github.com/go-openapi/swag/mangling v0.25.4 // indirect
78-
github.com/go-openapi/swag/netutils v0.24.0 // indirect
79-
github.com/go-openapi/swag/stringutils v0.25.4 // indirect
80-
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
81-
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
73+
github.com/go-openapi/swag v0.25.5 // indirect
74+
github.com/go-openapi/swag/cmdutils v0.25.5 // indirect
75+
github.com/go-openapi/swag/conv v0.25.5 // indirect
76+
github.com/go-openapi/swag/fileutils v0.25.5 // indirect
77+
github.com/go-openapi/swag/jsonname v0.25.5 // indirect
78+
github.com/go-openapi/swag/jsonutils v0.25.5 // indirect
79+
github.com/go-openapi/swag/loading v0.25.5 // indirect
80+
github.com/go-openapi/swag/mangling v0.25.5 // indirect
81+
github.com/go-openapi/swag/netutils v0.25.5 // indirect
82+
github.com/go-openapi/swag/stringutils v0.25.5 // indirect
83+
github.com/go-openapi/swag/typeutils v0.25.5 // indirect
84+
github.com/go-openapi/swag/yamlutils v0.25.5 // indirect
8285
github.com/go-openapi/validate v0.25.1 // indirect
83-
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
86+
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
8487
github.com/goccy/go-json v0.10.5 // indirect
8588
github.com/gogo/protobuf v1.3.2 // indirect
8689
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
@@ -98,11 +101,11 @@ require (
98101
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
99102
github.com/mattn/go-colorable v0.1.14 // indirect
100103
github.com/mattn/go-isatty v0.0.20 // indirect
101-
github.com/mattn/go-runewidth v0.0.16 // indirect
104+
github.com/mattn/go-runewidth v0.0.19 // indirect
102105
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
103106
github.com/mdlayher/lldp v0.0.0-20150915211757-afd9f83164c5 // indirect
104-
github.com/metal-stack/metal-lib v0.23.5 // indirect
105-
github.com/metal-stack/security v0.9.5 // indirect
107+
github.com/metal-stack/metal-lib v0.24.0 // indirect
108+
github.com/metal-stack/security v0.9.6 // indirect
106109
github.com/mitchellh/mapstructure v1.5.0 // indirect
107110
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
108111
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -117,7 +120,6 @@ require (
117120
github.com/prometheus/procfs v0.17.0 // indirect
118121
github.com/prometheus/prometheus v0.304.0 // indirect
119122
github.com/rekby/gpt v0.0.0-20200614112001-7da10aec5566 // indirect
120-
github.com/rivo/uniseg v0.4.7 // indirect
121123
github.com/samber/lo v1.52.0 // indirect
122124
github.com/samber/slog-common v0.20.0 // indirect
123125
github.com/segmentio/asm v1.2.1 // indirect

0 commit comments

Comments
 (0)