|
| 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 | + |
0 commit comments