Skip to content

Commit

Permalink
fix: renaming the BP_NODE_RUN_EXTENSION to a more generic name BP_UBI…
Browse files Browse the repository at this point in the history
…_RUN_IMAGE_OVERRIDE
  • Loading branch information
pacostas committed Jan 25, 2024
1 parent ba9adb2 commit 7881dd2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ the `BP_NODE_PROJECT_PATH` environment variable at build time either directly
file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md).
This could be useful if your app is a part of a monorepo.

### Setting explicitly a run image `BP_NODE_RUN_EXTENSION`
### Setting explicitly a run image `BP_UBI_RUN_IMAGE_OVERRIDE`

With `BP_NODE_RUN_EXTENSION` environment variable, you are able to specify the run image of the built application, without changing the source code of the extension (specifically the extension.toml file) as shown on below example.
With `BP_UBI_RUN_IMAGE_OVERRIDE` environment variable, you are able to specify the run image of the built application, without changing the source code of the extension (specifically the extension.toml file) as shown on below example.

```bash
pack build test-app-name \
--path ./app-dir \
--builder paketocommunity/builder-ubi-base \
--env BP_NODE_RUN_EXTENSION="localhost:5000/my-run-image"
--env BP_UBI_RUN_IMAGE_OVERRIDE="localhost:5000/my-run-image"
```

## Run Tests
Expand Down
4 changes: 2 additions & 2 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func Generate(dependencyManager DependencyManager, logger scribe.Emitter, during

var selectedNodeRunImage string

bpNodeRunExtension, bpNodeRunExtensionEnvExists := os.LookupEnv("BP_NODE_RUN_EXTENSION")
bpNodeRunExtension, bpNodeRunExtensionEnvExists := os.LookupEnv("BP_UBI_RUN_IMAGE_OVERRIDE")
if !bpNodeRunExtensionEnvExists || bpNodeRunExtension == "" {
selectedNodeRunImage = dependency.Source
} else {
logger.Process("Using run image specified by BP_NODE_RUN_EXTENSION %s", bpNodeRunExtension)
logger.Process("Using run image specified by BP_UBI_RUN_IMAGE_OVERRIDE %s", bpNodeRunExtension)
selectedNodeRunImage = bpNodeRunExtension
}

Expand Down
26 changes: 13 additions & 13 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
})
}, spec.Sequential())

