Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine documentation for bootBuildImage and use the additive form for lists and maps #32886

Closed
bitbaggi opened this issue Oct 26, 2022 · 7 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@bitbaggi
Copy link

Hello,

i have the normal vanilla Spring Boot 3.0.0-RC1 with only org.graalvm.buildtools.native as extra plugin.
You can download it from here Spring Initializr

When i try to build with gradlew bootBuildImage with buildpacks and environment it gives me an error.

Running creator
    [creator]     Restoring data for SBOM from previous image 
    [creator]     ===> DETECTING                              
    [creator]     ERROR: No buildpack groups passed detection.
    [creator]     ERROR: Please check that you are running against the correct path.
    [creator]     ERROR: failed to detect: no buildpacks participating

My bootBuildImage task is configured in build.gradle:

tasks.named('bootBuildImage') {
    builder = 'docker.io/paketobuildpacks/builder:tiny'
    runImage = 'docker.io/paketobuildpacks/run:tiny-cnb'
    buildpacks = ['gcr.io/paketo-buildpacks/bellsoft-liberica:9.9.0-ea', 'gcr.io/paketo-buildpacks/java-native-image']
    environment = [
            'BP_NATIVE_IMAGE_BUILD_ARGUMENTS': '--verbose'
    ]
}

The --verbose is only a test, i try to add a reflection-config.json to native image.

When i remove the environment part from task configuration everything is fine.

plugins {
    id 'org.springframework.boot' version '3.0.0-RC1'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'org.graalvm.buildtools.native' version '0.9.16'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('bootBuildImage') {
    builder = 'docker.io/paketobuildpacks/builder:tiny'
    runImage = 'docker.io/paketobuildpacks/run:tiny-cnb'
    buildpacks = ['gcr.io/paketo-buildpacks/bellsoft-liberica:9.9.0-ea', 'gcr.io/paketo-buildpacks/java-native-image']
    environment = [
            'BP_NATIVE_IMAGE_BUILD_ARGUMENTS': '--verbose'
    ]
}

tasks.named('test') {
    useJUnitPlatform()
}

Did i anything wrong?
Can i not use environment and buildpacks in combination?

Thank you.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 26, 2022
@scottfrederick
Copy link
Contributor

@bitbaggi This should work if you also add 'BP_NATIVE_IMAGE': 'true' to the environment in your build configuration. The Spring Boot Gradle plugin adds that by default, but it appears your configuration is overriding all environment variables set by default.

@scottfrederick scottfrederick added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 26, 2022
@scottfrederick scottfrederick modified the milestones: 3.0.0, 3.0.0-RC2 Oct 26, 2022
@wilkinsona
Copy link
Member

wilkinsona commented Oct 26, 2022

I don't think this is a bug. The syntax used is assigning a new Map to the environment rather than adding an entry to it. You can add an entry like this:

tasks.named('bootBuildImage') {
    environment['BP_NATIVE_IMAGE_BUILD_ARGUMENTS'] = '--verbose'
}

Or add multiple entries like this:

environment.putAll([
    'BP_NATIVE_IMAGE_BUILD_ARGUMENTS': '--verbose',
    'EXAMPLE': 'VALUE'
])

I think it's important that we support assignment replacing our defaults so that users can take complete control of the environment if needs be.

@scottfrederick
Copy link
Contributor

We should review the documentation for bootBuildImage and use the additive form for lists and maps in our examples then, to prevent this type of problem (and so everyone doesn't have to figure out the Groovy or Kotlin syntax).

@bitbaggi
Copy link
Author

Yeah, thank you @wilkinsona

environment['BP_NATIVE_IMAGE_BUILD_ARGUMENTS'] = '--verbose' is working

@wilkinsona
Copy link
Member

Thanks for the confirmation, @bitbaggi. I'm going to re-open this issue so that we can review the documentation.

@wilkinsona wilkinsona reopened this Oct 27, 2022
@wilkinsona wilkinsona modified the milestones: 3.0.0-RC2, 3.0.x Nov 10, 2022
@wilkinsona wilkinsona added the status: on-hold We can't start working on this issue yet label Nov 10, 2022
@philwebb philwebb changed the title bootBuildImage fails with combination of environment and buildpacks Refine documentation for bootBuildImage and use the additive form for lists and maps Nov 10, 2022
candrews added a commit to candrews/jumpstart that referenced this issue Nov 30, 2022
Assigning a new value to environment replaces all mappings. By assigning to individual keys, the existing map is updated so defaults are preserved.

See: spring-projects/spring-boot#32886
@candrews
Copy link
Contributor

I've submitted an MR to update the documentation as discussed in this issue: #33424

@philwebb
Copy link
Member

Closing in favor of PR #33424. Thanks @candrews!

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2022
@philwebb philwebb removed this from the 3.0.x milestone Nov 30, 2022
@philwebb philwebb removed the type: documentation A documentation update label Nov 30, 2022
@philwebb philwebb added status: superseded An issue that has been superseded by another and removed status: on-hold We can't start working on this issue yet labels Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants