Skip to content

Commit

Permalink
Refactors Windows package-buildpack to use baselayer shim
Browse files Browse the repository at this point in the history
Signed-off-by: Micah Young <[email protected]>
  • Loading branch information
Micah Young committed Oct 12, 2020
1 parent 3f57398 commit fabbb05
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 255 deletions.
2 changes: 0 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ func testWithoutSpecificBuilderRequirement(
"pack does not support 'package-buildpack'",
)

h.SkipIf(t, dockerHostOS() == "windows", "These tests are not yet compatible with Windows-based containers")

var err error
tmpDir, err = ioutil.TempDir("", "package-buildpack-tests")
assert.Nil(err)
Expand Down
4 changes: 3 additions & 1 deletion build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,9 @@ func newWindowsImage(name, topLayerSha string, identifier imgutil.Identifier) *f
result := fakes.NewImage(name, topLayerSha, identifier)
arch, _ := result.Architecture()
osVersion, _ := result.OSVersion()
result.SetPlatform("windows", osVersion, arch)
result.SetOS("windows")
result.SetOSVersion(osVersion)
result.SetArchitecture(arch)
return result
}

Expand Down
8 changes: 4 additions & 4 deletions create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {

prepareFetcherWithRunImages()

fakeBuildImage.SetPlatform("windows", "0123", "amd64")
h.AssertNil(t, fakeBuildImage.SetOS("windows"))
mockImageFetcher.EXPECT().Fetch(gomock.Any(), "some/build-image", true, config.PullAlways).Return(fakeBuildImage, nil)

err = packClientWithExperimental.CreateBuilder(context.TODO(), opts)
Expand All @@ -362,7 +362,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
it("fails", func() {
prepareFetcherWithRunImages()

fakeBuildImage.SetPlatform("windows", "0123", "amd64")
h.AssertNil(t, fakeBuildImage.SetOS("windows"))
mockImageFetcher.EXPECT().Fetch(gomock.Any(), "some/build-image", true, config.PullAlways).Return(fakeBuildImage, nil)

err := subject.CreateBuilder(context.TODO(), opts)
Expand Down Expand Up @@ -429,7 +429,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
prepareFetcherWithRunImages()
opts.Config.Lifecycle.URI = ""
opts.Config.Lifecycle.Version = "3.4.5"
fakeBuildImage.SetPlatform("windows", "0123", "amd64")
h.AssertNil(t, fakeBuildImage.SetOS("windows"))

mockDownloader.EXPECT().Download(
gomock.Any(),
Expand Down Expand Up @@ -481,7 +481,7 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
prepareFetcherWithRunImages()
opts.Config.Lifecycle.URI = ""
opts.Config.Lifecycle.Version = ""
fakeBuildImage.SetPlatform("windows", "0123", "amd64")
h.AssertNil(t, fakeBuildImage.SetOS("windows"))

mockDownloader.EXPECT().Download(
gomock.Any(),
Expand Down
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/apex/log v1.1.2-0.20190827100214-baa5455d1012/go.mod h1:Ls949n1HFtXfbDcjiTTFQqkVUrte0puoIBfO3SVgwOA=
github.com/apex/log v1.1.2 h1:bnDuVoi+o98wOdVqfEzNDlY0tcmBia7r4YkjS9EqGYk=
github.com/apex/log v1.1.2/go.mod h1:SyfRweFO+TlkIJ3DVizTSeI1xk7jOIIqOnUPZQTTsww=
github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0=
github.com/apex/log v1.9.0/go.mod h1:m82fZlWIuiWzWP04XCTXmnX0xRkYYbCdYn8jbJeLBEA=
github.com/apex/logs v0.0.3/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo=
github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo=
github.com/aphistic/golf v0.0.0-20180712155816-02c07f170c5a/go.mod h1:3NqKYiepwy8kCu4PNA+aP7WUV72eXWJeP9/r3/K9aLE=
github.com/aphistic/sweet v0.2.0/go.mod h1:fWDlIh/isSE9n6EPsRmC0det+whmX6dJid3stzu0Xys=
Expand Down Expand Up @@ -177,8 +174,6 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/mock v1.4.1 h1:ocYkMQY5RrXTYgXl7ICpV0IXwlEQGwKIsery4gyXa1U=
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -390,8 +385,7 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs=
github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v0.0.7 h1:FfTH+vuMXOas8jmfb5/M7dzEYx7LpcLb7a0LPe34uOU=
github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand All @@ -412,9 +406,11 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
github.com/tj/go-buffer v1.1.0/go.mod h1:iyiJpfFcR2B9sXu7KvjbT9fpM4mOelRSDTbntVj52Uc=
github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0=
Expand Down Expand Up @@ -475,8 +471,6 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -543,7 +537,6 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down Expand Up @@ -643,6 +636,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
Expand Down Expand Up @@ -683,8 +677,6 @@ modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06/go.mod h1:/ULNhyfzRopfcjskuui0cTITekDduZ7ycKN3oUT9R18=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
6 changes: 3 additions & 3 deletions internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
when("building for Windows", func() {
it("sets process isolation", func() {
fakeBuilderImage := ifakes.NewImage("fake-builder", "", nil)
fakeBuilderImage.SetPlatform("windows", "", "")
h.AssertNil(t, fakeBuilderImage.SetOS("windows"))
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithImage(fakeBuilderImage))
h.AssertNil(t, err)
lifecycle := newTestLifecycleExec(t, false, fakes.WithBuilder(fakeBuilder))
Expand Down Expand Up @@ -141,7 +141,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
when("building for Windows", func() {
it("sets daemon access on the config", func() {
fakeBuilderImage := ifakes.NewImage("fake-builder", "", nil)
fakeBuilderImage.SetPlatform("windows", "", "")
h.AssertNil(t, fakeBuilderImage.SetOS("windows"))
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithImage(fakeBuilderImage))
h.AssertNil(t, err)
lifecycle := newTestLifecycleExec(t, false, fakes.WithBuilder(fakeBuilder))
Expand Down Expand Up @@ -242,7 +242,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
when("building for Windows", func() {
it("sets root user on the config", func() {
fakeBuilderImage := ifakes.NewImage("fake-builder", "", nil)
fakeBuilderImage.SetPlatform("windows", "", "")
h.AssertNil(t, fakeBuilderImage.SetOS("windows"))
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithImage(fakeBuilderImage))
h.AssertNil(t, err)
lifecycle := newTestLifecycleExec(t, false, fakes.WithBuilder(fakeBuilder))
Expand Down
103 changes: 68 additions & 35 deletions internal/buildpackage/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package buildpackage
import (
"archive/tar"
"compress/gzip"
"context"
"io"
"io/ioutil"
"os"

"github.com/buildpacks/imgutil/layer"

"github.com/buildpacks/imgutil"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
Expand All @@ -15,24 +17,18 @@ import (
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/pkg/errors"

pubcfg "github.com/buildpacks/pack/config"
"github.com/buildpacks/pack/internal/archive"
"github.com/buildpacks/pack/internal/dist"
"github.com/buildpacks/pack/internal/stack"
"github.com/buildpacks/pack/internal/style"
)

const windowsPackageBase = "mcr.microsoft.com/windows/nanoserver:1809-amd64" // TODO: Should this be hard-coded?

type ImageFactory interface {
NewImage(repoName string, local bool) (imgutil.Image, error)
}

type ImageFetcher interface {
Fetch(ctx context.Context, name string, daemon bool, pullPolicy pubcfg.PullPolicy) (imgutil.Image, error)
}

type WorkableImage interface {
SetOS(string) error
SetLabel(string, string) error
AddLayerWithDiffID(path, diffID string) error
}
Expand All @@ -55,12 +51,22 @@ func (i *layoutImage) SetLabel(key string, val string) error {
return err
}

func (i *layoutImage) SetOS(osVal string) error {
configFile, err := i.ConfigFile()
if err != nil {
return err
}
configFile.OS = osVal
i.Image, err = mutate.ConfigFile(i.Image, configFile)
return err
}

func (i *layoutImage) AddLayerWithDiffID(path, _ string) error {
layer, err := tarball.LayerFromFile(path, tarball.WithCompressionLevel(gzip.DefaultCompression))
tarLayer, err := tarball.LayerFromFile(path, tarball.WithCompressionLevel(gzip.DefaultCompression))
if err != nil {
return err
}
i.Image, err = mutate.AppendLayers(i.Image, layer)
i.Image, err = mutate.AppendLayers(i.Image, tarLayer)
if err != nil {
return errors.Wrap(err, "add layer")
}
Expand All @@ -70,16 +76,12 @@ func (i *layoutImage) AddLayerWithDiffID(path, _ string) error {
type PackageBuilder struct {
buildpack dist.Buildpack
dependencies []dist.Buildpack
imageOS string
imageFactory ImageFactory
imageFetcher ImageFetcher
}

func NewBuilder(imageOS string, imageFactory ImageFactory, imageFetcher ImageFetcher) *PackageBuilder {
func NewBuilder(imageFactory ImageFactory) *PackageBuilder {
return &PackageBuilder{
imageOS: imageOS,
imageFactory: imageFactory,
imageFetcher: imageFetcher,
}
}

Expand All @@ -91,14 +93,24 @@ func (b *PackageBuilder) AddDependency(buildpack dist.Buildpack) {
b.dependencies = append(b.dependencies, buildpack)
}

func (b *PackageBuilder) finalizeImage(tmpDir string, image WorkableImage) error {
func (b *PackageBuilder) finalizeImage(image WorkableImage, imageOS, tmpDir string) error {
if err := dist.SetLabel(image, MetadataLabel, &Metadata{
BuildpackInfo: b.buildpack.Descriptor().Info,
Stacks: b.resolvedStacks(),
}); err != nil {
return err
}

if err := image.SetOS(imageOS); err != nil {
return err
}

if imageOS == "windows" {
if err := addWindowsShimBaseLayer(image, tmpDir); err != nil {
return err
}
}

bpLayers := dist.BuildpackLayers{}
for _, bp := range append(b.dependencies, b.buildpack) {
bpLayerTar, err := dist.BuildpackToLayerTar(tmpDir, bp)
Expand Down Expand Up @@ -128,6 +140,39 @@ func (b *PackageBuilder) finalizeImage(tmpDir string, image WorkableImage) error
return nil
}

func addWindowsShimBaseLayer(image WorkableImage, tmpDir string) error {
baseLayerFile, err := ioutil.TempFile(tmpDir, "windows-baselayer")
if err != nil {
return err
}
defer baseLayerFile.Close()

baseLayer, err := layer.WindowsBaseLayer()
if err != nil {
return err
}

if _, err := io.Copy(baseLayerFile, baseLayer); err != nil {
return err
}

if err := baseLayerFile.Close(); err != nil {
return err
}

baseLayerPath := baseLayerFile.Name()
diffID, err := dist.LayerDiffID(baseLayerPath)
if err != nil {
return err
}

if err := image.AddLayerWithDiffID(baseLayerPath, diffID.String()); err != nil {
return err
}

return nil
}

func (b *PackageBuilder) validate() error {
if b.buildpack == nil {
return errors.New("buildpack must be set")
Expand Down Expand Up @@ -159,7 +204,7 @@ func (b *PackageBuilder) resolvedStacks() []dist.Stack {
return stacks
}

func (b *PackageBuilder) SaveAsFile(path string) error {
func (b *PackageBuilder) SaveAsFile(path, imageOS string) error {
if err := b.validate(); err != nil {
return err
}
Expand All @@ -174,7 +219,7 @@ func (b *PackageBuilder) SaveAsFile(path string) error {
}
defer os.RemoveAll(tmpDir)

if err := b.finalizeImage(tmpDir, layoutImage); err != nil {
if err := b.finalizeImage(layoutImage, imageOS, tmpDir); err != nil {
return err
}

Expand Down Expand Up @@ -204,26 +249,14 @@ func (b *PackageBuilder) SaveAsFile(path string) error {
return archive.WriteDirToTar(tw, layoutDir, "/", 0, 0, 0755, true, nil)
}

func (b *PackageBuilder) SaveAsImage(ctx context.Context, repoName string, publish bool, pullPolicy pubcfg.PullPolicy) (imgutil.Image, error) {
func (b *PackageBuilder) SaveAsImage(repoName string, publish bool, imageOS string) (imgutil.Image, error) {
if err := b.validate(); err != nil {
return nil, err
}

var (
image imgutil.Image
err error
)
if b.imageOS == "windows" {
image, err = b.imageFetcher.Fetch(ctx, windowsPackageBase, !publish, pullPolicy)
if err != nil {
return nil, errors.Wrapf(err, "fetching base image")
}
image.Rename(repoName)
} else {
image, err = b.imageFactory.NewImage(repoName, !publish)
if err != nil {
return nil, errors.Wrapf(err, "creating image")
}
image, err := b.imageFactory.NewImage(repoName, !publish)
if err != nil {
return nil, errors.Wrapf(err, "creating image")
}

tmpDir, err := ioutil.TempDir("", "package-buildpack")
Expand All @@ -232,7 +265,7 @@ func (b *PackageBuilder) SaveAsImage(ctx context.Context, repoName string, publi
}
defer os.RemoveAll(tmpDir)

if err := b.finalizeImage(tmpDir, image); err != nil {
if err := b.finalizeImage(image, imageOS, tmpDir); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit fabbb05

Please sign in to comment.