Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions hops/llb.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ func CopyLLB(to llb.State, from PackCopies) llb.State {
return copyState
}

// Set the base image where we will pack the unikernel
func BaseLLB(inputBase string, monitor string) llb.State {
// Set the source llb state from the sourceRef image and also set
// the appropriate platform for unikraft images.
func GetSourceState(sourceRef string, monitor string) llb.State {
if monitor == "firecracker" {
monitor = "fc"
}
if inputBase == "scratch" {
if sourceRef == "scratch" {
return llb.Scratch()
}
if strings.HasPrefix(inputBase, unikraftHub) {
if strings.HasPrefix(sourceRef, unikraftHub) {
// Define the platform to qemu/amd64 so we can pull unikraft images
platform := ocispecs.Platform{
OS: monitor,
Architecture: runtime.GOARCH,
}
return llb.Image(inputBase, llb.Platform(platform))
return llb.Image(sourceRef, llb.Platform(platform))
}
return llb.Image(inputBase)

return llb.Image(sourceRef)
}
12 changes: 6 additions & 6 deletions hops/llb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,23 @@ func TestLLBCopy(t *testing.T) {

func TestLLBBase(t *testing.T) {
t.Run("From scratch", func(t *testing.T) {
state := BaseLLB("scratch", "")
state := GetSourceState("scratch", "")
def, err := state.Marshal(context.TODO())

require.NoError(t, err)
_, arr := parseDef(t, def.Def)
require.Equal(t, 0, len(arr))
})
t.Run("From scratch and monitor", func(t *testing.T) {
state := BaseLLB("scratch", "foo")
state := GetSourceState("scratch", "foo")
def, err := state.Marshal(context.TODO())

require.NoError(t, err)
_, arr := parseDef(t, def.Def)
require.Equal(t, 0, len(arr))
})
t.Run("From unikraft and qemu", func(t *testing.T) {
state := BaseLLB("unikraft.org/foo", "qemu")
state := GetSourceState("unikraft.org/foo", "qemu")
def, err := state.Marshal(context.TODO())

require.NoError(t, err)
Expand All @@ -288,7 +288,7 @@ func TestLLBBase(t *testing.T) {
require.Equal(t, "qemu", p.OS)
})
t.Run("From unikraft and firecracker", func(t *testing.T) {
state := BaseLLB("unikraft.org/foo", "firecracker")
state := GetSourceState("unikraft.org/foo", "firecracker")
def, err := state.Marshal(context.TODO())

require.NoError(t, err)
Expand All @@ -302,7 +302,7 @@ func TestLLBBase(t *testing.T) {
require.Equal(t, "fc", p.OS)
})
t.Run("From foo", func(t *testing.T) {
state := BaseLLB("foo", "")
state := GetSourceState("foo", "")
def, err := state.Marshal(context.TODO())

require.NoError(t, err)
Expand All @@ -316,7 +316,7 @@ func TestLLBBase(t *testing.T) {
require.Equal(t, "linux", p.OS)
})
t.Run("From foo and monitor", func(t *testing.T) {
state := BaseLLB("foo", "bar")
state := GetSourceState("foo", "bar")
def, err := state.Marshal(context.TODO())

require.NoError(t, err)
Expand Down
Loading
Loading