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

many: extract newGCETarPipelineForImg() helper #985

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 1 addition & 11 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ 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 @@ -92,15 +90,7 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes
fmt.Sprintf("%s.vhd", fileBasename),
}

// XXX: copied from https://github.com/osbuild/images/blob/v0.85.0/pkg/image/disk.go#L102
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 := newGCETarPipelineForImg(buildPipeline, rawImage, "gce")
gcePipeline.SetFilename("image.tgz")

return nil
Expand Down
9 changes: 1 addition & 8 deletions pkg/image/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"strings"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/environment"
"github.com/osbuild/images/internal/workload"
"github.com/osbuild/images/pkg/artifact"
Expand Down Expand Up @@ -103,13 +102,7 @@ func (img *DiskImage) InstantiateManifest(m *manifest.Manifest,
// NOTE(akoutsou): temporary workaround; filename required for GCP
// TODO: define internal raw filename on image type
rawImagePipeline.SetFilename("disk.raw")
tarPipeline := manifest.NewTar(buildPipeline, rawImagePipeline, "archive")
tarPipeline.Format = osbuild.TarArchiveFormatOldgnu
tarPipeline.RootNode = osbuild.TarRootNodeOmit
// these are required to successfully import the image to GCP
tarPipeline.ACLs = common.ToPtr(false)
tarPipeline.SELinux = common.ToPtr(false)
tarPipeline.Xattrs = common.ToPtr(false)
tarPipeline := newGCETarPipelineForImg(buildPipeline, rawImagePipeline, "archive")
tarPipeline.SetFilename(img.Filename) // filename extension will determine compression
imagePipeline = tarPipeline
default:
Expand Down
24 changes: 24 additions & 0 deletions pkg/image/gce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package image

import (
"fmt"
"regexp"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
)

func newGCETarPipelineForImg(buildPipeline manifest.Build, inputPipeline manifest.FilePipeline, pipelinename string) *manifest.Tar {
tarPipeline := manifest.NewTar(buildPipeline, inputPipeline, pipelinename)
tarPipeline.Format = osbuild.TarArchiveFormatOldgnu
tarPipeline.RootNode = osbuild.TarRootNodeOmit
// these are required to successfully import the image to GCP
tarPipeline.ACLs = common.ToPtr(false)
tarPipeline.SELinux = common.ToPtr(false)
tarPipeline.Xattrs = common.ToPtr(false)
if inputPipeline.Filename() != "disk.raw" {
tarPipeline.Transform = fmt.Sprintf(`s/%s/disk.raw/`, regexp.QuoteMeta(inputPipeline.Filename()))
}
return tarPipeline
}
33 changes: 33 additions & 0 deletions pkg/image/gce_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package image

import (
"testing"

"github.com/stretchr/testify/assert"

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

func TestNewGCETarPipeline(t *testing.T) {
var repos []rpmmd.RepoConfig
m := &manifest.Manifest{}
runner := &runner.Fedora{}

buildPipeline := manifest.NewBuild(m, runner, repos, nil)
buildPipeline.Checkpoint()

imgPipeline := manifest.NewRawImage(buildPipeline, nil)
imgPipeline.SetFilename("foo.img")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well also have a test for disk.raw just to be sure.
Looks good to me though, other than the merge conflict :)


tar := newGCETarPipelineForImg(buildPipeline, imgPipeline, "my-test")
assert.NotNil(t, tar)
assert.Equal(t, tar.Format, osbuild.TarArchiveFormatOldgnu)
assert.Equal(t, tar.RootNode, osbuild.TarRootNodeOmit)
assert.Equal(t, *tar.ACLs, false)
assert.Equal(t, *tar.SELinux, false)
assert.Equal(t, *tar.Xattrs, false)
assert.Equal(t, tar.Transform, `s/foo\.img/disk.raw/`)
}
Loading