Created
July 21, 2026 10:46
-
-
Save jonashackt/cee6c5da2555bafa5d9859086239ce7a to your computer and use it in GitHub Desktop.
Use Paketo.io / CloudNativeBuildpacks (CNB) in GitLab CI with Kubernetes executor & unprivileged Runners (without pack CLI & docker) - including Paketo build cache-image and different JDK versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| stages: | |
| - container-image | |
| variables: | |
| # see usage of Namespaces at https://docs.gitlab.com/ee/user/group/#namespaces | |
| REGISTRY_GROUP_PROJECT: $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME | |
| build-publish-image: | |
| stage: container-image | |
| # For a detailed description on how to use Paketo.io Buildpacks in GitLab CI | |
| # with Kubernetes executor & unprivileged Runners (without pack CLI & docker) | |
| # see https://stackoverflow.com/questions/69569784/use-paketo-io-cloudnativebuildpacks-cnb-in-gitlab-ci-with-kubernetes-executo | |
| image: paketobuildpacks/builder-jammy-base | |
| # As we don't have docker available, we can't login to GitLab Container Registry as described in the docs https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#using-the-gitlab-container-registry | |
| # But we somehow need to access GitLab Container Registry with the Paketo lifecycle | |
| # So we simply create ~/.docker/config.json as stated in https://stackoverflow.com/a/46422186/4964553 | |
| before_script: | |
| - mkdir ~/.docker | |
| - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_JOB_TOKEN\"}}}" >> ~/.docker/config.json | |
| # As described in https://buildpacks.io/docs/for-platform-operators/tutorials/lifecycle/#set-environment-variables | |
| # we need to set some variables like the platform api version in order to prevent errors like this: | |
| # failed to get platform API version; please set 'CNB_PLATFORM_API' to specify the desired platform API version | |
| - export CNB_USER_ID=$(id -u) CNB_GROUP_ID=$(id -g) CNB_PLATFORM_API=0.14 | |
| # Configuring Environment variables for the paketo lifecycle is a bit more sophisticated | |
| # As described in https://stackoverflow.com/a/79766353/4964553 & the lifecycle spec https://github.com/buildpacks/spec/blob/main/platform.md#user-provided-variables | |
| # we need to create a single file for each variable, where the file name defines the key and the file contents define the value | |
| # WE NEED TO USE -n with echo, otherwise we have a trailing newline in the environment variable configuration files, that breaks the parameters usage (https://github.com/paketo-buildpacks/libpak/issues/416) | |
| - mkdir -p ~/platform/env | |
| # Using a different JDK than default 21 | |
| - echo -n "25" >> ~/platform/env/BP_JVM_VERSION | |
| # Using a JDK instead of a JRE at runtime (not recommended for default, but used inside the PMS currently for validation, that relies on Java Bytecode) | |
| - echo -n "JDK" >> ~/platform/env/BP_JVM_TYPE | |
| script: | |
| # We need to add the -platform /home/cnb/platform parameter in order to let the lifecycle use our defined environment variables | |
| - /cnb/lifecycle/creator -app . -platform /home/cnb/platform -cache-image $REGISTRY_GROUP_PROJECT/paketo-build-cache:latest $REGISTRY_GROUP_PROJECT:latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment