Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image: add new gce pipeline to BootcDiskImage #923

Merged
merged 3 commits into from
Sep 26, 2024
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: 14 additions & 0 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package image
import (
"fmt"
"math/rand"
"regexp"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/container"
"github.com/osbuild/images/pkg/customizations/users"
"github.com/osbuild/images/pkg/disk"
Expand Down Expand Up @@ -89,5 +91,17 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes
fmt.Sprintf("%s.vmdk", fileBasename),
fmt.Sprintf("%s.vhd", fileBasename),
}

// XXX: copied from https://github.com/osbuild/images/blob/v0.85.0/pkg/image/disk.go#L102
achilleas-k marked this conversation as resolved.
Show resolved Hide resolved
gcePipeline := manifest.NewTar(buildPipeline, rawImage, "gce")
gcePipeline.Format = osbuild.TarArchiveFormatOldgnu
gcePipeline.RootNode = osbuild.TarRootNodeOmit
// these are required to successfully import the image to GCP
gcePipeline.ACLs = common.ToPtr(false)
gcePipeline.SELinux = common.ToPtr(false)
gcePipeline.Xattrs = common.ToPtr(false)
gcePipeline.Transform = fmt.Sprintf(`s/%s/disk.raw/`, regexp.QuoteMeta(rawImage.Filename()))
gcePipeline.SetFilename("image.tgz")

return nil
}
4 changes: 4 additions & 0 deletions pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func TestBootcDiskImageExportPipelines(t *testing.T) {
// tar pipeline for ova
tarPipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "archive")
require.NotNil(tarPipeline)

// gce pipeline
gcePipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "gce")
require.NotNil(gcePipeline)
}

func TestBootcDiskImageInstantiateUsers(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/manifest/export_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
package manifest

import (
"github.com/osbuild/images/pkg/osbuild"
)

var FindStage = findStage

func (p *Tar) Serialize() osbuild.Pipeline {
return p.serialize()
}
28 changes: 15 additions & 13 deletions pkg/manifest/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ type Tar struct {
Base
filename string

Format osbuild.TarArchiveFormat
RootNode osbuild.TarRootNode
Paths []string
ACLs *bool
SELinux *bool
Xattrs *bool
Format osbuild.TarArchiveFormat
RootNode osbuild.TarRootNode
Paths []string
ACLs *bool
SELinux *bool
Xattrs *bool
Transform string

inputPipeline Pipeline
}
Expand Down Expand Up @@ -50,13 +51,14 @@ func (p *Tar) serialize() osbuild.Pipeline {
pipeline := p.Base.serialize()

tarOptions := &osbuild.TarStageOptions{
Filename: p.Filename(),
Format: p.Format,
ACLs: p.ACLs,
SELinux: p.SELinux,
Xattrs: p.Xattrs,
RootNode: p.RootNode,
Paths: p.Paths,
Filename: p.Filename(),
Format: p.Format,
ACLs: p.ACLs,
SELinux: p.SELinux,
Xattrs: p.Xattrs,
RootNode: p.RootNode,
Paths: p.Paths,
Transform: p.Transform,
}
tarStage := osbuild.NewTarStage(tarOptions, p.inputPipeline.Name())
pipeline.AddStage(tarStage)
Expand Down
35 changes: 35 additions & 0 deletions pkg/manifest/tar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package manifest_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/runner"
)

func TestTarSerialize(t *testing.T) {
mani := manifest.New()
runner := &runner.Linux{}
build := manifest.NewBuild(&mani, runner, nil, nil)

// setup
rawImage := manifest.NewRawImage(build, nil)
tarPipeline := manifest.NewTar(build, rawImage, "tar-pipeline")
tarPipeline.SetFilename("filename.tar")
tarPipeline.Transform = "s/foo/bar"

// run
osbuildPipeline := tarPipeline.Serialize()

// assert
assert.Equal(t, "tar-pipeline", osbuildPipeline.Name)
assert.Equal(t, 1, len(osbuildPipeline.Stages))
tarStage := osbuildPipeline.Stages[0]
assert.Equal(t, &osbuild.TarStageOptions{
Filename: "filename.tar",
Transform: "s/foo/bar",
}, tarStage.Options.(*osbuild.TarStageOptions))
}
3 changes: 3 additions & 0 deletions pkg/osbuild/tar_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type TarStageOptions struct {

// List of paths to include, instead of the whole tree
Paths []string `json:"paths,omitempty"`

// Pass --transform=...
Transform string `json:"transform,omitempty"`
achilleas-k marked this conversation as resolved.
Show resolved Hide resolved
}

func (TarStageOptions) isStageOptions() {}
Expand Down
14 changes: 14 additions & 0 deletions pkg/osbuild/tar_stage_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package osbuild

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -77,3 +78,16 @@ func TestTarStageOptionsValidate(t *testing.T) {
})
}
}

func TestTarStageOptionsJSON(t *testing.T) {
stageOptions := &TarStageOptions{
Filename: "archive.tar.xz",
Transform: "s/foo/bar/",
}
b, err := json.MarshalIndent(stageOptions, "", " ")
assert.NoError(t, err)
assert.Equal(t, string(b), `{
"filename": "archive.tar.xz",
"transform": "s/foo/bar/"
}`)
}
Loading