Search code examples
buildpack

Using apt install in custom cloud native buildpack


I am trying to create a custom buildpack using this tutorial. I want to use this buildpack for one of the spring boot apps along with other available buildpacks. The buildpack installs tesseract using apt. But I am getting the below exception:

Error when installing tesseract in buildpacks base image

My understanding is this builder image with cnb as the user who doesn't have these permissions. Adding sudo gives command not found.

One way to solve this is to create a Dockerfile with this as the base and do anything needed there as root user and use the resulting image as the builder base image. pack build doesn't have an option to pass the user like docker container run. But this may not be as flexible as buildpacks since the latter can be selected or eliminated using some condition in the detect phase, and so I can specify all the buildpacks in the spring-boot-maven-plugin configuration. Since the whole objective of CNB is to avoid/replace the Dockerfiles, is there any option I am missing here, or is this the only way?

PS: I tried running the base builder as root and achieved what I needed.


Solution

  • There is a community supported apt-buildpack that may help. I believe you would create a Aptfile in your repo with contents like:

    tesseract
    

    Depending on how you're running CNBs, you could add this to your build with a command like:

    $ pack build -b fagiani/[email protected]
    

    For more info see the registry entry for fagiani/apt