redhat-buildpacks / testing

Project aiming to help us to perform e2e tests using Buildpacks
Apache License 2.0
0 stars 3 forks source link

Shipwright: Is there a way to re-use the ENV_VARS ? #14

Closed cmoulliard closed 1 year ago

cmoulliard commented 1 year ago

Problem

The ENV_VARs defined within the BuildRun here

    - name: ENV_VARS
      values:
        - value: BP_NATIVE_IMAGE=false
        - value: BP_MAVEN_BUILT_ARTIFACT=target/quarkus-app/lib/ target/quarkus-app/*.jar target/quarkus-app/app/ target/quarkus-app/quarkus/
        - value: BP_MAVEN_BUILD_ARGUMENTS=package -DskipTests=true -Dmaven.javadoc.skip=true -Dquarkus.package.type=fast-jar

are mounted as /platform/env var during the execution of the Lifecycle prepare step

> Processing any environment variables...
--> Creating 'env' directory: /platform/env
--> Writing /platform/env/BP_NATIVE_IMAGE...
--> Writing /platform/env/BP_MAVEN_BUILT_ARTIFACT...
--> Writing /platform/env/BP_MAVEN_BUILD_ARGUMENTS...

Is it possible to use them when one of the lifecycle phase is executed to avoid to declare them as individual parameter within the BuildStrategy.yaml resource

    - # TODO: Should be defined using ENV_VARS. To be reviewed
      name: BP_NATIVE_IMAGE
      description: Whether to build a native image from the application. Defaults to false.
      default: "false"
    - # TODO: Should be defined using ENV_VARS. To be reviewed
      name: BP_MAVEN_BUILT_ARTIFACT
      description: Configure the built application artifact explicitly. Supersedes $BP_MAVEN_BUILT_MODULE Defaults to target/*.[ejw]ar. Can match a single file, multiple files or a directory. Can be one or more space separated patterns.
      default: "target/*.[ejw]ar"
    - # TODO: Should be defined using ENV_VARS. To be reviewed
      name: BP_MAVEN_BUILD_ARGUMENTS
      description: Configure the arguments to pass to Maven. Defaults to -Dmaven.test.skip=true --no-transfer-progress package. --batch-mode will be prepended to the argument list in environments without a TTY.
      default: "-Dmaven.test.skip=true --no-transfer-progress package"
...
    - name: build-and-push
      image: $(params.CNB_BUILDER_IMAGE)
      imagePullPolicy: Always
      securityContext:
        runAsUser: 1000
        runAsGroup: 1000
      command: ["/cnb/lifecycle/builder"]
      args:
        - "-app=$(workspaces.source.path)/$(params.SOURCE_SUBPATH)"
        - "-layers=/layers"
        - "-group=/layers/group.toml"
        - "-plan=/layers/plan.toml"
        - "-platform=$(params.PLATFORM_DIR)"
      env:
        - name: CNB_PLATFORM_API
          value: $(params.CNB_PLATFORM_API)
        # TODO: Can we retrieve the ENV VARs using Build.Spec.ParamsValues.ENV_VARs ?
        # instead of hard coding them here
        - name: BP_NATIVE_IMAGE
          value: $(params.BP_NATIVE_IMAGE)
        - name: BP_MAVEN_BUILT_ARTIFACT
          value: $(params.BP_MAVEN_BUILT_ARTIFACT)
        - name: BP_MAVEN_BUILD_ARGUMENTS
          value: $(params.BP_MAVEN_BUILD_ARGUMENTS)
cmoulliard commented 1 year ago

The issue was due to this parameter -platform=$(params.PLATFORM_DIR) setted to - '-platform=empty-dir' which is wrong. So we will remove it from the phases where it has been added to fix the problem and also to be aligned with the existing Tekton Buildpack task