dockergitlab-cipaketo

How to set environment variables on paketobuildpacks/builder lifecycle for builder layers


I have a GitLab pipeline that builds a simple app, like https://github.com/spring-projects/spring-petclinic using the spring-boot:build-image target. The build works locally, and I deploy or run the image as expected. However, to get deployment working on our lifecycle creator like this:

    image: paketobuildpacks/builder
    variables:
        REGISTRY_GROUP_PROJECT: $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
    before_script:
        - mkdir ~/.docker
        - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_JOB_TOKEN\"}}}" >> ~/.docker/config.json
    script:
        - /cnb/lifecycle/creator -app=. $REGISTRY_GROUP_PROJECT:latest

This sets up the Kubernetes runner properly, and I can execute the build as expected, without having to change anything on the pom.xml definition. However, when trying to update one of the dependencies, I have to set an environment variable to one of the layers, as for some reason the current version will not use the correct packaged jar that I want.

So I want to do a very simple export BP_MAVEN_BUILT_MODULE=myModule before the script step - however, this is not picked up by the lifecycle creator at all. The documentation leads me to believe that I cannot set the environment variable without having to create an entire buildpack just for this - I am trying to look for a solution that doesn't require me to change the entire way of how the build is done just for a single environment variable.

I can verify that the environment variable is being ignored because it still uses the default and prints it on the execution steps, but the result is still a failed build. I have tried setting the variable in different ways, but it is never picked up.

Is there something really simple that I am missing, or is there truly no other way than creating a buildpack just for this?

Mind you, I can create the image just fine by running on my machine:

$ pack build myModule --builder paketobuildpacks/builder:base --env BP_MAVEN_BUILT_MODULE=myModule

And it will pick up the variable properly with pack 0.27.0.


Solution

  • SO only recommended me the exact answer that I needed after I posted it... Configure container image labels using CNB Paketo Image-Labels-Buildpack and the lifecycle creator

    Only had to change the platform key on the command to have the environment name properly, like this if you want to change the JVM_VERSION to 17:

    $ mkdir -p platform/env
    $ echo "17.*" >> platform/env/BP_JVM_VERSION
    $ /cnb/lifecycle/creator -app=. -platform platform $REGISTRY_GROUP_PROJECT:latest
    

    It is a bit weird to have to create the platform folder and I am not sure whether it will change something else, but @VeryDogeWow had a much better way of asking the same thing.