Skip to content

Commit

Permalink
Merge branch 'main' into run-extend
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdarshankumar authored Feb 11, 2024
2 parents b416335 + 5cbc93e commit 3b52e66
Show file tree
Hide file tree
Showing 44 changed files with 1,263 additions and 393 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.21"
- name: Set up go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:
}
shell: powershell
- name: Set up go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.21"
check-latest: true
- name: Set up go env for Unix
if: runner.os != 'Windows'
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
env:
PACK_BUILD: ${{ github.run_number }}
shell: powershell
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: matrix.config != 'windows-lcow'
with:
name: pack-${{ matrix.os }}
Expand All @@ -181,17 +181,17 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.21"
check-latest: true
- name: Build
run: |
[[ $GITHUB_REF =~ ^refs\/heads\/release/(.*)$ ]] && version=${BASH_REMATCH[1]} || version=0.0.0
env PACK_VERSION=${version} GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }} make build
env:
PACK_BUILD: ${{ github.run_number }}
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: pack-${{ matrix.name }}
path: out/${{ env.PACK_BIN }}
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
echo "PACK_MILESTONE=${milestone}" >> $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
- name: Package artifacts - macos
run: |
chmod +x pack-macos/pack
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check-latest-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Read go versions
Expand All @@ -25,7 +25,7 @@ jobs:
LATEST_GO_VERSION=$(go version | cut -d ' ' -f 3)
LATEST_RELEASE_VERSION=$(gh release list -L 1 | cut -d $'\t' -f 1 | cut -d ' ' -f 2)
LATEST_RELEASE_VERSION=$(gh release list --exclude-drafts --exclude-pre-releases -L 1 | cut -d $'\t' -f 1 | cut -d ' ' -f 2)
wget https://github.com/$GITHUB_REPOSITORY/releases/download/$LATEST_RELEASE_VERSION/pack-$LATEST_RELEASE_VERSION-linux.tgz -O out.tgz
tar xzf out.tgz
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -45,7 +45,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -59,4 +59,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
4 changes: 2 additions & 2 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.21"
check-latest: true
- name: Set up go env
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delivery-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: buildpacks/github-actions/[email protected].1
- uses: buildpacks/github-actions/[email protected].2
- name: Buildx Build/Publish
run: |
docker buildx build . \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/delivery-release-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
repo: ['buildpacks/docs', 'buildpacks/samples', 'buildpacks/pack-orb', 'buildpacks/github-actions']
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PLATFORM_GITHUB_TOKEN }}
event-type: pack-release
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ install-golangci-lint:

## mod-tidy: Tidy Go modules
mod-tidy:
$(GOCMD) mod tidy -compat=1.20
cd tools && $(GOCMD) mod tidy -compat=1.20
$(GOCMD) mod tidy -compat=1.21
cd tools && $(GOCMD) mod tidy -compat=1.21

## tidy: Tidy modules and format the code
tidy: mod-tidy format
Expand Down
201 changes: 201 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2929,6 +2929,56 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ]
})
})
})

when("builder create", func() {
when("--flatten=<buildpacks>", func() {
it("should flatten together all specified buildpacks", func() {
h.SkipIf(t, !createBuilderPack.SupportsFeature(invoke.FlattenBuilderCreationV2), "pack version <= 0.33.0 fails with this test")
h.SkipIf(t, imageManager.HostOS() == "windows", "These tests are not yet compatible with Windows-based containers")

// create a task, handled by a 'task manager' which executes our pack commands during tests.
// looks like this is used to de-dup tasks
key := taskKey(
"create-complex-flattened-builder",
append(
[]string{runImageMirror, createBuilderPackConfig.Path(), lifecycle.Identifier()},
createBuilderPackConfig.FixturePaths()...,
)...,
)

builderName, err := suiteManager.RunTaskOnceString(key, func() (string, error) {
return createFlattenBuilder(t,
assert,
buildpackManager,
lifecycle,
createBuilderPack,
runImageMirror)
})
assert.Nil(err)

// register task to be run to 'clean up' a task
suiteManager.RegisterCleanUp("clean-"+key, func() error {
imageManager.CleanupImages(builderName)
return nil
})

assertImage.ExistsLocally(builderName)

// 3 layers for runtime OS
// 1 layer setting cnb, platform, layers folders
// 1 layer for lifecycle binaries
// 1 layer for order.toml
// 1 layer for run.toml
// 1 layer for stack.toml
// 1 layer status file changed
// Base Layers = 9

// 1 layer for 3 flattened builpacks
// 3 layers for single buildpacks not flattened
assertImage.HasLengthLayers(builderName, 13)
})
})
})
})
}

