Using apt buildpack to install extra packages onto Linux container for application on Tanzu Platform for Cloud Foundry
search cancel

Using apt buildpack to install extra packages onto Linux container for application on Tanzu Platform for Cloud Foundry

book

Article ID: 387600

calendar_today

Updated On:

Products

VMware Tanzu Application Service

Issue/Introduction

When pushing an application onto Tanzu Platform for Cloud Foundry (TPCF) foundation, a droplet will be created during staging to include necessary system packages for running the application. However, sometimes there might be special need to install extra packages onto Linux container for running the application in a different way. This article shows how to install extra packages using apt buildpack, which is also mentioned in another KB article

Environment

Tanzu Platform for Cloud Foundry (TPCF), which is formerly called Tanzu Application Service (TAS)

Cause

For apps deployed in Cloud Foundry, its best practice to follow 12 factor app
 

"Twelve-factor apps also do not rely on the implicit existence of any system tools. Examples include shelling out to ImageMagick or curl. While these tools may exist on many or even most systems, there is no guarantee that they will exist on all systems where the app may run in the future, or whether the version found on a future system will be compatible with the app. If the app needs to shell out to a system tool, that tool should be vendored into the app."
 
Therefore, some packages like shared objects libraries can not be vendored. It needs to be installed by the users themselves as necessary.

Resolution

For application running in Linux environment, the apt buildpack can be utilised to install packages that are not included by default. Here are the detailed steps.

1. Download apt-buildpack package file from https://github.com/cloudfoundry/apt-buildpack/releases, For example,

https://github.com/cloudfoundry/apt-buildpack/releases/download/v0.3.6/apt-buildpack-cflinuxfs4-v0.3.6.zip

2. Create apt-buildpack in TPCF environment

$ cf create-buildpack apt_buildpack apt-buildpack-cflinuxfs4-v0.3.6.zip 14
 Creating buildpack apt_buildpack as admin...
 OK
 
 Uploading buildpack apt_buildpack as admin...
  2.53 MiB / 2.53 MiB [===========================================================================================================================================================================] 100.00% 1s
 OK
 
 Processing uploaded buildpack apt_buildpack...
 OK
 
 $ cf buildpacks
 Getting buildpacks as admin...
 
 position   name                     stack        enabled   locked   state   filename
 1          staticfile_buildpack     cflinuxfs4   true      false    READY   staticfile_buildpack-cached-cflinuxfs4-v1.6.21.zip
 2          binary_buildpack         cflinuxfs4   true      false    READY   binary_buildpack-cached-cflinuxfs4-v1.1.15.zip
 ......
 14         apt_buildpack            cflinuxfs4   true      false    READY   apt-buildpack-cflinuxfs4-v0.3.6.zip

3. Create a file called apt.yml in app source directory, which includes the package to install. For example, to install extra package libnss3-tools

~/python-web-app$ ls -l
total 56
-rw-rw-r-- 1 ubuntu ubuntu 11504 Feb  5 04:26 accelerator-log.md
-rw-rw-r-- 1 ubuntu ubuntu    30 Feb  5 07:06 apt.yml
drwxrwxr-x 2 ubuntu ubuntu  4096 Feb  5 04:26 catalog
drwxrwxr-x 2 ubuntu ubuntu  4096 Feb  5 04:26 config
-rw-rw-r-- 1 ubuntu ubuntu   118 Feb  5 04:26 Procfile
-rw-rw-r-- 1 ubuntu ubuntu  9955 Feb  5 04:26 pythonlogo.png
-rw-rw-r-- 1 ubuntu ubuntu    79 Feb  5 04:26 README.md
-rw-rw-r-- 1 ubuntu ubuntu   218 Feb  5 05:13 requirements.txt
-rw-rw-r-- 1 ubuntu ubuntu  1313 Feb  5 04:26 Tiltfile
-rw-rw-r-- 1 ubuntu ubuntu   590 Feb  5 05:06 web.py

