From 421cc99c806a0e734c9fc7ad6e1fa39ad86175da Mon Sep 17 00:00:00 2001 From: Costas Papastathis Date: Tue, 24 Sep 2024 23:11:01 +0300 Subject: [PATCH] Moving stacks under the stacks directory (#104) * Moving stacks under the stacks directory --- .github/workflows/create-release.yml | 4 +-- .gitignore | 11 ++----- buildpack_integration_test.go | 6 ++-- init_test.go | 21 ++++++++++-- internal/utils/utils.go | 6 ++-- scripts/.syncignore | 3 +- scripts/create.sh | 5 +-- scripts/test.sh | 2 +- images.json => stacks/images.json | 32 +++++++++---------- .../stack-java-11}/run.Dockerfile | 0 .../stack-java-11}/stack.toml | 0 .../stack-java-17}/run.Dockerfile | 0 .../stack-java-17}/stack.toml | 0 .../stack-java-21}/run.Dockerfile | 0 .../stack-java-21}/stack.toml | 0 .../stack-java-8}/run.Dockerfile | 0 .../stack-java-8}/stack.toml | 0 .../stack-nodejs-16}/run.Dockerfile | 0 .../stack-nodejs-16}/stack.toml | 0 .../stack-nodejs-18}/run.Dockerfile | 0 .../stack-nodejs-18}/stack.toml | 0 .../stack-nodejs-20}/run.Dockerfile | 0 .../stack-nodejs-20}/stack.toml | 0 {stack => stacks/stack}/build.Dockerfile | 0 {stack => stacks/stack}/run.Dockerfile | 0 {stack => stacks/stack}/stack.toml | 0 26 files changed, 50 insertions(+), 40 deletions(-) rename images.json => stacks/images.json (81%) rename {stack-java-11 => stacks/stack-java-11}/run.Dockerfile (100%) rename {stack-java-11 => stacks/stack-java-11}/stack.toml (100%) rename {stack-java-17 => stacks/stack-java-17}/run.Dockerfile (100%) rename {stack-java-17 => stacks/stack-java-17}/stack.toml (100%) rename {stack-java-21 => stacks/stack-java-21}/run.Dockerfile (100%) rename {stack-java-21 => stacks/stack-java-21}/stack.toml (100%) rename {stack-java-8 => stacks/stack-java-8}/run.Dockerfile (100%) rename {stack-java-8 => stacks/stack-java-8}/stack.toml (100%) rename {stack-nodejs-16 => stacks/stack-nodejs-16}/run.Dockerfile (100%) rename {stack-nodejs-16 => stacks/stack-nodejs-16}/stack.toml (100%) rename {stack-nodejs-18 => stacks/stack-nodejs-18}/run.Dockerfile (100%) rename {stack-nodejs-18 => stacks/stack-nodejs-18}/stack.toml (100%) rename {stack-nodejs-20 => stacks/stack-nodejs-20}/run.Dockerfile (100%) rename {stack-nodejs-20 => stacks/stack-nodejs-20}/stack.toml (100%) rename {stack => stacks/stack}/build.Dockerfile (100%) rename {stack => stacks/stack}/run.Dockerfile (100%) rename {stack => stacks/stack}/stack.toml (100%) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index e501e01..f779345 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -22,7 +22,7 @@ on: concurrency: release env: - STACKS_FILENAME: "images.json" + STACKS_FILENAME: "stacks/images.json" jobs: preparation: @@ -485,7 +485,7 @@ jobs: name=$(echo "$stack" | jq -r '.name') output_dir=$(echo "$stack" | jq -r '.output_dir') create_build_image=$(echo "$stack" | jq -r '.create_build_image') - mkdir $output_dir + mkdir -p $output_dir mv "current-run-image-${name}/run.oci" "${output_dir}/run.oci" if [ $create_build_image == 'true' ]; then mv "current-build-image-${name}/build.oci" "${output_dir}/build.oci" diff --git a/.gitignore b/.gitignore index 1a149f4..5ac0139 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,3 @@ .bin/ -build/ -build-nodejs-16/ -build-nodejs-18/ -build-nodejs-20/ -build-java-8/ -build-java-11/ -build-java-17/ -build-java-21/ -stack/images.json +builds/ +stacks/stack/images.json diff --git a/buildpack_integration_test.go b/buildpack_integration_test.go index 7399ecc..8e66d51 100644 --- a/buildpack_integration_test.go +++ b/buildpack_integration_test.go @@ -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()) @@ -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. @@ -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()) diff --git a/init_test.go b/init_test.go index 3f4fdf4..3783148 100644 --- a/init_test.go +++ b/init_test.go @@ -18,6 +18,7 @@ import ( var root string var RegistryUrl string +var DefaultStack StackImages type StackImages struct { Name string `json:"name"` @@ -96,7 +97,7 @@ func TestAcceptance(t *testing.T) { Expect(json.NewDecoder(integration_json).Decode(&settings.Config)).To(Succeed()) Expect(integration_json.Close()).To(Succeed()) - images_json, err := os.Open("./images.json") + images_json, err := os.Open("./stacks/images.json") Expect(err).NotTo(HaveOccurred()) Expect(json.NewDecoder(images_json).Decode(&settings.ImagesJson)).To(Succeed()) @@ -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. @@ -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) @@ -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{} +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 9db2e23..30d383f 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -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 { diff --git a/scripts/.syncignore b/scripts/.syncignore index 5029858..a97b728 100644 --- a/scripts/.syncignore +++ b/scripts/.syncignore @@ -1,3 +1,2 @@ test.sh -options.json -images.json \ No newline at end of file +options.json \ No newline at end of file diff --git a/scripts/create.sh b/scripts/create.sh index 050ad3f..b15a8a8 100755 --- a/scripts/create.sh +++ b/scripts/create.sh @@ -6,7 +6,7 @@ set -o pipefail readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly ROOT_DIR="$(cd "${PROG_DIR}/.." && pwd)" readonly BIN_DIR="${ROOT_DIR}/.bin" -readonly IMAGES_JSON="${ROOT_DIR}/images.json" +readonly IMAGES_JSON="${ROOT_DIR}/stacks/images.json" # shellcheck source=SCRIPTDIR/.util/tools.sh source "${PROG_DIR}/.util/tools.sh" @@ -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}/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 diff --git a/scripts/test.sh b/scripts/test.sh index 4aecd79..7d263d9 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -5,7 +5,7 @@ set -o pipefail readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly STACK_DIR="$(cd "${PROG_DIR}/.." && pwd)" -readonly STACK_IMAGES_JSON_PATH="${STACK_DIR}/images.json" +readonly STACK_IMAGES_JSON_PATH="${STACK_DIR}/stacks/images.json" readonly INTEGRATION_JSON="${STACK_DIR}/integration.json" declare STACK_IMAGES diff --git a/images.json b/stacks/images.json similarity index 81% rename from images.json rename to stacks/images.json index dc3f250..1ff3410 100644 --- a/images.json +++ b/stacks/images.json @@ -5,8 +5,8 @@ "images": [ { "name": "default", - "config_dir": "stack", - "output_dir": "build", + "config_dir": "stacks/stack", + "output_dir": "builds/build", "build_image": "build", "run_image": "run", "build_receipt_filename": "build-receipt.cyclonedx.json", @@ -17,8 +17,8 @@ }, { "name": "java-8", - "config_dir": "stack-java-8", - "output_dir": "build-java-8", + "config_dir": "stacks/stack-java-8", + "output_dir": "builds/build-java-8", "build_image": "build-java-8", "run_image": "run-java-8", "build_receipt_filename": "build-java-8-receipt.cyclonedx.json", @@ -27,8 +27,8 @@ }, { "name": "java-11", - "config_dir": "stack-java-11", - "output_dir": "build-java-11", + "config_dir": "stacks/stack-java-11", + "output_dir": "builds/build-java-11", "build_image": "build-java-11", "run_image": "run-java-11", "build_receipt_filename": "build-java-11-receipt.cyclonedx.json", @@ -37,8 +37,8 @@ }, { "name": "java-17", - "config_dir": "stack-java-17", - "output_dir": "build-java-17", + "config_dir": "stacks/stack-java-17", + "output_dir": "builds/build-java-17", "build_image": "build-java-17", "run_image": "run-java-17", "build_receipt_filename": "build-java-17-receipt.cyclonedx.json", @@ -47,8 +47,8 @@ }, { "name": "java-21", - "config_dir": "stack-java-21", - "output_dir": "build-java-21", + "config_dir": "stacks/stack-java-21", + "output_dir": "builds/build-java-21", "build_image": "build-java-21", "run_image": "run-java-21", "build_receipt_filename": "build-java-21-receipt.cyclonedx.json", @@ -57,8 +57,8 @@ }, { "name": "nodejs-16", - "config_dir": "stack-nodejs-16", - "output_dir": "build-nodejs-16", + "config_dir": "stacks/stack-nodejs-16", + "output_dir": "builds/build-nodejs-16", "build_image": "build-nodejs-16", "run_image": "run-nodejs-16", "build_receipt_filename": "build-nodejs-16-receipt.cyclonedx.json", @@ -67,8 +67,8 @@ }, { "name": "nodejs-18", - "config_dir": "stack-nodejs-18", - "output_dir": "build-nodejs-18", + "config_dir": "stacks/stack-nodejs-18", + "output_dir": "builds/build-nodejs-18", "build_image": "build-nodejs-18", "run_image": "run-nodejs-18", "build_receipt_filename": "build-nodejs-18-receipt.cyclonedx.json", @@ -78,8 +78,8 @@ { "name": "nodejs-20", "is_default_run_image": true, - "config_dir": "stack-nodejs-20", - "output_dir": "build-nodejs-20", + "config_dir": "stacks/stack-nodejs-20", + "output_dir": "builds/build-nodejs-20", "build_image": "build-nodejs-20", "run_image": "run-nodejs-20", "build_receipt_filename": "build-nodejs-20-receipt.cyclonedx.json", diff --git a/stack-java-11/run.Dockerfile b/stacks/stack-java-11/run.Dockerfile similarity index 100% rename from stack-java-11/run.Dockerfile rename to stacks/stack-java-11/run.Dockerfile diff --git a/stack-java-11/stack.toml b/stacks/stack-java-11/stack.toml similarity index 100% rename from stack-java-11/stack.toml rename to stacks/stack-java-11/stack.toml diff --git a/stack-java-17/run.Dockerfile b/stacks/stack-java-17/run.Dockerfile similarity index 100% rename from stack-java-17/run.Dockerfile rename to stacks/stack-java-17/run.Dockerfile diff --git a/stack-java-17/stack.toml b/stacks/stack-java-17/stack.toml similarity index 100% rename from stack-java-17/stack.toml rename to stacks/stack-java-17/stack.toml diff --git a/stack-java-21/run.Dockerfile b/stacks/stack-java-21/run.Dockerfile similarity index 100% rename from stack-java-21/run.Dockerfile rename to stacks/stack-java-21/run.Dockerfile diff --git a/stack-java-21/stack.toml b/stacks/stack-java-21/stack.toml similarity index 100% rename from stack-java-21/stack.toml rename to stacks/stack-java-21/stack.toml diff --git a/stack-java-8/run.Dockerfile b/stacks/stack-java-8/run.Dockerfile similarity index 100% rename from stack-java-8/run.Dockerfile rename to stacks/stack-java-8/run.Dockerfile diff --git a/stack-java-8/stack.toml b/stacks/stack-java-8/stack.toml similarity index 100% rename from stack-java-8/stack.toml rename to stacks/stack-java-8/stack.toml diff --git a/stack-nodejs-16/run.Dockerfile b/stacks/stack-nodejs-16/run.Dockerfile similarity index 100% rename from stack-nodejs-16/run.Dockerfile rename to stacks/stack-nodejs-16/run.Dockerfile diff --git a/stack-nodejs-16/stack.toml b/stacks/stack-nodejs-16/stack.toml similarity index 100% rename from stack-nodejs-16/stack.toml rename to stacks/stack-nodejs-16/stack.toml diff --git a/stack-nodejs-18/run.Dockerfile b/stacks/stack-nodejs-18/run.Dockerfile similarity index 100% rename from stack-nodejs-18/run.Dockerfile rename to stacks/stack-nodejs-18/run.Dockerfile diff --git a/stack-nodejs-18/stack.toml b/stacks/stack-nodejs-18/stack.toml similarity index 100% rename from stack-nodejs-18/stack.toml rename to stacks/stack-nodejs-18/stack.toml diff --git a/stack-nodejs-20/run.Dockerfile b/stacks/stack-nodejs-20/run.Dockerfile similarity index 100% rename from stack-nodejs-20/run.Dockerfile rename to stacks/stack-nodejs-20/run.Dockerfile diff --git a/stack-nodejs-20/stack.toml b/stacks/stack-nodejs-20/stack.toml similarity index 100% rename from stack-nodejs-20/stack.toml rename to stacks/stack-nodejs-20/stack.toml diff --git a/stack/build.Dockerfile b/stacks/stack/build.Dockerfile similarity index 100% rename from stack/build.Dockerfile rename to stacks/stack/build.Dockerfile diff --git a/stack/run.Dockerfile b/stacks/stack/run.Dockerfile similarity index 100% rename from stack/run.Dockerfile rename to stacks/stack/run.Dockerfile diff --git a/stack/stack.toml b/stacks/stack/stack.toml similarity index 100% rename from stack/stack.toml rename to stacks/stack/stack.toml