packaging.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. .. meta::
  2. :status: review
  3. .. _spm-packaging:
  4. =====================
  5. Building SPM Packages
  6. =====================
  7. The first step when using Salt Package Manager is to build packages for each of
  8. of the formulas that you want to distribute. Packages can be built on any
  9. system where you can install Salt.
  10. Package Build Overview
  11. ======================
  12. To build a package, all state, pillar, jinja, and file templates used by your
  13. formula are assembled into a folder on the build system. These files can be
  14. cloned from a Git repository, such as those found at the `saltstack-formulas
  15. <https://github.com/saltstack-formulas>`_ organization on GitHub, or copied
  16. directly to the folder.
  17. The following diagram demonstrates
  18. a typical formula layout on the build system:
  19. .. image:: /_static/spm-package-contents.png
  20. :align: center
  21. :scale: 70%
  22. In this example, all formula files are placed in a ``myapp-formula`` folder.
  23. This is the folder that is targeted by the ``spm build`` command when this
  24. package is built.
  25. Within this folder, pillar data is placed in
  26. a ``pillar.example`` file at the root, and all state, jinja, and template files
  27. are placed within a subfolder that is named after the application being
  28. packaged. State files are typically contained within a subfolder, similar to
  29. how state files are organized in the state tree. Any non-pillar files
  30. in your package that are not contained in a subfolder are placed at the root
  31. of the spm state tree.
  32. Additionally, a :ref:`FORMULA <spm-formula>` file is created and placed in the
  33. root of the folder. This file contains package metadata that is used by SPM.
  34. Package Installation Overview
  35. =============================
  36. When building packages, it is useful to know where files are installed on the
  37. Salt master. During installation, all files except ``pillar.example`` and ``FORMULA`` are copied
  38. directly to the spm state tree on the Salt master (located at
  39. ``\srv\spm\salt``).
  40. If a ``pillar.example`` file is present in the root, it is renamed to
  41. ``<formula name>.sls.orig`` and placed in the ``pillar_path``.
  42. .. image:: /_static/spm-package-extraction.png
  43. :align: center
  44. :scale: 70%
  45. .. note::
  46. Even though the pillar data file is copied to the pillar root, you still
  47. need to manually assign this pillar data to systems using the pillar top
  48. file. This file can also be duplicated and renamed so the ``.orig``
  49. version is left intact in case you need to restore it later.
  50. Building an SPM Formula Package
  51. ===============================
  52. #. Assemble formula files in a folder on the build system.
  53. #. Create a :ref:`FORMULA <spm-formula>` file and place it in the root of the package folder.
  54. #. Run ``spm build <folder name>``. The package is built and placed in the ``/srv/spm_build`` folder.
  55. .. code-block:: bash
  56. spm build /path/to/salt-packages-source/myapp-formula
  57. #. Copy the ``.spm`` file to a folder on the :ref:`repository system <spm-repo>`.
  58. Types of Packages
  59. =================
  60. SPM supports different types of packages. The function of each package
  61. is denoted by its name. For instance, packages which end in ``-formula`` are
  62. considered to be Salt States (the most common type of formula). Packages which
  63. end in ``-conf`` contain configuration which is to be placed in the
  64. ``/etc/salt/`` directory. Packages which do not contain one of these names are
  65. treated as if they have a ``-formula`` name.
  66. formula
  67. -------
  68. By default, most files from this type of package live in the ``/srv/spm/salt/``
  69. directory. The exception is the ``pillar.example`` file, which will be renamed
  70. to ``<package_name>.sls`` and placed in the pillar directory (``/srv/spm/pillar/``
  71. by default).
  72. reactor
  73. -------
  74. By default, files from this type of package live in the ``/srv/spm/reactor/``
  75. directory.
  76. conf
  77. ----
  78. The files in this type of package are configuration files for Salt, which
  79. normally live in the ``/etc/salt/`` directory. Configuration files for packages
  80. other than Salt can and should be handled with a Salt State (using a ``formula``
  81. type of package).
  82. Technical Information
  83. =====================
  84. Packages are built using BZ2-compressed tarballs. By default, the package
  85. database is stored using the ``sqlite3`` driver (see Loader Modules below).
  86. Support for these are built into Python, and so no external dependencies are
  87. needed.
  88. All other files belonging to SPM use YAML, for portability and ease of use and
  89. maintainability.
  90. SPM-Specific Loader Modules
  91. ===========================
  92. SPM was designed to behave like traditional package managers, which apply files
  93. to the filesystem and store package metadata in a local database. However,
  94. because modern infrastructures often extend beyond those use cases, certain
  95. parts of SPM have been broken out into their own set of modules.
  96. Package Database
  97. ----------------
  98. By default, the package database is stored using the ``sqlite3`` module. This
  99. module was chosen because support for SQLite3 is built into Python itself.
  100. Please see the SPM Development Guide for information on creating new modules
  101. for package database management.
  102. Package Files
  103. -------------
  104. By default, package files are installed using the ``local`` module. This module
  105. applies files to the local filesystem, on the machine that the package is
  106. installed on.
  107. Please see the :ref:`SPM Development Guide <spm-development>` for information
  108. on creating new modules for package file management.