Skip to content

Commit

Permalink
Merge branch 'main' into automation/github-config/update
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt authored Dec 6, 2024
2 parents db83854 + c5fe218 commit 09455ce
Show file tree
Hide file tree
Showing 1,301 changed files with 229,075 additions and 108,028 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ $ ./scripts/package.sh
This builds the buildpack's source using GOOS=linux by default. You can supply
another value as the first argument to package.sh.

## Specifying a project path
## Configuration

To specify a project subdirectory (i.e. the directory containing your
`.csproj`/`.fsproj`/`.vbproj` file), please use the BP_DOTNET_PROJECT_PATH
environment variable at build time either directly (e.g. pack build my-app
--env BP_DOTNET_PROJECT_PATH=./src/my-app) or through a project.toml file. This
configuration does not apply to FDD, FDE or Self-Contained app deployments.
### `BP_DOTNET_PROJECT_PATH`
To specify a project subdirectory to be used as the root of the app, please use
the `BP_DOTNET_PROJECT_PATH` environment variable at build time either directly
(e.g. `pack build my-app --env BP_DOTNET_PROJECT_PATH=./src/my-app`) or through a
[`project.toml` file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md).

```shell
BP_DOTNET_PROJECT_PATH=./src/my-app
```
13 changes: 0 additions & 13 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/Masterminds/semver"
"github.com/Netflix/go-env"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
Expand All @@ -30,7 +29,6 @@ type SBOMGenerator interface {
// will determine at launch-time which container port the app should listen on.
func Build(
config Configuration,
buildpackYMLParser BuildpackConfigParser,
configParser ConfigParser,
sbomGenerator SBOMGenerator,
logger scribe.Emitter,
Expand All @@ -54,17 +52,6 @@ func Build(
}
logger.Debug.Break()

projectPath, err := buildpackYMLParser.ParseProjectPath(filepath.Join(context.WorkingDir, "buildpack.yml"))
if err != nil {
return packit.BuildResult{}, fmt.Errorf("error parsing buildpack.yml: %w", err)
}

if projectPath != "" {
nextMajorVersion := semver.MustParse(context.BuildpackInfo.Version).IncMajor()
logger.Subprocess("WARNING: Setting the project path through buildpack.yml will be deprecated soon in .NET Execute Buildpack v%s.", nextMajorVersion.String())
logger.Subprocess("Please specify the project path through the $BP_DOTNET_PROJECT_PATH environment variable instead. See README.md or the documentation on paketo.io for more information.")
}

runtimeConfig, err := configParser.Parse(filepath.Join(context.WorkingDir, "*.runtimeconfig.json"))
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to find *.runtimeconfig.json: %w", err)
Expand Down
83 changes: 10 additions & 73 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect

buffer *bytes.Buffer
buildpackYMLParser *fakes.BuildpackConfigParser
cnbDir string
configParser *fakes.ConfigParser
layersDir string
logger scribe.Emitter
sbomGenerator *fakes.SBOMGenerator
workingDir string
buffer *bytes.Buffer
cnbDir string
configParser *fakes.ConfigParser
layersDir string
logger scribe.Emitter
sbomGenerator *fakes.SBOMGenerator
workingDir string

build packit.BuildFunc
)
Expand All @@ -49,15 +48,13 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

configParser = &fakes.ConfigParser{}

buildpackYMLParser = &fakes.BuildpackConfigParser{}

sbomGenerator = &fakes.SBOMGenerator{}
sbomGenerator.GenerateCall.Returns.SBOM = sbom.SBOM{}

buffer = bytes.NewBuffer(nil)
logger = scribe.NewEmitter(buffer)

build = dotnetexecute.Build(dotnetexecute.Configuration{}, buildpackYMLParser, configParser, sbomGenerator, logger, chronos.DefaultClock)
build = dotnetexecute.Build(dotnetexecute.Configuration{}, configParser, sbomGenerator, logger, chronos.DefaultClock)
})

it.After(func() {
Expand Down Expand Up @@ -161,8 +158,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(buildpackYMLParser.ParseProjectPathCall.Receives.Path).To(Equal(filepath.Join(workingDir, "buildpack.yml")))

Expect(configParser.ParseCall.Receives.Glob).To(Equal(filepath.Join(workingDir, "*.runtimeconfig.json")))

Expect(sbomGenerator.GenerateCall.Receives.Path).To(Equal(workingDir))
Expand Down Expand Up @@ -245,7 +240,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

build = dotnetexecute.Build(dotnetexecute.Configuration{
LiveReloadEnabled: true,
}, buildpackYMLParser, configParser, sbomGenerator, logger, chronos.DefaultClock)
}, configParser, sbomGenerator, logger, chronos.DefaultClock)
})

