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

Using build image on all the generated builders on the acceptance/integration tests #50

Merged
merged 5 commits into from
Feb 29, 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
4 changes: 2 additions & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ jobs:
- name: Create stack
id: create-stack
run: |
./scripts/create.sh
scripts/create.sh

## build image
- name: Upload build image
Expand Down Expand Up @@ -603,7 +603,7 @@ jobs:
path: build-java-21

- name: Run Acceptance Tests
run: scripts/test.sh
run: ./scripts/test.sh

force_release_creation:
name: Force Release Creation
Expand Down
21 changes: 8 additions & 13 deletions buildpack_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"

structs "github.com/paketo-community/ubi-base-stack/internal/structs"
utils "github.com/paketo-community/ubi-base-stack/internal/utils"
"github.com/sclevine/spec"

Expand Down Expand Up @@ -62,7 +61,7 @@ func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
})

it("should successfully build a go app", func() {
buildImageID, _, runImageID, runImageUrl, builderImageUrl, err = utils.GenerateBuilder(filepath.Join(root, "build"), RegistryUrl)
buildImageID, _, runImageID, runImageUrl, builderImageUrl, err = utils.GenerateBuilder(root, "build", RegistryUrl)
Expect(err).NotTo(HaveOccurred())

image, _, err = pack.WithNoColor().Build.
Expand Down Expand Up @@ -94,7 +93,7 @@ func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
})
})