~/python-web-app$ cat apt.yml 
---
packages:
- libnss3-tools

4. Push app by including multiple buildpacks and putting apt_buildpack before the final buildpack for building the application

~/python-web-app$ cf push myweb -b apt_buildpack -b python_buildpackcf push myweb -b apt_buildpack -b python_buildpack
 Pushing app myweb to org test / space test as admin...
 Packaging files to upload...
 Uploading files...
  13.81 KiB / 13.81 KiB [=========================================================================================================================================================================] 100.00% 1s
 
 Waiting for API to complete processing files...
 
 Staging app and tracing logs...
    Downloading python_buildpack...
    Downloading apt_buildpack...
    Downloaded python_buildpack
    Downloaded apt_buildpack (2.5M)
    Cell 88297e5d-####-####-####-1f331100ae49 creating container for instance c64c43b0-####-####-####-6c53c98e0ecd
    Security group rules were updated
    Cell 88297e5d-####-####-####-1f331100ae49 successfully created container for instance c64c43b0-####-####-####-6c53c98e0ecd
    Downloading app package...
    Downloading build artifacts cache...
    Downloaded app package (13.8K)
    Downloaded build artifacts cache (13M)
    -----> Apt Buildpack version 0.3.6
    -----> Updating apt cache
    -----> Downloading apt packages
    Reading package lists...
    Building dependency tree...
    The following additional packages will be installed:
    libnspr4 libnss3
    The following NEW packages will be installed:
    libnspr4 libnss3 libnss3-tools
    0 upgraded, 3 newly installed, 0 to remove and 37 not upgraded.
    Need to get 2,036 kB of archives.
    After this operation, 6,632 kB of additional disk space will be used.
    Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libnspr4 amd64 2:4.35-0ubuntu0.22.04.1 [119 kB]
    Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libnss3 amd64 2:3.98-0ubuntu0.22.04.2 [1,347 kB]
    Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libnss3-tools amd64 2:3.98-0ubuntu0.22.04.2 [570 kB]
    Fetched 2,036 kB in 2s (937 kB/s)
    Download complete and in download only mode
    
    -----> Installing apt packages
 ......

5. The extra packages will be installed in directory "/home/vcap/deps/0/apt/" on app container

~/python-web-app$ cf ssh myweb
 
 vcap@b26c5569-####-####-####-90e1:~$ ls -l /home/vcap/deps/0/apt/usr/lib/x86_64-linux-gnu/
 total 2292
 lrwxrwxrwx 1 vcap vcap      18 Apr 11  2024 libfreebl3.chk -> nss/libfreebl3.chk
 lrwxrwxrwx 1 vcap vcap      17 Apr 11  2024 libfreebl3.so -> nss/libfreebl3.so
 lrwxrwxrwx 1 vcap vcap      22 Apr 11  2024 libfreeblpriv3.chk -> nss/libfreeblpriv3.chk
 lrwxrwxrwx 1 vcap vcap      21 Apr 11  2024 libfreeblpriv3.so -> nss/libfreeblpriv3.so
 -rw-r--r-- 1 vcap vcap  246248 Mar 21  2024 libnspr4.so
 -rw-r--r-- 1 vcap vcap 1240024 Apr 11  2024 libnss3.so
 -rw-r--r-- 1 vcap vcap  203816 Apr 11  2024 libnssutil3.so
 -rw-r--r-- 1 vcap vcap   22784 Mar 21  2024 libplc4.so
 -rw-r--r-- 1 vcap vcap   14624 Mar 21  2024 libplds4.so
 -rw-r--r-- 1 vcap vcap  167808 Apr 11  2024 libsmime3.so
 -rw-r--r-- 1 vcap vcap  434928 Apr 11  2024 libssl3.so
 drwxr-xr-x 2 vcap vcap    4096 Apr 11  2024 nss

 

Finally please note that apt buildpack is not one of  the TPCF system buildpacks and is considered a third party buildpack, which Broadcom by VMWare Tanzu does not officially support. 

 

 

Additional Information