@@ -77,7 +77,7 @@ be included in an `imageconfig` file through the `packagelist` files. The result
7777will include the set of all ` rpms ` specified within the array of ` packagelist ` files from the
7878` imageconfig ` .
7979
80- ### Example: Adding Nano
80+ ### Example: Adding an existing RPM ( Nano)
8181
8282The following example shows how to add ` nano ` as an alternative text editor to the image.
8383You can add the packages for which ` .spec ` files already exist. Simply include them in an
@@ -122,11 +122,140 @@ Then, rebuild the image:
122122``` bash
123123sudo make image -j8 REBUILD_TOOLS=y REBUILD_PACKAGES=n CONFIG_FILE=./imageconfigs/edge-image.json
124124```
125+ ### Add a new package
125126
126- ### Update or Add Packages
127+ To add a new package you need to generate a ` SPEC ` file for the package which
128+ contains all required information for the build infrastructure to generate the
129+ ` SRPM ` and ` RPM ` for the package. There are a few steps involved in creating
130+ a new package for Edge Microvisor Toolkit.
127131
128- 1 . If a new package has to be released, follow these steps to ensure the package is available
129- in the artifactory:
132+ 1 . Create a folder, define the SPEC file and add it into the ` /SPECS ` directory.
133+ 2 . Create the source archive and generate the sha256sum for the package.
134+ 3 . Update the ` cgmanifest.json ` file.
135+ 4 . Build an image with the package included and test locally.
136+ 5 . Upload the tar.gz package to the source package repository after is has been tested locally.
137+
138+ You need to first install the required build tools for ` rpm ` . On Fedora you
139+ can simply install the required packages with:
140+
141+ ``` bash
142+ sudo dnf install rpm-build rpmdevtools
143+ rpmdev-setuptree
144+ ```
145+
146+ ` rpmdev-setuptree ` creates the necessary directories, which you may need to
147+ manually create on an Ubuntu distribution.
148+
149+ ``` bash
150+ sudo apt-get install rpm
151+ mkdir -p ~ /rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
152+ echo ' %_topdir %(echo $HOME)/rpmbuild' > ~ /.rpmmacros
153+ ```
154+
155+ ** Defining the SPEC file**
156+ Define the SPEC file and test that it works as expected and generates locally the required artifacts.
157+ the required artifacts. This example builds a simple hello world ` rpm ` package
158+ which contains a bash scripts that prints hello world.
159+
160+ ``` bash
161+ Name: helloworld
162+ Version: 1.0
163+ Release: 1%{? dist}
164+ Summary: Simple Hello World script
165+
166+ License: MIT
167+ URL: https://example.com/helloworld
168+ Source0: helloworld-1.0.tar.gz
169+
170+ BuildArch: noarch
171+
172+ %description
173+ A very basic " Hello World" script packaged as an RPM.
174+
175+ %prep
176+ %setup -q
177+
178+ %build
179+ # Nothing to build for a shell script
180+
181+ %install
182+ mkdir -p %{buildroot}/usr/bin
183+ install -m 0755 helloworld.sh %{buildroot}/usr/bin/helloworld
184+
185+ mkdir -p %{buildroot}/usr/share/helloworld
186+ install -m 0644 helloworld.signature.json %{buildroot}/usr/share/helloworld/
187+
188+ %files
189+ /usr/bin/helloworld
190+ /usr/share/helloworld/helloworld.signature.json
191+
192+ %changelog
193+ * Wed May 01 2025 Your Name < you@example.com> - 1.0-1
194+ - Initial package
195+ ```
196+
197+ ** Create the archive** : Create your source archive, add the simple script and
198+ make it executable.
199+
200+ ``` bash
201+ # 1. Make your source tree and tarball
202+ mkdir -p ~ /helloworld-1.0
203+ cat > ~ /helloworld-1.0/helloworld.sh << 'EOF '
204+ #!/bin/bash
205+ echo "Hello, world!"
206+ EOF
207+ chmod +x ~ /helloworld-1.0/helloworld.sh
208+
209+ tar -czf helloworld-1.0.tar.gz helloworld-1.0/
210+
211+ # 2. Compute its SHA-256
212+ sum=$( sha256sum helloworld-1.0.tar.gz | awk ' {print $1}' )
213+
214+ # 3. Write the JSON signature for the tarball
215+ cat > helloworld-1.0.tar.gz.signature.json << EOF
216+ {
217+ "file": "helloworld-1.0.tar.gz",
218+ "sha256": "$sum "
219+ }
220+ EOF
221+
222+ ```
223+
224+ Copy the RPM package to the building directory and build it.
225+
226+ ``` bash
227+ cp helloworld-1.0.tar.gz ~ /rpmbuild/SOURCES/
228+ cp helloworld.spec ~ /rpmbuild/SPECS/
229+ rpmbuild -ba ~ /rpmbuild/SPECS/helloworld.spec
230+ ```
231+
232+ ** Adding the SPEC** : Add the ` helloworld.spec ` and the 'helloworld.spec.signature`
233+ file to the ` /SPECS ` directory. Finally update the ` cgmanifest ` by using the
234+ provided ` python ` script.
235+
236+ ``` bash
237+ python3 -m pip install -r ./toolkit/scripts/requirements.txt
238+ python3 ./toolkit/scripts/update_cgmanifest.py first cgmanifest.json ./SPECS/helloworld.spec
239+ ```
240+
241+ ** Local Build and Testing** : If testing is complete and you are ready to contribute this package,
242+ please raise a PR and work with a code owner to upload the source tarball to package source mirror.
243+
244+ ``` bash
245+ make build-packages # to rebuild the packages
246+ ```
247+ Follow the steps under [ Customizing an image] ( ./building-howto.md#Customizing-an-Image ) to create
248+ an image with your new package.
249+
250+ ** Uploading the archive** : Intel will upload the tar.gz archive to the mirror.
251+
252+ ### Update an agent
253+
254+ To add or update an existing BMA (Bare metal agent) from the Edge Management
255+ Framework, follow these steps.
256+
257+ 1 . If a new package has to be released, follow these steps to ensure the package
258+ is available in the artifactory:
130259
131260 a. Checkout the tag for your agent which has to be released.
132261 b. cd into your agent's directory.
@@ -162,10 +291,6 @@ Example : `sha256sum ./SPECS/node-agent/env_wrapper.sh`
162291 python3 -m pip install -r ./toolkit/scripts/requirements.txt
163292 python3 ./toolkit/scripts/update_cgmanifest.py first cgmanifest.json ./SPECS/node-agent/node-agent.spec
164293 ` ` `
165-
166- > ** Note:**
167- This guide applies to ` rpm` package addition in general for Edge Microvisor.
168-
169294# # Next
170295
171296- Learn how to [Enable Secure Boot for Edge Microvisor Toolkit](sb-howto.md).
0 commit comments