You can run tests in two different environments: without dokku installed locally (majority of them) and with dokku installed.
This method won't run all tests but will run the majority of them. It requires Python and
requirements-development.txt packages installed. You may want to use a virtualenv for this.
On the first time, execute:
python -m venv venv
source venv/bin/activate
pip install -r requirements-development.txtThen:
make testYou can pass other pytest parameters via TEST_ARGS environment variable. Some useful examples:
- Use
TEST_ARGS="--pdb" make testto automatically open pdb++ when an assert fails (pdbpp is installed fromrequirements-development.txt) - Use
TEST_ARGS="-x" make testto stop test running after the first assert fails - Use
TEST_ARGS="-k test_plugin_network" make testto only run tests which matchtest_plugin_network(for more details, check pytest CLI docs)
The "real" tests executes Dokku commands. To make it easier to run we provide a script to help running a virtual machine so you can test Dokku easily.
The make vm-create script is meant to be run on a Debian GNU/Linux machine, requires sudo and will:
- Install required system packages to manage virtual machines with libvirt
- Configure user permissions and the default libvirt network
- Download an official Debian 12 "cloud-ready" QCOW2 image
- Generate cloud-init YAML files to configure the virtual machine with:
- Locale and timezone settings
- SSH password authentication enabled
- A root user and a default non-root user (
debian) with sudo privileges - Pre-installed
openssh-serverpackage for remote access - A custom Docker + Dokku installation script (
/root/install.sh)
- Create an overlay QCOW2 disk image (so the original Debian 12 won't be overwritten)
- Use
virt-installto create a VM with 2 GB of RAM, 2 vCPUs, the overlay QCOW2 disk and cloud-init configs - Wait for the virtual machine's network to become available and retrieve its IP address
Note that you must install and properly configure libvirt before running the script. This step is out of the scope of this script, but the commands below could help making the Internet connection work inside the VM:
# Replace 'enp0s31f6' with your network interface
iptables -I FORWARD -i virbr0 -o enp0s31f6 -j ACCEPT
iptables -I FORWARD -i enp0s31f6 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPTAfter having libvirt configured and running, create the virtual machine by executing:
make vm-create # ~2min with a good Internet connectionThe VM's IP address will be shown. You may want to copy your SSH public key so it's easier to connect:
ssh-copy-id debian@$(make vm-ip)After that you can connect to the VM and install Docker, Dokku and some Dokku plugins so you can run the tests:
ssh debian@$(make vm-ip) sudo /root/install.sh # ~4minYou may also download and compile other Python versions using pyenv with:
ssh debian@$(make vm-ip) bash -i /home/debian/install-pythons.sh # ~12minAfter that, you may want to create a snapshot of the current disk, so you can easily go back to this fresh install state if the tests make the disk dirty:
OVERLAY_QCOW2="/var/lib/libvirt/images/pydokku.qcow2"
make vm-stop
sudo qemu-img snapshot -c "Docker and Dokku installed" "$OVERLAY_QCOW2"
make vm-startAnd to return to a specific snapshot:
OVERLAY_QCOW2="/var/lib/libvirt/images/pydokku.qcow2"
make vm-stop
sudo qemu-img snapshot -a "Docker and Dokku installed" "$OVERLAY_QCOW2"
make vm-startYou can list all snapshots by running sudo qemu-img snapshot -l $OVERLAY_QCOW2.
By now, the only way to run tests inside the VM is:
- Use the shared folder to create a Git bare repository
- From your host machine, push the current repository to the shared one
- From the VM, clone the repository, install dependencies and run
make test
To execute these steps, first run on your host machine:
HOST_SHARED="/var/lib/libvirt/shared/debian12-pydokku"
REPO_PATH="${HOST_SHARED}/repo.git/"
sudo mkdir -p "$REPO_PATH"
sudo chown -R ${SUDO_USER:-$USER}:libvirt "$HOST_SHARED"
git init --bare --initial-branch=develop "$REPO_PATH"
git remote add shared "$REPO_PATH"
git push shared developConnect to the VM using make vm-ssh and run inside the VM as the user debian:
cd
source venv/bin/activate
git clone /shared/repo.git pydokku
cd pydokku
make testIf you make changes to the repository on the host machine, push them by running git push shared and then, inside the
VM:
cd ~/pydokku
git fetch origin
git reset --hard origin/develop # WARNING: this will REMOVE all changes made in the VM repository!
make testThis project follows the git flow branching strategy. In summary:
- Bug in a released version: start your branch from the git tag where the problem was found and name it
hotfix/short-description - Bug in a unreleased version: start your branch from the
developbranch and name itfix/short-description - New feature: start your branch from the
developbranch and name itfeature/short-description - Small enhancement (not a full feature): start your branch from the
developbranch and name itenhancement/short-description
Other considerations:
- Keep branch names concise: avoid using spaces in
short-descriptionand keep it brief. This makes it easier for others to quickly understand the branch's purpose by just reading its name. - Keep your branch in sync: if the base branch (e.g.,
developormain) has received new commits, rebase your branch onto the latest version. Do NOT merge the base branch into yours (avoid unneeded commits). This helps avoiding merge conflicts and keeps your commit history clean. - Write clear, short but descriptive commit messages, referencing issue numbers if applicable (e.g.,
fix #123)