Skip to content

Commit 662f15a

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 662f15a

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

deployer/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ 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
4545
return d.Add(opContainerPull,
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 {

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
}

0 commit comments

Comments
 (0)