Skip to content

Commit

Permalink
dynamically fetching the build directories from images.json
Browse files Browse the repository at this point in the history
  • Loading branch information
pacostas committed Sep 20, 2024
1 parent d2a25ea commit c834438
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions buildpack_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
docker = occam.NewDocker()
})

context("When building an app using default stack", func() {
context("When building GO app using default stack", func() {

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expand All @@ -67,7 +67,7 @@ func testBuildpackIntegration(t *testing.T, context spec.G, it spec.S) {
}

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

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

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

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expand Down
19 changes: 18 additions & 1 deletion init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

var root string
var RegistryUrl string
var DefaultStack StackImages

type StackImages struct {
Name string `json:"name"`
Expand Down Expand Up @@ -121,6 +122,9 @@ func TestAcceptance(t *testing.T) {
settings.ImagesJson.StackImages = filteredStacks
}

DefaultStack = getDefaultStack(settings.ImagesJson.StackImages)
Expect(DefaultStack).NotTo(Equal(StackImages{}))

buildpackStore := occam.NewBuildpackStore()

settings.Extensions.UbiNodejsExtension.Online, err = buildpackStore.Get.
Expand All @@ -139,7 +143,11 @@ func TestAcceptance(t *testing.T) {
Execute(settings.Config.GoDist)
Expect(err).NotTo(HaveOccurred())

builder.buildImageUrl, builder.runImageUrl, builder.imageUrl, err = utils.GenerateBuilder(root, "build", RegistryUrl)
builder.buildImageUrl, builder.runImageUrl, builder.imageUrl, err = utils.GenerateBuilder(
root,
DefaultStack.OutputDir,
RegistryUrl,
)
Expect(err).NotTo(HaveOccurred())

SetDefaultEventuallyTimeout(120 * time.Second)
Expand All @@ -158,3 +166,12 @@ func TestAcceptance(t *testing.T) {
Expect(err).NotTo(HaveOccurred())

}

func getDefaultStack(stackImages []StackImages) StackImages {
for _, stack := range stackImages {
if stack.Name == "default" {
return stack
}
}
return StackImages{}
}
6 changes: 3 additions & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (
"github.com/paketo-buildpacks/packit/v2/pexec"
)

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

buildArchive := filepath.Join(rootDir, "build", "build.oci")
buildArchive := filepath.Join(rootDir, outputDir, "build.oci")
buildImageID := fmt.Sprintf("build-image-%s", uuid.NewString())
buildImageUrl, err = PushFileToLocalRegistry(buildArchive, registryUrl, buildImageID)
if err != nil {
return "", "", "", err
}

runArchive := filepath.Join(rootDir, stackPath, "run.oci")
runArchive := filepath.Join(rootDir, outputDir, "run.oci")
runImageID := fmt.Sprintf("run-image-%s", uuid.NewString())
runImageUrl, err = PushFileToLocalRegistry(runArchive, registryUrl, runImageID)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function main() {

if [ -f "${IMAGES_JSON}" ]; then
# we need to copy images.json for inclusion in the build image
cp $IMAGES_JSON "${ROOT_DIR}/stacks/stack/"
defaultStackPath=$(jq -r '.images[] | select(.name == "default") | .config_dir' "${IMAGES_JSON}")
cp $IMAGES_JSON $ROOT_DIR/$defaultStackPath/images.json
fi

# if stack or build argument is provided but not both, then throw an error
Expand Down

0 comments on commit c834438

Please sign in to comment.