Skip to content

Commit 0abb24e

Browse files
authored
Add BP_DOTNET_RUNTIME_VERSION (#603)
* Add BP_DOTNET_RUNTIME_VERSION * Add env vars metadata
1 parent 3b69993 commit 0abb24e

6 files changed

Lines changed: 92 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ file that looks like the following:
5656

5757
## Configuration
5858

59-
### `BP_DOTNET_FRAMEWORK_VERSION`
60-
The `BP_DOTNET_FRAMEWORK_VERSION` variable allows you to specify the version of
59+
### `BP_DOTNET_RUNTIME_VERSION`
60+
The `BP_DOTNET_RUNTIME_VERSION` variable allows you to specify the version of
6161
ASP.NET Core Runtime that is installed. The environment variable can be
6262
set at build-time either directly (ex. `pack build my-app --env
6363
BP_ENVIRONMENT_VARIABLE=some-value`) or through a [`project.toml`
6464
file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md)
6565

6666
```shell
67-
BP_DOTNET_FRAMEWORK_VERSION=6.0.5
67+
BP_DOTNET_RUNTIME_VERSION=6.0.5
6868
```
6969

7070
### `BP_LOG_LEVEL`

build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func Build(
8686
logger.Process("Resolving ASP.NET Core Runtime version")
8787

8888
priorities := []interface{}{
89+
"BP_DOTNET_RUNTIME_VERSION",
8990
"BP_DOTNET_FRAMEWORK_VERSION",
9091
"runtimeconfig.json",
9192
regexp.MustCompile(`.*\.(cs)|(fs)|(vb)proj`),

buildpack.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ api = "0.8"
1515
include-files = ["buildpack.toml", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/run", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/run"]
1616
pre-package = "./scripts/build.sh --target linux/amd64 --target linux/arm64"
1717

18+
[[metadata.configurations]]
19+
name = "BP_DOTNET_RUNTIME_VERSION"
20+
description = "specify a version of ASP.NET Runtime to use"
21+
build = true
22+
23+
[[metadata.configurations]]
24+
name = "BP_DOTNET_ROLL_FORWARD"
25+
description = "set to 'Disable' to prevent ASP.NET version roll-forward"
26+
build = true
27+
1828
[[metadata.dependencies]]
1929
arch = "amd64"
2030
checksum = "sha512:4aa9458d3de7b4ff960adcc4a655e4d7e4e6570e97791919113b8c9a55883964a60241daf3a70c60494cde1a61155d802339ec03b046466eac67298f0acc7289"

detect.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,36 @@ package dotnetcoreaspnetruntime
22

33
import (
44
"github.com/paketo-buildpacks/packit/v2"
5+
"github.com/paketo-buildpacks/packit/v2/scribe"
56
)
67

78
type Environment struct {
8-
DotnetRollForward string `env:"BP_DOTNET_ROLL_FORWARD"`
9-
DotnetFrameworkVersion string `env:"BP_DOTNET_FRAMEWORK_VERSION"`
9+
DotnetRollForward string `env:"BP_DOTNET_ROLL_FORWARD"`
10+
DotnetRuntimeVersion string `env:"BP_DOTNET_RUNTIME_VERSION"`
11+
DeprecatedDotnetFrameworkVersion string `env:"BP_DOTNET_FRAMEWORK_VERSION"`
1012
}
1113

12-
func Detect(environment Environment) packit.DetectFunc {
14+
func Detect(environment Environment, logger scribe.Emitter) packit.DetectFunc {
1315
return func(context packit.DetectContext) (packit.DetectResult, error) {
1416
var requirements []packit.BuildPlanRequirement
1517

16-
if environment.DotnetFrameworkVersion != "" {
18+
if environment.DotnetRuntimeVersion != "" {
19+
requirements = append(requirements, packit.BuildPlanRequirement{
20+
Name: "dotnet-core-aspnet-runtime",
21+
Metadata: map[string]interface{}{
22+
"version-source": "BP_DOTNET_RUNTIME_VERSION",
23+
"version": environment.DotnetRuntimeVersion,
24+
},
25+
})
26+
}
27+
28+
if environment.DeprecatedDotnetFrameworkVersion != "" {
29+
logger.Subprocess(scribe.YellowColor("WARNING: BP_DOTNET_FRAMEWORK_VERSION is deprecated and will be removed in a future version. Please use BP_DOTNET_RUNTIME_VERSION instead."))
1730
requirements = append(requirements, packit.BuildPlanRequirement{
1831
Name: "dotnet-core-aspnet-runtime",
1932
Metadata: map[string]interface{}{
2033
"version-source": "BP_DOTNET_FRAMEWORK_VERSION",
21-
"version": environment.DotnetFrameworkVersion,
34+
"version": environment.DeprecatedDotnetFrameworkVersion,
2235
},
2336
})
2437
}

detect_test.go

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package dotnetcoreaspnetruntime_test
22

33
import (
4+
"bytes"
45
"os"
56
"testing"
67

78
dotnetcoreaspnetruntime "github.com/paketo-buildpacks/dotnet-core-aspnet-runtime"
89
"github.com/paketo-buildpacks/packit/v2"
10+
"github.com/paketo-buildpacks/packit/v2/scribe"
911
"github.com/sclevine/spec"
1012

1113
. "github.com/onsi/gomega"
@@ -17,14 +19,19 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
1719

1820
workingDir string
1921
detect packit.DetectFunc
22+
buffer *bytes.Buffer
2023
)
2124

2225
it.Before(func() {
2326
var err error
2427
workingDir, err = os.MkdirTemp("", "working-dir")
2528
Expect(err).NotTo(HaveOccurred())
2629

27-
detect = dotnetcoreaspnetruntime.Detect(dotnetcoreaspnetruntime.Environment{})
30+
buffer = bytes.NewBuffer(nil)
31+
detect = dotnetcoreaspnetruntime.Detect(
32+
dotnetcoreaspnetruntime.Environment{},
33+
scribe.NewEmitter(buffer),
34+
)
2835
})
2936

3037
it.After(func() {
@@ -58,11 +65,59 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
5865
}))
5966
})
6067

61-
context("when BP_DOTNET_FRAMEWORK_VERSION is set", func() {
68+
context("when BP_DOTNET_RUNTIME_VERSION is set", func() {
6269
it.Before(func() {
63-
detect = dotnetcoreaspnetruntime.Detect(dotnetcoreaspnetruntime.Environment{
64-
DotnetFrameworkVersion: "1.2.3",
70+
detect = dotnetcoreaspnetruntime.Detect(
71+
dotnetcoreaspnetruntime.Environment{
72+
DotnetRuntimeVersion: "1.2.3",
73+
},
74+
scribe.NewEmitter(buffer))
75+
})
76+
77+
it("provides and requires dotnet core runtime", func() {
78+
result, err := detect(packit.DetectContext{
79+
WorkingDir: workingDir,
6580
})
81+
Expect(err).NotTo(HaveOccurred())
82+
Expect(result.Plan).To(Equal(packit.BuildPlan{
83+
Provides: []packit.BuildPlanProvision{
84+
{
85+
Name: "dotnet-core-aspnet-runtime",
86+
},
87+
},
88+
Requires: []packit.BuildPlanRequirement{
89+
{
90+
Name: "dotnet-core-aspnet-runtime",
91+
Metadata: map[string]interface{}{
92+
"version-source": "BP_DOTNET_RUNTIME_VERSION",
93+
"version": "1.2.3",
94+
},
95+
},
96+
},
97+
Or: []packit.BuildPlan{
98+
{
99+
Provides: []packit.BuildPlanProvision{
100+
{Name: "dotnet-runtime"},
101+
},
102+
},
103+
{
104+
Provides: []packit.BuildPlanProvision{
105+
{Name: "dotnet-runtime"},
106+
{Name: "dotnet-aspnetcore"},
107+
},
108+
},
109+
},
110+
}))
111+
})
112+
})
113+
114+
context("when BP_DOTNET_FRAMEWORK_VERSION is set", func() {
115+
it.Before(func() {
116+
detect = dotnetcoreaspnetruntime.Detect(
117+
dotnetcoreaspnetruntime.Environment{
118+
DeprecatedDotnetFrameworkVersion: "1.2.3",
119+
},
120+
scribe.NewEmitter(buffer))
66121
})
67122

68123
it("provides and requires dotnet core runtime", func() {

run/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func main() {
4444
packit.Run(
4545
dotnetcoreaspnetruntime.Detect(
4646
environment,
47+
logEmitter,
4748
),
4849
dotnetcoreaspnetruntime.Build(
4950
entryResolver,

0 commit comments

Comments
 (0)