Add Packages, Libraries and Tools
Introduction
In this article you will learn how to add external dependencies and tools to an existing single-container project created with Torizon IDE Extension 2 using one of our supported templates.
It includes instructions on how to use torizonPackages.json
and gives a general direction for those who want to manually add packages by directly changing Dockerfile
, Dockerfile.debug
and Dockerfile.sdk
.
Why Add Dependencies and Tools to an IDE Extension 2 Project
Your application might need some external libraries and other utilities available in most Linux distro repositories or built by your team. TorizonCore uses containers to pack software resources needed for your application. Hence, the way for adding dependencies and tools to a project in Torizon is to add it to the containers. It provides isolation from your host machine, portability, reproducibility, and ease of deployment of the application.
Prerequisites
- Basic understanding of the Torizon IDE Extension 2.
- Toradex Computer on Module (CoM) with TorizonCore installed.
- Created a Single-Container Project with the IDE Extension 2.
The instructions provided in this article work for both Linux and Windows environments.
Add Debian Packages with torizonPackages.json
Our project templates use Debian-based containers. These templates come with a file called torizonPackages.json
, where you can easily add packages available in the Debian feeds to debug and production container images.
The packages specified in this file will be automatically added to Dockerfile
, Dockerfile.debug
and Dockerfile.sdk
files when building the project, according to the following rules:
- Packages in the
deps
array will be added toDockerfile
(Release container image) - Packages in the
devDeps
array will be added toDockerfile.debug
(Debug container image) andDockerfile.sdk
(SDK container image used in C/C++ projects)
1.Choose the Package: the IDE Extension 2 supports auto-completion of packages from the Debian feeds in the torizonPackages.json
file.
To trigger it press Ctrl + Space
inside the array, wait for it to load, then start typing the package name:
- Check the Description: under the list of packages, it will also show the selected package description:
If the description doesn't appear, press Ctrl + Space
again, as this key combination is a VS Code shortcut that hides or shows a list item description.
- Add the package: add all the packages you need in a common .JSON list format.
Changing the Debian Package Version
By default the auto-complete feature used in torizonPackages.json
will search packages from the bookworm
feeds.
You can use other Debian feeds by changing the apollox.debianRelease
setting to one of the following values:
bookworm
bullseye
stable
testing
sid
This change can be done globally or in a single project.
Globally
- Press
F1
in VSCode - Type to choose
Preferences: Open Settings (JSON)
- Add a line similar to the example below:
"apollox.debianRelease": "bullseye"
In a single project
- Go to
.vscode/settings.json
file, present in the project directory - Add the
apollox.debianRelease
setting, configured to the desired Debian feed. This overwrites the global setting
Note that this only changes the feeds used in the auto-complete feature and not the Debian version used in the container images, which you can alter by manually editing the corresponding Dockerfiles
.
Manually Add Debian Packages
Although it is recommended to use torizonPackages.json
as detailed above for a more convenient solution, you can also manually add packages by directly editing Dockerfile
, Dockerfile.debug
and Dockerfile.sdk
. In each file, add the packages you need with an apt-get install
instruction, like the example below:
[...]
RUN apt-get -q -y update && \
apt-get -q -y install \
libgpiod-dev:arm64 \
libasound2-dev:arm64 && \
apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
[...]
When manually adding packages to Dockerfile.sdk
always put the SoM architecture after each entry e.g. libgpiod-dev:armhf
, as otherwise it will default to the host machine architecture, usually x64
.
Dockerfile
and Dockerfile.debug
Integration
The packages that you add on the torizonPackages.json
file will be automatically added on the Dockerfile
and Dockerfile.debug
. This is done by the apply-torizon-packages
task. This task is automatically executed when the build, launch or release tasks are executed.
The Dockerfile
and Dockerfile.debug
files has the following entries:
- Dockerfile:
RUN apt-get -y update && apt-get install -y --no-install-recommends \
# ADD YOUR PACKAGES HERE
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
# __torizon_packages_prod_start__
# __torizon_packages_prod_end__
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
&& apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
- Dockerfile.debug:
# automate for torizonPackages.json
RUN apt-get -q -y update && \
apt-get -q -y install \
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
# __torizon_packages_dev_start__
# __torizon_packages_dev_end__
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
&& \
apt-get clean && apt-get autoremove && \
rm -rf /var/lib/apt/lists/*
These are used by the tasks to append the packages from the torizonPackages.json
file.