forked from osbuild/images
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
many: extract newGCETarPipelineForImg() helper
This commit extracts a common helper to setup the right tar options for the GCE tar file generation. The options that need to be passed to tar for GCE need to be exactly right so let's make sure we only have a single place where they are set.
- Loading branch information
Showing
4 changed files
with
68 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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) { | ||
for _, tc := range []struct { | ||
imgFilename string | ||
expectedTransform string | ||
}{ | ||
{"disk.raw", ""}, | ||
{"foo.img", `s/foo\.img/disk.raw/`}, | ||
} { | ||
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(tc.imgFilename) | ||
|
||
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, tc.expectedTransform) | ||
|
||
} | ||
} |