Skip to content

Commit e9104f6

Browse files
committed
Support images in the form of "dir:", in build-iso
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
1 parent 98c1d3f commit e9104f6

File tree

7 files changed

+39
-42
lines changed

7 files changed

+39
-42
lines changed

deployer/register.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
opPrepareNetboot = "prepare-netboot"
2020
opStartNetboot = "start-netboot"
2121

22-
opContainerPull = "container-pull"
22+
opDumpSource = "dump-source"
2323
opGenISO = "gen-iso"
2424
opPreparetmproot = "prepare-temp"
2525
opExtractNetboot = "extract-netboot"
@@ -43,7 +43,7 @@ func RegisterAll(d *Deployer) error {
4343
d.StepPrepNetbootDir,
4444
d.StepPrepISODir,
4545
d.StepCopyCloudConfig,
46-
d.StepPullContainer,
46+
d.StepDumpSource,
4747
d.StepGenISO,
4848
d.StepExtractNetboot,
4949
//TODO: add Validate step

deployer/steps.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ func (d *Deployer) StepCopyCloudConfig() error {
4040
}))
4141
}
4242

43-
func (d *Deployer) StepPullContainer() error {
43+
func (d *Deployer) StepDumpSource() error {
4444
// Ops to generate from container image
45-
return d.Add(opContainerPull,
45+
return d.Add(opDumpSource,
4646
herd.EnableIf(d.fromImage),
47-
herd.WithDeps(opPreparetmproot), herd.WithCallback(ops.PullContainerImage(d.containerImage(), d.tmpRootFs())))
47+
herd.WithDeps(opPreparetmproot), herd.WithCallback(ops.DumpSource(d.containerImage(), d.tmpRootFs())))
4848
}
4949

5050
func (d *Deployer) StepGenISO() error {
5151
return d.Add(opGenISO,
5252
herd.EnableIf(func() bool { return d.fromImage() && !d.rawDiskIsSet() && d.Config.Disk.ARM == nil }),
53-
herd.WithDeps(opContainerPull, opCopyCloudConfig), herd.WithCallback(ops.GenISO(d.tmpRootFs(), d.destination(), d.Config.ISO)))
53+
herd.WithDeps(opDumpSource, opCopyCloudConfig), herd.WithCallback(ops.GenISO(d.tmpRootFs(), d.destination(), d.Config.ISO)))
5454
}
5555

