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

Adds reproducibility tests #818

Merged
merged 3 commits into from
Apr 11, 2023
Merged
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
18 changes: 10 additions & 8 deletions integration/init_test.go
Original file line number Diff line number Diff line change
@@ -31,20 +31,22 @@ func TestIntegration(t *testing.T) {
Expect(err).NotTo(HaveOccurred())

suite := spec.New("Integration", spec.Parallel(), spec.Report(report.Terminal{}))

// This test will only run on the Bionic full stack, because stack upgrade
// failures have only been observed when upgrading from the Bionic full stack.
// All other tests will run against the Bionic base stack and Jammy base stack
if builder.BuilderName == "paketobuildpacks/builder:buildpackless-full" {
suite("StackUpgrades", testGracefulStackUpgrades)
} else {
suite("Passenger", testPassenger)
suite("Puma", testPuma)
suite("Rackup", testRackup)
suite("RailsAssets", testRailsAssets)
suite("Rake", testRake)
suite("Thin", testThin)
suite("Unicorn", testUnicorn)
}

suite("Passenger", testPassenger)
suite("Puma", testPuma)
suite("Rackup", testRackup)
suite("RailsAssets", testRailsAssets)
suite("Rake", testRake)
suite("ReproducibleBuilds", testReproducibleBuilds)
suite("Thin", testThin)
suite("Unicorn", testUnicorn)

suite.Run(t)
}
321 changes: 321 additions & 0 deletions integration/reproducible_builds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
package integration_test

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
)

func testReproducibleBuilds(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect

pack occam.Pack
docker occam.Docker
)

it.Before(func() {
pack = occam.NewPack()
docker = occam.NewDocker()
})

context("when building a passenger app", func() {
var (
image occam.Image

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "passenger"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a two identical images from the same input", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

firstID := image.ID

// Delete the first image
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
WithClearCache().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(firstID).To(Equal(image.ID))
})
})

context("when building a puma app", func() {
var (
image occam.Image

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "puma"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a two identical images from the same input", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

firstID := image.ID

// Delete the first image
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
WithClearCache().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(firstID).To(Equal(image.ID))
})
})

context("when building a rackup app", func() {
var (
image occam.Image

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "rackup"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a two identical images from the same input", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

firstID := image.ID

// Delete the first image
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
WithClearCache().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(firstID).To(Equal(image.ID))
})
})

context("when building a rake container", func() {
var (
image occam.Image

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "rake"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a two identical images from the same input", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

firstID := image.ID

// Delete the first image
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
WithClearCache().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(firstID).To(Equal(image.ID))
})
})

context("when building a thin app", func() {
var (
image occam.Image

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "thin"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a two identical images from the same input", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

firstID := image.ID

// Delete the first image
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
WithClearCache().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(firstID).To(Equal(image.ID))
})
})

context("when building a unicorn app", func() {
var (
image occam.Image

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "unicorn"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a two identical images from the same input", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

firstID := image.ID

// Delete the first image
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(rubyBuildpack).
WithPullPolicy("never").
WithClearCache().
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(firstID).To(Equal(image.ID))
})
})
}