Expand Down Expand Up @@ -3315,6 +3365,157 @@ func createStackImage(dockerCli client.CommonAPIClient, repoName string, dir str
}))
}

func createFlattenBuilder(
t *testing.T,
assert h.AssertionManager,
buildpackManager buildpacks.BuildModuleManager,
lifecycle config.LifecycleAsset,
pack *invoke.PackInvoker,
runImageMirror string,
) (string, error) {
t.Helper()
t.Log("creating flattened builder image...")

// CREATE TEMP WORKING DIR
tmpDir, err := os.MkdirTemp("", "create-complex-test-flattened-builder")
if err != nil {
return "", err
}
defer os.RemoveAll(tmpDir)

// ARCHIVE BUILDPACKS
builderBuildpacks := []buildpacks.TestBuildModule{
buildpacks.BpNoop,
buildpacks.BpNoop2,
buildpacks.BpOtherStack,
buildpacks.BpReadEnv,
}

templateMapping := map[string]interface{}{
"run_image_mirror": runImageMirror,
}

packageImageName := registryConfig.RepoName("nested-level-1-buildpack-" + h.RandString(8))
nestedLevelTwoBuildpackName := registryConfig.RepoName("nested-level-2-buildpack-" + h.RandString(8))
simpleLayersBuildpackName := registryConfig.RepoName("simple-layers-buildpack-" + h.RandString(8))
simpleLayersBuildpackDifferentShaName := registryConfig.RepoName("simple-layers-buildpack-different-name-" + h.RandString(8))

templateMapping["package_id"] = "simple/nested-level-1"
templateMapping["package_image_name"] = packageImageName
templateMapping["nested_level_1_buildpack"] = packageImageName
templateMapping["nested_level_2_buildpack"] = nestedLevelTwoBuildpackName
templateMapping["simple_layers_buildpack"] = simpleLayersBuildpackName
templateMapping["simple_layers_buildpack_different_sha"] = simpleLayersBuildpackDifferentShaName

fixtureManager := pack.FixtureManager()

nestedLevelOneConfigFile, err := os.CreateTemp(tmpDir, "nested-level-1-package.toml")
assert.Nil(err)
fixtureManager.TemplateFixtureToFile(
"nested-level-1-buildpack_package.toml",
nestedLevelOneConfigFile,
templateMapping,
)
err = nestedLevelOneConfigFile.Close()
assert.Nil(err)

nestedLevelTwoConfigFile, err := os.CreateTemp(tmpDir, "nested-level-2-package.toml")
assert.Nil(err)
fixtureManager.TemplateFixtureToFile(
"nested-level-2-buildpack_package.toml",
nestedLevelTwoConfigFile,
templateMapping,
)

err = nestedLevelTwoConfigFile.Close()
assert.Nil(err)

packageImageBuildpack := buildpacks.NewPackageImage(
t,
pack,
packageImageName,
nestedLevelOneConfigFile.Name(),
buildpacks.WithRequiredBuildpacks(
buildpacks.BpNestedLevelOne,
buildpacks.NewPackageImage(
t,
pack,
nestedLevelTwoBuildpackName,
nestedLevelTwoConfigFile.Name(),
buildpacks.WithRequiredBuildpacks(
buildpacks.BpNestedLevelTwo,
buildpacks.NewPackageImage(
t,
pack,
simpleLayersBuildpackName,
fixtureManager.FixtureLocation("simple-layers-buildpack_package.toml"),
buildpacks.WithRequiredBuildpacks(buildpacks.BpSimpleLayers),
),
),
),
),
)

simpleLayersDifferentShaBuildpack := buildpacks.NewPackageImage(
t,
pack,
simpleLayersBuildpackDifferentShaName,
fixtureManager.FixtureLocation("simple-layers-buildpack-different-sha_package.toml"),
buildpacks.WithRequiredBuildpacks(buildpacks.BpSimpleLayersDifferentSha),
)

defer imageManager.CleanupImages(packageImageName, nestedLevelTwoBuildpackName, simpleLayersBuildpackName, simpleLayersBuildpackDifferentShaName)

builderBuildpacks = append(
builderBuildpacks,
packageImageBuildpack,
simpleLayersDifferentShaBuildpack,
)

buildpackManager.PrepareBuildModules(tmpDir, builderBuildpacks...)

// ADD lifecycle
if lifecycle.HasLocation() {
lifecycleURI := lifecycle.EscapedPath()
t.Logf("adding lifecycle path '%s' to builder config", lifecycleURI)
templateMapping["lifecycle_uri"] = lifecycleURI
} else {
lifecycleVersion := lifecycle.Version()
t.Logf("adding lifecycle version '%s' to builder config", lifecycleVersion)
templateMapping["lifecycle_version"] = lifecycleVersion
}

// RENDER builder.toml
builderConfigFile, err := os.CreateTemp(tmpDir, "nested_builder.toml")
if err != nil {
return "", err
}

pack.FixtureManager().TemplateFixtureToFile("nested_builder.toml", builderConfigFile, templateMapping)

err = builderConfigFile.Close()
if err != nil {
return "", err
}

// NAME BUILDER
bldr := registryConfig.RepoName("test/flatten-builder-" + h.RandString(10))

// CREATE BUILDER
output := pack.RunSuccessfully(
"builder", "create", bldr,
"-c", builderConfigFile.Name(),
"--no-color",
"--verbose",
"--flatten", "read/env@read-env-version,[email protected],[email protected]",
)

assert.Contains(output, fmt.Sprintf("Successfully created builder image '%s'", bldr))
assert.Succeeds(h.PushImage(dockerCli, bldr, registryConfig))

return bldr, nil
}

