Blame HACKING.md

Packit Service 509fd4
# Hacking on osbuild-composer
Packit Service 509fd4
Packit Service 3a6627
## Virtual Machine
Packit Service 3a6627
Packit Service 509fd4
*osbuild-composer* cannot be run from the source tree, but has to be installed
Packit Service 509fd4
onto a system. We recommend doing this by building rpms, with:
Packit Service 509fd4
Packit Service 509fd4
    make rpm
Packit Service 509fd4
Packit Service 509fd4
This will build rpms from the latest git HEAD (remember to commit changes), for
Packit Service 509fd4
the current operating system, with a version that contains the commit hash. The
Packit Service 509fd4
packages end up in `./rpmbuild/RPMS/$arch`.
Packit Service 509fd4
Packit Service 509fd4
RPMS are easiest to deal with when they're in a dnf repository. To turn this
Packit Service 509fd4
directory into a dnf repository and serve it on localhost:8000, run:
Packit Service 509fd4
Packit Service 509fd4
    createrepo_c ./rpmbuild/RPMS/x86_64
Packit Service 509fd4
    python3 -m http.server --directory ./rpmbuild/RPMS/x86_64 8000
Packit Service 509fd4
Packit Service 509fd4
To start a ephemeral virtual machine using this repository, run:
Packit Service 509fd4
Packit Service 509fd4
    tools/deploy-qemu IMAGE tools/deploy/test
Packit Service 509fd4
Packit Service 509fd4
`IMAGE` has to be a path to an cloud-init-enabled image matching the host
Packit Service bcdfb1
operating system, because that's what the packages were built for above.
Packit Service 509fd4
Note that the Fedora/RHEL cloud images might be too small for some tests
Packit Service 509fd4
to pass. Run `qemu-img resize IMAGE 10G` to grow them, cloud-init's growpart
Packit Service 509fd4
module will grow the root partition automatically during boot. 
Packit Service 509fd4
Packit Service 509fd4
The second argument points to a directory from which cloud-init user-data is
Packit Service 509fd4
generated (see `tools/gen-user-data` for details). The one given above tries to
Packit Service bcdfb1
mimic what is run on *osbuild-composer*'s continuous integration
Packit Service 509fd4
infrastructure, i.e., installing `osbuild-composer-tests` and starting the
Packit Service 509fd4
service.
Packit Service 509fd4
Packit Service 509fd4
The virtual machine uses qemu's [user networking][1], forwarding port 22 to
Packit Service 509fd4
the host's 2222 and 443 to 4430. You can log into the running machine with
Packit Service 509fd4
Packit Service 509fd4
    ssh admin@localhost -p 2222
Packit Service 509fd4
Packit Service 509fd4
The password is `foobar`. Stopping the machine loses all data.
Packit Service 509fd4
Packit Service 509fd4
For a quick compile and debug cycle, we recommend iterating code using thorough
Packit Service 509fd4
unit tests before going through the full workflow described above.
Packit Service 509fd4
Packit Service 509fd4
[1]: https://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29
Packit Service 3a6627
Packit Service 3a6627
## Containers
Packit Service 3a6627
Packit Service 3a6627
*osbuild-composer* and *osbuild-composer-worker* can be run using Docker
Packit Service 3a6627
containers. Building and starting containers is generally faster than building
Packit Service 3a6627
RPMs and installing them in a VM, so this method is more convenient for
Packit Service 3a6627
developing and testing changes quickly. However, using this method has several
Packit Service 3a6627
downsides:
Packit Service 3a6627
- It doesn't build the RPMs so the `.spec` file isn't tested.
Packit Service 3a6627
- The environment is quite different from production (e.g., installation paths,
Packit Service 3a6627
  privileges and permissions).
Packit Service 3a6627
- The setup is not complete for all required services, so some functionality
Packit Service 3a6627
  isn't available for testing this way (e.g., Koji Hub and all its dependent
Packit Service 3a6627
  services).
Packit Service 3a6627
Packit Service 3a6627
The containers are a good way to quickly test small changes, but before
Packit Service 3a6627
submitting a Pull Request, it's recommended to run through all the tests using
Packit Service 3a6627
the [Virtual Machine](#virtual-machine) setup described above.
Packit Service 3a6627
Packit Service 3a6627
### Configuration
Packit Service 3a6627
Packit Service 3a6627
Each service (*composer* and *worker*) requires a configuration file and a set
Packit Service 3a6627
of certificates. The storage location for these is shared between the
Packit Service 3a6627
containers for simplicity. By default it's configured to be at
Packit Service 3a6627
`./containers/config`, but this can be changed in the
Packit Service 3a6627
[`./distribution/.env`](./distribution/.env) file by modifying the value of the
Packit Service bcdfb1
`$CONTAINER_CONFIG_DIR` variable (both absolute and relative paths work).
Packit Service 3a6627
Packit Service 3a6627
Use the [`tools/gen-certs.sh`](./tools/gen-certs.sh) script to
Packit Service 3a6627
generate the certificates (using the test OpenSSL config file):
Packit Service 3a6627
Packit Service 3a6627
    ./tools/gen-certs.sh ./test/data/x509/openssl.cnf ./containers/config  ./containers/config/ca
Packit Service 3a6627
Packit Service 3a6627
Note that the two arguments `./containers/config` and `./containers/config/ca`
Packit Service 3a6627
should be the same location as the `$CONTAINER_CONFIG_DIR` described above
Packit Service 3a6627
Packit Service 3a6627
The services also require a config file each which they expect to be in the
Packit Service 3a6627
same directory. The following test files can be copied into it:
Packit Service 3a6627
Packit Service 3a6627
    cp ./test/data/composer/osbuild-composer.toml ./test/data/composer/osbuild-worker.toml ./containers/config/
Packit Service 3a6627
Packit Service 3a6627
The `$CONTAINER_CONFIG_DIR` (default `containers/config`) directory will be mounted inside both containers (see
Packit Service 3a6627
the [`docker-composer.yml`](./distribution/docker-compose.yml) file).
Packit Service 3a6627
Packit Service 3a6627
### Build and run
Packit Service 3a6627
Packit Service 3a6627
To build the containers, change into the `distribution/` directory and run:
Packit Service 3a6627
Packit Service 3a6627
    docker-compose build
Packit Service 3a6627
Packit Service 3a6627
To start the containers, change into the `distribution/` directory and run:
Packit Service 3a6627
Packit Service 3a6627
    docker-compose up
Packit Service 3a6627
Packit Service 3a6627
You can send requests to the *osbuild-composer* container directly using the
Packit Service 3a6627
generated certificate and client key. For example, from the project root, run:
Packit Service 3a6627
Packit Service 3a6627
    curl -k --cert ./containers/config/client-crt.pem --key ./containers/config/client-key.pem https://172.30.0.10:9196/api/composer-koji/v1/status
Packit Service 3a6627
Packit Service 3a6627
To rebuild the containers after a change, add the `--build` flag to the `docker-compose` command:
Packit Service 3a6627
Packit Service 3a6627
    docker-compose up --build