5656
func (d *Deployer) StepExtractNetboot() error {
@@ -233,7 +233,7 @@ func (d *Deployer) isoOption() bool {
233233
}
234234

235235
func (d *Deployer) imageOrSquashFS() herd.OpOption {
236-
return herd.IfElse(d.fromImage(), herd.WithDeps(opContainerPull), herd.WithDeps(opExtractSquashFS))
236+
return herd.IfElse(d.fromImage(), herd.WithDeps(opDumpSource), herd.WithDeps(opExtractSquashFS))
237237
}
238238

239239
func (d *Deployer) cloudConfigPath() string {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ godebug x509negativeserial=1
99
require (
1010
github.com/cavaliergopher/grab/v3 v3.0.1
1111
github.com/containerd/containerd v1.7.23
12-
github.com/distribution/reference v0.6.0
1312
github.com/foxboron/go-uefi v0.0.0-20241017190036-fab4fdf2f2f3
1413
github.com/foxboron/sbctl v0.0.0-20240526163235-64e649b31c8e
1514
github.com/gofrs/uuid v4.4.0+incompatible
@@ -71,6 +70,7 @@ require (
7170
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
7271
github.com/denisbrodbeck/machineid v1.0.1 // indirect
7372
github.com/diskfs/go-diskfs v1.4.2 // indirect
73+
github.com/distribution/reference v0.6.0 // indirect
7474
github.com/djherbis/times v1.6.0 // indirect
7575
github.com/docker/cli v27.1.1+incompatible // indirect
7676
github.com/docker/distribution v2.8.2+incompatible // indirect

internal/cmd/build-iso.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var BuildISOCmd = cli.Command{
113113
d.StepPrepTmpRootDir,
114114
d.StepPrepISODir,
115115
d.StepCopyCloudConfig,
116-
d.StepPullContainer,
116+
d.StepDumpSource,
117117
d.StepGenISO,
118118
} {
119119
if err := step(); err != nil {

pkg/ops/container.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,32 @@ package ops
33
import (
44
"context"
55
"fmt"
6-
"os"
76

8-
"github.com/distribution/reference"
9-
"github.com/kairos-io/AuroraBoot/internal"
10-
sdkUtils "github.com/kairos-io/kairos-sdk/utils"
7+
"github.com/kairos-io/kairos-agent/v2/pkg/elemental"
8+
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
9+
sdkTypes "github.com/kairos-io/kairos-sdk/types"
1110
)
1211

13-
// PullContainerImage pulls a container image either remotely or locally from a docker daemon.
14-
func PullContainerImage(image, dst string) func(ctx context.Context) error {
12+
// DumpSource pulls a container image either remotely or locally from a docker daemon
13+
// or simply copies the directory to the destination.
14+
// Supports these prefixes:
15+
// https://github.com/kairos-io/kairos-agent/blob/1e81cdef38677c8a36cae50d3334559976f66481/pkg/types/v1/common.go#L30-L33
16+
func DumpSource(image, dst string) func(ctx context.Context) error {
1517
return func(ctx context.Context) error {
16-
_, err := reference.ParseNormalizedNamed(image)
17-
if err != nil {
18-
return fmt.Errorf("invalid image reference %s", image)
19-
}
18+
cfg := NewConfig(
19+
WithImageExtractor(v1.OCIImageExtractor{}),
20+
WithLogger(sdkTypes.NewKairosLogger("auroraboot-dump-source", "debug", false)),
21+
)
22+
e := elemental.NewElemental(cfg)
2023

21-
img, err := sdkUtils.GetImage(image, "", nil, nil)
24+
imgSource, err := v1.NewSrcFromURI(image)
2225
if err != nil {
23-
internal.Log.Logger.Error().Err(err).Str("image", image).Msg("failed to pull image")
2426
return err
2527
}
26-
internal.Log.Logger.Info().Msgf("Pulling container image '%s' to '%s')", image, dst)
27-
28-
// This method already first tries the local registry and then moves to remote, so no need to pass local
29-
err = os.MkdirAll(dst, os.ModeDir|os.ModePerm)
30-
if err != nil {
31-
internal.Log.Logger.Error().Err(err).Str("image", image).Msg("failed to create directory")
28+
if _, err := e.DumpSource(dst, imgSource); err != nil {
29+
return fmt.Errorf("dumping the source image %s: %w", image, err)
3230
}
33-
err = sdkUtils.ExtractOCIImage(img, dst)
34-
if err != nil {
35-
internal.Log.Logger.Error().Err(err).Str("image", image).Msg("failed to extract OCI image")
36-
}
37-
return err
31+
32+
return nil
3833
}
3934
}

tests/e2e/disks_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var _ = Describe("Disk image generation", Label("raw-disks"), func() {
4343
Expect(out).To(ContainSubstring("gen-raw-disk"), out)
4444
Expect(out).To(ContainSubstring("download-squashfs"), out)
4545
Expect(out).To(ContainSubstring("extract-squashfs"), out)
46-
Expect(out).ToNot(ContainSubstring("container-pull"), out)
46+
Expect(out).ToNot(ContainSubstring("dump-source"), out)
4747
Expect(err).ToNot(HaveOccurred(), out)
4848
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw"))
4949
Expect(err).ToNot(HaveOccurred())
@@ -65,7 +65,7 @@ var _ = Describe("Disk image generation", Label("raw-disks"), func() {
6565
Expect(out).To(ContainSubstring("gen-raw-disk"), out)
6666
Expect(out).To(ContainSubstring("download-squashfs"), out)
6767
Expect(out).To(ContainSubstring("extract-squashfs"), out)
68-
Expect(out).ToNot(ContainSubstring("container-pull"), out)
68+
Expect(out).ToNot(ContainSubstring("dump-source"), out)
6969
Expect(err).ToNot(HaveOccurred(), out)
7070
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw.gce"))
7171
Expect(err).ToNot(HaveOccurred())
@@ -87,7 +87,7 @@ var _ = Describe("Disk image generation", Label("raw-disks"), func() {
8787
Expect(out).To(ContainSubstring("gen-raw-disk"), out)
8888
Expect(out).To(ContainSubstring("download-squashfs"), out)
8989
Expect(out).To(ContainSubstring("extract-squashfs"), out)
90-
Expect(out).ToNot(ContainSubstring("container-pull"), out)
90+
Expect(out).ToNot(ContainSubstring("dump-source"), out)
9191
Expect(err).ToNot(HaveOccurred(), out)
9292
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw.vhd"))
9393
Expect(err).ToNot(HaveOccurred())
@@ -109,7 +109,7 @@ var _ = Describe("Disk image generation", Label("raw-disks"), func() {
109109
// Expect(out).To(ContainSubstring("gen-raw-mbr-disk"), out)
110110
// Expect(out).To(ContainSubstring("download-squashfs"), out)
111111
// Expect(out).To(ContainSubstring("extract-squashfs"), out)
112-
// Expect(out).ToNot(ContainSubstring("container-pull"), out)
112+
// Expect(out).ToNot(ContainSubstring("dump-source"), out)
113113
// Expect(err).ToNot(HaveOccurred(), out)
114114
// _, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw.gce"))
115115
// Expect(err).ToNot(HaveOccurred())
@@ -184,7 +184,7 @@ stages:
184184
Expect(out).To(ContainSubstring("Generating raw disk"), out)
185185
Expect(out).ToNot(ContainSubstring("build-arm-image"), out)
186186
Expect(out).To(ContainSubstring("gen-raw-disk"), out)
187-
Expect(out).To(ContainSubstring("container-pull"), out)
187+
Expect(out).To(ContainSubstring("dump-source"), out)
188188
Expect(err).ToNot(HaveOccurred(), out)
189189
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw"))
190190
Expect(err).ToNot(HaveOccurred())
@@ -205,7 +205,7 @@ stages:
205205
Expect(out).ToNot(ContainSubstring("build-arm-image"), out)
206206
Expect(out).To(ContainSubstring("gen-raw-disk"), out)
207207
Expect(out).To(ContainSubstring("convert-gce"), out)
208-
Expect(out).To(ContainSubstring("container-pull"), out)
208+
Expect(out).To(ContainSubstring("dump-source"), out)
209209
Expect(err).ToNot(HaveOccurred(), out)
210210
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw.gce"))
211211
Expect(err).ToNot(HaveOccurred())
@@ -226,7 +226,7 @@ stages:
226226
Expect(out).ToNot(ContainSubstring("build-arm-image"), out)
227227
Expect(out).To(ContainSubstring("gen-raw-disk"), out)
228228
Expect(out).To(ContainSubstring("convert-vhd"), out)
229-
Expect(out).To(ContainSubstring("container-pull"), out)
229+
Expect(out).To(ContainSubstring("dump-source"), out)
230230
Expect(err).ToNot(HaveOccurred(), out)
231231
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw.vhd"))
232232
Expect(err).ToNot(HaveOccurred())
@@ -247,7 +247,7 @@ stages:
247247
Expect(out).To(ContainSubstring("Generating MBR disk"), out)
248248
Expect(out).ToNot(ContainSubstring("build-arm-image"), out)
249249
Expect(out).To(ContainSubstring("gen-raw-mbr-disk"), out)
250-
Expect(out).To(ContainSubstring("container-pull"), out)
250+
Expect(out).To(ContainSubstring("dump-source"), out)
251251
Expect(err).ToNot(HaveOccurred(), out)
252252
_, err = os.Stat(filepath.Join(tempDir, "build/build/disk.raw"))
253253
Expect(err).ToNot(HaveOccurred())

tests/e2e/iso_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ var _ = Describe("ISO image generation", Label("iso"), func() {
4545
})
4646

4747
It("fails if cloud config is empty", func() {
48+
image := "quay.io/kairos/core-rockylinux:latest"
49+
4850
err := WriteConfig("", tempDir)
4951
Expect(err).ToNot(HaveOccurred())
5052

51-
out, err := RunAurora(fmt.Sprintf(`--set container_image=quay.io/kairos/core-rockylinux:latest \
53+
out, err := RunAurora(fmt.Sprintf(`--set container_image=oci://%s \
5254
--set "disable_http_server=true" \
5355
--set "disable_netboot=true" \
5456
--cloud-config /config.yaml \
55-
--set "state_dir=/tmp/auroraboot"`), tempDir)
57+
--set "state_dir=/tmp/auroraboot"`, image), tempDir)
5658
Expect(err).To(HaveOccurred(), out)
5759
Expect(out).To(MatchRegexp("cloud config set but contents are empty"))
5860
})

0 commit comments

Comments
 (0)