context("When BP_NODE_RUN_EXTENSION env has been set", func() {
context("When BP_UBI_RUN_IMAGE_OVERRIDE env has been set", func() {

it.Before(func() {

Expand All @@ -871,7 +871,7 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Expect(os.RemoveAll(workingDir)).To(Succeed())
})

it("Should have the same value as the BP_NODE_RUN_EXTENSION if is not empty string", func() {
it("Should have the same value as the BP_UBI_RUN_IMAGE_OVERRIDE if is not empty string", func() {

extensionToml, _ := readExtensionTomlTemplateFile()

Expand All @@ -880,8 +880,8 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Expect(os.WriteFile(cnbDir+"/extension.toml", []byte(extensionToml), 0600)).To(Succeed())

entriesTests := []struct {
Entries []packit.BuildpackPlanEntry
BP_NODE_RUN_EXTENSION string
Entries []packit.BuildpackPlanEntry
BP_UBI_RUN_IMAGE_OVERRIDE string
}{
{
Entries: []packit.BuildpackPlanEntry{
Expand All @@ -890,12 +890,12 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Metadata: map[string]interface{}{"version": ">0", "version-source": ".node-version"},
},
},
BP_NODE_RUN_EXTENSION: "testregistry/image-name",
BP_UBI_RUN_IMAGE_OVERRIDE: "testregistry/image-name",
},
}

for _, tt := range entriesTests {
t.Setenv("BP_NODE_RUN_EXTENSION", tt.BP_NODE_RUN_EXTENSION)
t.Setenv("BP_UBI_RUN_IMAGE_OVERRIDE", tt.BP_UBI_RUN_IMAGE_OVERRIDE)

generateResult, err = generate(packit.GenerateContext{
WorkingDir: workingDir,
Expand All @@ -910,7 +910,7 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Expect(generateResult).NotTo(Equal(nil))

RunDockerfileProps := ubinodejsextension.RunDockerfileProps{
Source: tt.BP_NODE_RUN_EXTENSION,
Source: tt.BP_UBI_RUN_IMAGE_OVERRIDE,
}

runDockerfileContent, _ := ubinodejsextension.FillPropsToTemplate(RunDockerfileProps, runDockerfileTemplate)
Expand All @@ -930,9 +930,9 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Expect(os.WriteFile(cnbDir+"/extension.toml", []byte(extensionToml), 0600)).To(Succeed())

entriesTests := []struct {
Entries []packit.BuildpackPlanEntry
selectedNodeVersion int
BP_NODE_RUN_EXTENSION string
Entries []packit.BuildpackPlanEntry
selectedNodeVersion int
BP_UBI_RUN_IMAGE_OVERRIDE string
}{
{
Entries: []packit.BuildpackPlanEntry{
Expand All @@ -941,13 +941,13 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Metadata: map[string]interface{}{"version": "16.*", "version-source": ".node-version"},
},
},
selectedNodeVersion: 16,
BP_NODE_RUN_EXTENSION: "",
selectedNodeVersion: 16,
BP_UBI_RUN_IMAGE_OVERRIDE: "",
},
}

for _, tt := range entriesTests {
t.Setenv("BP_NODE_RUN_EXTENSION", tt.BP_NODE_RUN_EXTENSION)
t.Setenv("BP_UBI_RUN_IMAGE_OVERRIDE", tt.BP_UBI_RUN_IMAGE_OVERRIDE)

generateResult, err = generate(packit.GenerateContext{
WorkingDir: workingDir,
Expand Down
8 changes: 4 additions & 4 deletions integration/fetch_run_image_from_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func testFetchRunImageFromEnv(t *testing.T, context spec.G, it spec.S) {
Expect(os.RemoveAll(source)).To(Succeed())
})

context("when BP_NODE_RUN_EXTENSION is set", func() {
it("uses the run image specified from the BP_NODE_RUN_EXTENSION", func() {
context("when BP_UBI_RUN_IMAGE_OVERRIDE is set", func() {
it("uses the run image specified from the BP_UBI_RUN_IMAGE_OVERRIDE", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "simple_app"))
Expect(err).NotTo(HaveOccurred())
Expand All @@ -71,7 +71,7 @@ func testFetchRunImageFromEnv(t *testing.T, context spec.G, it spec.S) {
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.Processes.Online,
).
WithEnv(map[string]string{"BP_NODE_RUN_EXTENSION": nodeRunImage, "BP_NODE_VERSION": fmt.Sprint(buildNodeMajorVersion)}).
WithEnv(map[string]string{"BP_UBI_RUN_IMAGE_OVERRIDE": nodeRunImage, "BP_NODE_VERSION": fmt.Sprint(buildNodeMajorVersion)}).
WithPullPolicy("always").
Execute(name, source)

Expand All @@ -82,7 +82,7 @@ func testFetchRunImageFromEnv(t *testing.T, context spec.G, it spec.S) {
Expect(logs).To(ContainLines(" Candidate version sources (in priority order):"))
Expect(logs).To(ContainLines(fmt.Sprintf(" BP_NODE_VERSION -> \"%d\"", buildNodeMajorVersion)))
Expect(logs).To(ContainLines(" <unknown> -> \"\""))
Expect(logs).To(ContainLines(fmt.Sprintf(" Using run image specified by BP_NODE_RUN_EXTENSION %s", nodeRunImage)))
Expect(logs).To(ContainLines(fmt.Sprintf(" Using run image specified by BP_UBI_RUN_IMAGE_OVERRIDE %s", nodeRunImage)))

Expect(logs).To(ContainLines(
"[extender (build)] Enabling module streams:",
Expand Down

0 comments on commit 7881dd2

Please sign in to comment.