SlapOS Best Practices & Guidelines¶
This summary of the best practices and guidelines for working with SlapOS covers key conventions, development practices and release procedures.
I. Key Conventions and Standards¶
A. Software:¶
-
Atomic Parameters:
- Guideline: Use atomic parameters for instance configurations. Define parameters as granular and independent units (e.g.,
host
,port
separately) rather than combined or complex structures. - Rationale: Ensures modularity, flexibility, and easier management of configurations. Prevents conflicts and simplifies updates.
- Guideline: Use atomic parameters for instance configurations. Define parameters as granular and independent units (e.g.,
-
Backward Compatibility:
- Guideline: Maintain backward compatibility when updating software or configurations.
- Rationale: Ensures that existing deployments continue to function correctly after updates, reducing the risk of breaking changes.
B. Recipes:¶
-
Extend
GenericBaseRecipe
:- Guideline: When creating custom recipes, extend the
GenericBaseRecipe
class provided by SlapOS. - Rationale: Promotes consistency and maintainability across recipes. Ensures that common functionalities and error handling are inherited.
- Guideline: When creating custom recipes, extend the
-
Fail Early and Provide Meaningful Error Messages:
- Guideline: Implement robust error handling in recipes. Raise exceptions with clear, informative messages when errors occur.
- Rationale: Facilitates debugging and troubleshooting. Helps users and developers quickly identify and resolve issues.
C. Components:¶
-
Modularize Patches and Dependencies:
- Guideline: Organize patches and dependencies in a modular way within the
component
directory. - Rationale: Improves maintainability and reusability of components. Makes it easier to manage updates and track changes.
- Guideline: Organize patches and dependencies in a modular way within the
-
Clear, Representative Naming Conventions:
- Guideline: Use descriptive and consistent names for components, files, and directories. Component names should match file names (e.g.,
component/foo/buildout.cfg
for componentfoo
). - Rationale: Enhances readability and makes it easier to navigate the codebase.
- Guideline: Use descriptive and consistent names for components, files, and directories. Component names should match file names (e.g.,
D. Testing:¶
- Integrate Promises:
- Guideline: Include at least one Promise in every Software Release to monitor instance health and functionality.
- Rationale: Ensures that every instance is continuously monitored, and corrective actions are triggered automatically in case of failures. This is crucial for maintaining system reliability.
- Regularly Test with Pinned Versions:
- Guideline: Use pinned versions of dependencies during testing to ensure consistent results.
- Rationale: Prevents unexpected issues caused by dependency updates. Ensures that tests accurately reflect the behavior of production environments.
- Automated Systems:
- Guideline: Integrate tests with automated CI/CD pipelines.
- Rationale: Enables continuous testing and early detection of regressions.
II. Buildout and Development Practices¶
A. Buildout in SlapOS:¶
- Profiles (
software.cfg
,instance.cfg.in
):- Guideline: Use
software.cfg
to define how to install software and its dependencies. Useinstance.cfg.in
to define instance-specific configurations and parameters. - Rationale: Separates installation instructions from instance configuration, promoting reusability of Software Releases.
- Guideline: Use
- Recipes:
- Guideline: Utilize Buildout recipes to automate tasks such as downloading files, compiling code, creating directories, and generating configuration files.
- Rationale: Automates repetitive tasks and ensures consistency across deployments.
- Extensions:
- Guideline: Use Buildout extensions to modularize configurations and reference other profiles.
- Rationale: Reduces duplication and promotes reuse of common configurations.
B. Developing Software Releases:¶
- Structure:
- Guideline: Organize Software Releases following a standard directory structure, including
software.cfg
for installation andinstance.cfg.in
for instantiation. - Rationale: Ensures consistency and makes it easier to understand and maintain Software Releases.
- Guideline: Organize Software Releases following a standard directory structure, including
- JSON Schemas:
- Guideline: Use JSON schemas to define and document instance parameters.
- Rationale: Provides a clear and structured way to specify input parameters and their expected types, improving usability and enabling automated form generation.
- Modularization:
- Guideline: Break down configurations into reusable components and recipes.
- Rationale: Promotes code reuse, simplifies maintenance, and makes it easier to extend or customize Software Releases.
- Promises:
- Guideline: Employ Promises to monitor instance health and trigger corrective actions.
- Rationale: Ensures that instances are continuously monitored and that problems are automatically addressed, improving system reliability.
C. Extending Software Releases:¶
- Modify Configuration Files:
- Guideline: Update
software.cfg
andinstance.cfg.in
to add new features, parameters, or components. - Rationale: Allows customization and extension of existing Software Releases to meet specific requirements.
- Guideline: Update
- Add New Components:
- Guideline: Introduce new components (e.g., for log rotation with
cron
andlogrotate
) to enhance functionality. - Rationale: Enables the addition of new features without modifying the core Software Release.
- Guideline: Introduce new components (e.g., for log rotation with
- Jinja2 Templates:
- Guideline: Use Jinja2 templates to introduce dynamic configurations and parameters.
- Rationale: Provides a flexible way to generate configuration files based on instance-specific parameters.
- Reusability:
- Guideline: Leverage existing recipes and extend base configurations to avoid duplication and promote consistency.
- Rationale: Simplifies development and maintenance of Software Releases.
III. Release and Upgrade Procedures¶
A. Release Process:¶
- Freeze Versions:
- Guideline: Pin versions of all dependencies (eggs) and use tags for repositories to ensure reproducibility.
- Rationale: Prevents unexpected changes from affecting deployments and ensures that the same software environment is used consistently.
- MD5 Checksums:
- Guideline: Generate and validate MD5 checksums for all downloaded resources.
- Rationale: Ensures the integrity of downloaded files and prevents the use of corrupted or tampered resources.
- Shacache:
- Guideline: Pre-cache resources in Shacache to speed up deployments.
- Rationale: Reduces build times and ensures that precompiled binaries are available for faster installation.
B. Testing and Quality Assurance:¶
- Rigorous Testing:
- Guideline: Thoroughly test installation and instantiation processes before releasing a new version.
- Rationale: Ensures that the Software Release works as expected and that no regressions have been introduced.
- Compliance:
- Guideline: Ensure compliance with naming conventions, versioning policies, and monitoring requirements.
- Rationale: Maintains consistency and quality across Software Releases.
C. Publication:¶
- Merge to Master:
- Guideline: Merge development branches into the
master
branch after thorough testing and review. - Rationale: Ensures that the
master
branch always contains the latest stable code.
- Guideline: Merge development branches into the
- Create Release Tag:
- Guideline: Create a new tag for each release to mark a specific version of the Software Release.
- Rationale: Provides a clear way to identify and track different versions of the software.
- Automated Testing Pipelines:
- Guideline: Add the new Software Release to SlapOS automated testing pipelines.
- Rationale: Ensures that the software is continuously tested and that any issues are detected early.
IV. Naming Conventions and Coding Standards¶
A. Naming Conventions:¶
- Software Releases:
- Directory:
slapos/software/[name]
- Branches: Use topic-based names (e.g.,
feature-x
,bugfix-y
), not personal names.
- Directory:
- Components:
- Directory:
/component/[name]
- Main Section: Named like the component (e.g.,
[foo]
for componentfoo
). - File Name: Matches component name (e.g.,
component/foo/buildout.cfg
).
- Directory:
- Buildout Profiles:
- Software Release:
software.cfg
- Instance Profiles:
instance[ * ].cfg
- Other Profiles:
buildout.cfg
- Software Release:
- Sections and Parameters:
- Use
-
(dash) instead of_
(underscore) in section and parameter names (e.g.,[install-foo-bar]
).
- Use
- Instance Parameters:
- Must be atomic (e.g.,
host
,ip
,port
separately). - Maintain common parameter names (e.g.,
host
,ip
,port
,url
).
- Must be atomic (e.g.,
B. Coding Standards:¶
- Recipes:
- Extend from
GenericBaseRecipe
orGenericSlapRecipe
. - Fail early with meaningful error messages.
- Get SLAP parameters from the Buildout Instance Profile.
- Publish SLAP connection parameters using the
slapos.cookbook:publish
recipe.
- Extend from
- Promises:
- Define a class called
RunPromise
that inherits fromGenericPromise
. - Implement
sense()
,test()
, andanomaly()
methods. - Use
getConfig()
to access configuration parameters.
- Define a class called
- General:
- Avoid copy-pasting more than 30 lines of code.
- Always pin versions of eggs/products.
- Tag Software Releases for production.
- Only release precompiled Software Releases for production.
Page last modified: 2025-01-03 08:36:57