Thank you for considering contributing to docker-keepalived! This document provides guidelines to ensure smooth collaboration.
- Conventional Commits
- Writing and Modifying Init Scripts
- Running Tests with BATS
- Submitting Pull Requests
This project follows the Conventional Commits specification. Please adhere to the specification when creating commit messages.
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
feat: A new feature.fix: A bug fix.docs: Documentation only changes.style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).refactor: A code change that neither fixes a bug nor adds a feature.perf: A code change that improves performance.test: Adding missing tests or correcting existing tests.chore: Changes to the build process or auxiliary tools and libraries such as documentation generation.
When adding or modifying init scripts, please ensure the following:
- Code Quality: Follow best practices for Bash scripting.
- Error Handling: Ensure that scripts handle errors gracefully and provide informative error messages.
- Testing: Write tests using BATS (Bash Automated Testing System).
We use BATS for testing our Bash scripts. Please follow these steps to write and run tests:
Make sure you have BATS installed. You can use the linked submodules:
git submodule update --init --recursive
Please refer to the BATS installation guide.
- Create a new test file in the
testdirectory with a.batsextension. For example:test/my_script.bats - Write your test cases within the new
.batsfile. Here's a basic example:
#!/usr/bin/env bats
bats_require_minimum_version 1.5.0
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
setup() {
# prepare s6 paths (this is mandatory for the bats tests to work with s6-overlay)
export PATH="/command:$PATH"
mkdir -p /run/s6/container_environment
}
teardown() {
rm -f /run/s6/container_environment/*
}
@test "init-your-script does something whenever your variable was set" {
echo -n "your variable value" > /run/s6/container_environment/WHAT_EVER_YOU_WANT_TO_SET_FOR_S6
run /etc/s6-overlay/s6-rc.d/init-your-script
assert_output "your variable was set and your script did something to output this text, yay!"
}Writing tests for s6-overlay scripts is a little bit special, since we don't run s6-overlay but execute the scripts directly, we must add /command to the PATH and we also have to create the directory /run/s6/container_environment.
Environment variables must be set in the /run/s6/container_environment directory, not with export.
To run all tests, execute the following command in the project root:
# build the container locally
docker build -t keepalived:test-build .
# run tests using bats
docker run --rm -it --name keepalived-test \
--cap-add=NET_ADMIN \
--entrypoint /test/bats/bin/bats \
-w /test \
-v "$PWD/test:/test" \
keepalived:test-build .
This will execute all test files in the test directory and show the results.
- Fork the Repository: Create a fork of the repository to work on your changes.
- Create a Branch: Create a new branch for your feature or bugfix.
- Commit Changes: Make your changes, commit using Conventional Commits, and push to your fork.
- Open a Pull Request: Open a pull request (PR) to merge your changes into the main repository.
- Review Process: Your PR will be reviewed by the maintainers. Please address any feedback and make necessary changes.
- Merge: Once approved, your PR will be merged.
Thank you for contributing to docker-keepalived! We appreciate your efforts in making this project better.