Skip to content

Commit

Permalink
Moving stacks under the stacks directory (#104)
Browse files Browse the repository at this point in the history
* Moving stacks under the stacks directory
  • Loading branch information
pacostas authored Sep 24, 2024
1 parent 82bf0ad commit 421cc99
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:

concurrency: release
env:
STACKS_FILENAME: "images.json"
STACKS_FILENAME: "stacks/images.json"

jobs:
preparation:
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 2 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
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
21 changes: 19 additions & 2 deletions 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 @@ -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())
Expand All @@ -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: 1 addition & 2 deletions scripts/.syncignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
test.sh
options.json
images.json
options.json
5 changes: 3 additions & 2 deletions scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down 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}/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
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 16 additions & 16 deletions images.json → stacks/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 421cc99

Please sign in to comment.