// taskKey creates a key from the prefix and all arguments to be unique
func taskKey(prefix string, args ...string) string {
hash := sha256.New()
Expand Down
1 change: 0 additions & 1 deletion acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func (o OutputAssertionManager) IncludesPrefixedGoogleBuilder() {
}

var herokuBuilders = []string{
"heroku/builder:20",
"heroku/builder:22",
}

Expand Down
4 changes: 4 additions & 0 deletions acceptance/invoke/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const (
BuildpackFlatten
MetaBuildpackFolder
PlatformRetries
FlattenBuilderCreationV2
)

var featureTests = map[Feature]func(i *PackInvoker) bool{
Expand Down Expand Up @@ -266,6 +267,9 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
PlatformRetries: func(i *PackInvoker) bool {
return i.atLeast("v0.32.1")
},
FlattenBuilderCreationV2: func(i *PackInvoker) bool {
return i.atLeast("v0.33.1")
},
}

func (i *PackInvoker) SupportsFeature(f Feature) bool {
Expand Down
2 changes: 1 addition & 1 deletion acceptance/testdata/pack_fixtures/report_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pack:
Version: {{ .Version }}
OS/Arch: {{ .OS }}/{{ .Arch }}

Default Lifecycle Version: 0.17.2
Default Lifecycle Version: 0.18.4

Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12

Expand Down
Loading

0 comments on commit 3b52e66

Please sign in to comment.