context("When building an app using nodejs stacks", func() {
context("When building an app using Node.js stacks", func() {

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expand All @@ -113,17 +112,11 @@ func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
Expect(err).NotTo(HaveOccurred())
})

var stacks []structs.Stack

for _, nodeMajorVersion := range settings.Config.NodeMajorVersions {
stacks = append(stacks, structs.NewStack(nodeMajorVersion, "nodejs", root))
}

for _, stack := range stacks {
// Create a copy of the stack to get the value and instead of the pointer
for _, stack := range settings.Stacks {
// Create a copy of the stack to get the value instead of a pointer
stack := stack
it(fmt.Sprintf("it should successfully build a nodejs app with node version %d", stack.MajorVersion), func() {
buildImageID, _, runImageID, runImageUrl, builderImageUrl, err = utils.GenerateBuilder(stack.AbsPath, RegistryUrl)
buildImageID, _, runImageID, runImageUrl, builderImageUrl, err = utils.GenerateBuilder(root, stack.Path, RegistryUrl)
Expect(err).NotTo(HaveOccurred())

image, _, err = pack.WithNoColor().Build.
Expand Down Expand Up @@ -151,7 +144,9 @@ func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {

Eventually(container).Should(BeAvailable())
Eventually(container).Should(Serve(MatchRegexp(`go1.*`)).OnPort(8080))
Eventually(container).Should(Serve(MatchRegexp(fmt.Sprintf(`v%d.*`, stack.MajorVersion))).OnPort(8080).WithEndpoint("/node/version"))

engineVersionEndpoint := fmt.Sprintf("/nodejs/v%d/version", stack.MajorVersion)
Eventually(container).Should(Serve(MatchRegexp(fmt.Sprintf(`v%d.*`, stack.MajorVersion))).OnPort(8080).WithEndpoint(engineVersionEndpoint))
})
}
})
Expand Down
10 changes: 8 additions & 2 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/paketo-buildpacks/occam"
structs "github.com/paketo-community/ubi-base-stack/internal/structs"
utils "github.com/paketo-community/ubi-base-stack/internal/utils"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
Expand Down Expand Up @@ -52,12 +53,18 @@ var settings struct {
GoDist string `json:"go-dist"`
NodeMajorVersions []int `json:"nodejs-major-versions"`
}

Stacks []structs.Stack
}

func by(_ string, f func()) { f() }

func TestAcceptance(t *testing.T) {

for _, nodeMajorVersion := range settings.Config.NodeMajorVersions {
settings.Stacks = append(settings.Stacks, structs.NewStack(nodeMajorVersion, "nodejs", root))
}

var err error
Expect := NewWithT(t).Expect

Expand All @@ -81,7 +88,6 @@ func TestAcceptance(t *testing.T) {
Execute(settings.Config.UbiNodejsExtension)
Expect(err).ToNot(HaveOccurred())


settings.Buildpacks.Nodejs.Online, err = buildpackStore.Get.
Execute(settings.Config.Nodejs)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -94,7 +100,7 @@ func TestAcceptance(t *testing.T) {
Execute(settings.Config.GoDist)
Expect(err).NotTo(HaveOccurred())

builder.buildImageID, builder.buildImageUrl, builder.runImageID, builder.runImageUrl, builder.imageUrl, err = utils.GenerateBuilder(filepath.Join(root, "build"), RegistryUrl)
builder.buildImageID, builder.buildImageUrl, builder.runImageID, builder.runImageUrl, builder.imageUrl, err = utils.GenerateBuilder(root, "build", RegistryUrl)
Expect(err).NotTo(HaveOccurred())

SetDefaultEventuallyTimeout(120 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/simple_app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
fmt.Fprintln(w, runtime.Version())
})

http.HandleFunc("/node/version", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/nodejs/version", func(w http.ResponseWriter, r *http.Request) {

cmd := exec.Command("node", "--version")

Expand Down
6 changes: 2 additions & 4 deletions internal/structs/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package structs

import (
"fmt"
"path/filepath"
)

type Stack struct {
MajorVersion int
AbsPath string
Path string
Engine string
}

// Create a factory for the stack struct
func NewStack(majorVersion int, engine string, rootDir string) Stack {
return Stack{
MajorVersion: majorVersion,
AbsPath: filepath.Join(rootDir, fmt.Sprintf("build-%s-%d", engine, majorVersion)),
Path: fmt.Sprintf("build-%s-%d", engine, majorVersion),
Engine: engine,
}
}
11 changes: 6 additions & 5 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/paketo-buildpacks/packit/v2/pexec"
)

func GenerateBuilder(stackPath string, registryUrl string) (buildImageID string, buildImageUrl string, runImageID string, runImageUrl string, builderImageUrl string, err error) {
func GenerateBuilder(rootDir string, stackPath string, registryUrl string) (buildImageID string, buildImageUrl string, runImageID string, runImageUrl string, builderImageUrl string, err error) {

buildArchive := filepath.Join(stackPath, "build.oci")
buildImageID = fmt.Sprintf("build-nodejs-%s", uuid.NewString())
buildArchive := filepath.Join(rootDir, "build", "build.oci")
buildImageID = fmt.Sprintf("build-image-%s", uuid.NewString())
err = archiveToDaemon(buildArchive, buildImageID)
if err != nil {
return "", "", "", "", "", err
Expand All @@ -27,12 +27,13 @@ func GenerateBuilder(stackPath string, registryUrl string) (buildImageID string,
return "", "", "", "", "", err
}

runArchive := filepath.Join(stackPath, "run.oci")
runImageID = fmt.Sprintf("run-nodejs-%s", uuid.NewString())
runArchive := filepath.Join(rootDir, stackPath, "run.oci")
runImageID = fmt.Sprintf("run-image-%s", uuid.NewString())
err = archiveToDaemon(runArchive, runImageID)
if err != nil {
return "", "", "", "", "", err
}

runImageUrl, err = PushFileToLocalRegistry(runArchive, registryUrl, runImageID)
if err != nil {
return "", "", "", "", "", err
Expand Down
3 changes: 1 addition & 2 deletions nodejs_stack_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func testNodejsStackIntegration(t *testing.T, context spec.G, it spec.S) {
source string
name string

// These variables probably are not being used
image occam.Image
container occam.Container

Expand Down Expand Up @@ -70,7 +69,7 @@ func testNodejsStackIntegration(t *testing.T, context spec.G, it spec.S) {
// Create a copy of the stack to get the value and instead of the pointer
stack := stack
it(fmt.Sprintf("it successfully builds an app using Nodejs %d run image", stack.MajorVersion), func() {
runArchive := filepath.Join(stack.AbsPath, "run.oci")
runArchive := filepath.Join(root, stack.Path, "run.oci")
bpUbiRunImageOverrideImageID, err = utils.PushFileToLocalRegistry(runArchive, RegistryUrl, fmt.Sprintf("run-%s-%d-%s", stack.Engine, stack.MajorVersion, uuid.NewString()))
Expect(err).NotTo(HaveOccurred())

Expand Down
Loading