it.After(func() {
Expand Down Expand Up @@ -338,7 +333,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

build = dotnetexecute.Build(dotnetexecute.Configuration{
DebugEnabled: true,
}, buildpackYMLParser, configParser, sbomGenerator, logger, chronos.DefaultClock)
}, configParser, sbomGenerator, logger, chronos.DefaultClock)
})

it.After(func() {
Expand Down Expand Up @@ -385,65 +380,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
})
})

context("The project path is set via buildpack.yml", func() {
it.Before(func() {
buildpackYMLParser.ParseProjectPathCall.Returns.ProjectPath = "src/proj1"
configParser.ParseCall.Returns.RuntimeConfig = dotnetexecute.RuntimeConfig{
Path: filepath.Join(workingDir, "my.app.runtimeconfig.json"),
AppName: "my.app",
Executable: true,
}
})

it("Logs a deprecation warning to the user", func() {
_, err := build(packit.BuildContext{
WorkingDir: workingDir,
CNBPath: cnbDir,
Stack: "some-stack",
BuildpackInfo: packit.BuildpackInfo{
Name: "Some Buildpack",
Version: "1.2.3",
},
Plan: packit.BuildpackPlan{
Entries: []packit.BuildpackPlanEntry{},
},
Layers: packit.Layers{Path: layersDir},
})
Expect(err).NotTo(HaveOccurred())

Expect(buildpackYMLParser.ParseProjectPathCall.Receives.Path).To(Equal(filepath.Join(workingDir, "buildpack.yml")))

Expect(configParser.ParseCall.Receives.Glob).To(Equal(filepath.Join(workingDir, "*.runtimeconfig.json")))

Expect(buffer.String()).To(ContainSubstring("WARNING: Setting the project path through buildpack.yml will be deprecated soon in .NET Execute Buildpack v2.0.0"))
Expect(buffer.String()).To(ContainSubstring("Please specify the project path through the $BP_DOTNET_PROJECT_PATH environment variable instead. See README.md or the documentation on paketo.io for more information."))
})
})

context("failure cases", func() {
context("buildpack.yml parsing fails", func() {
it.Before(func() {
buildpackYMLParser.ParseProjectPathCall.Returns.Err = errors.New("error parsing buildpack.yml")
})

it("logs a warning", func() {
_, err := build(packit.BuildContext{
WorkingDir: workingDir,
CNBPath: cnbDir,
Stack: "some-stack",
BuildpackInfo: packit.BuildpackInfo{
Name: "Some Buildpack",
Version: "some-version",
},
Plan: packit.BuildpackPlan{
Entries: []packit.BuildpackPlanEntry{},
},
Layers: packit.Layers{Path: layersDir},
})
Expect(err).To(MatchError(ContainSubstring("error parsing buildpack.yml")))
})
})

context("runtime config parsing fails", func() {
it.Before(func() {
configParser.ParseCall.Returns.Error = errors.New("error parsing runtimeconfig.json")
Expand Down
47 changes: 0 additions & 47 deletions buildpack_yml_parser.go

This file was deleted.

97 changes: 0 additions & 97 deletions buildpack_yml_parser_test.go

This file was deleted.

14 changes: 0 additions & 14 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ type BuildPlanMetadata struct {
Launch bool `toml:"launch"`
}

//go:generate faux --interface BuildpackConfigParser --output fakes/buildpack_config_parser.go
type BuildpackConfigParser interface {
ParseProjectPath(path string) (projectPath string, err error)
}

//go:generate faux --interface ConfigParser --output fakes/config_parser.go
type ConfigParser interface {
Parse(glob string) (RuntimeConfig, error)
Expand Down Expand Up @@ -65,7 +60,6 @@ type ProjectParser interface {
func Detect(
config Configuration,
logger scribe.Emitter,
buildpackYMLParser BuildpackConfigParser,
configParser ConfigParser,
projectParser ProjectParser,
) packit.DetectFunc {
Expand Down Expand Up @@ -104,14 +98,6 @@ func Detect(
})
}

if config.ProjectPath == "" {
var err error
config.ProjectPath, err = buildpackYMLParser.ParseProjectPath(filepath.Join(context.WorkingDir, "buildpack.yml"))
if err != nil {
return packit.DetectResult{}, fmt.Errorf("failed to parse buildpack.yml: %w", err)
}
}

root := context.WorkingDir
if config.ProjectPath != "" {
root = filepath.Join(root, config.ProjectPath)
Expand Down
Loading

0 comments on commit 09455ce

Please sign in to comment.