Skip to content

Commit 31a15e7

Browse files
authored
docs: add new how-to for parts (#1031)
1 parent 90c6bcf commit 31a15e7

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

docs/common/craft-parts/craft-parts.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ ZipSourceModel
309309
abcdef
310310
args
311311
armv
312+
artifact
312313
artifacts
313314
autogen
314315
autotools
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parts:
2+
my-part:
3+
plugin: dump
4+
source: hello.sh
5+
source-type: file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.. _how-to-use-parts:
2+
3+
Using parts in a project file
4+
=============================
5+
6+
When packing, :ref:`parts <parts>` are used to describe your package, where its various
7+
components can be found, its build and run-time requirements, and its dependencies.
8+
Consequently, all packages will have one or more parts.
9+
10+
.. _how-to-use-parts_details:
11+
12+
Parts are purposefully flexible to allow for varied and disparate sources. At its
13+
simplest, a part will locate a project's source code and invoke a
14+
:ref:`plugin <plugins>` to build the application in the environment. However, you can
15+
just as easily use a part to source and extract a binary executable from an RPM file.
16+
It can also download tagged code from a remote repository, pull in dependencies,
17+
define a build order, or completely override any stage of the
18+
:ref:`lifecycle <lifecycle>`.
19+
20+
.. _how-to-use-parts_defining:
21+
22+
Define a part
23+
=============
24+
25+
To define a part, give it a name and declare its keys. The rest of this section uses a
26+
part that packs a "Hello, world!" shell script as an example.
27+
28+
First, create the shell script:
29+
30+
.. code:: shell
31+
32+
echo "echo 'Hello, world!'" >> hello.sh
33+
34+
Next, create a simple part named my-part:
35+
36+
.. literalinclude:: code/use_parts.yaml
37+
:language: yaml
38+
:end-at: my-part:
39+
40+
This block starts the list of all parts in the project and declares the singular part
41+
named my-part.
42+
43+
All parts need a plugin. Declare the part's plugin:
44+
45+
.. literalinclude:: code/use_parts.yaml
46+
:language: yaml
47+
:end-at: plugin: dump
48+
49+
The dump plugin is the simplest of all the plugins. It takes source files and copies
50+
them directly into the staging directory of the project.
51+
52+
Next, give the plugin a source to copy:
53+
54+
.. literalinclude:: code/use_parts.yaml
55+
:language: yaml
56+
:end-at: source-type: file
57+
58+
With this, you have a complete part that packs the :file:`hello.sh` file into your
59+
project's final artifact. For more information on keys available to use within a part,
60+
see the :ref:`parts reference <part_properties>`.
61+

docs/how-to/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ How-to guides
66
.. toctree::
77
:maxdepth: 1
88

9+
Use parts </common/craft-parts/how-to/use_parts>
910
Use the craftctl tool </common/craft-parts/how-to/craftctl>
1011
Use craft-parts from the command-line <cli_tool>
1112
Override a part's default build behavior </common/craft-parts/how-to/override_build>

0 commit comments

Comments
 (0)