Search code examples
servicegitlabgitlab-cisystemd

GitLab CI for systemd service


I have built a deb package for a systemd service, which I would like to test after building it with GitLab CI.

The image I use is based on debian:stable (i.e. buster at the time of this writing).

I am doing a basic smoke test like this:

test:
  stage: test
  script:
    - dpkg -i myservice.deb
    - systemctl start myservice

This fails with an error message, because systemctl is not found. If I install that as part of the test, it still fails because systemd is not the first process on the system.

How can I test a systemctl service on GitLab CI? Is there a Debian image which runs systemd?


Solution

  • systemd is not compatible with Docker, and is normally not needed as the Docker paradigm is to run one service per container, therefore a service control framework does not make much sense. Unless you specifically rely on systemd for tests…

    I found an instruction to run systemd inside a Docker container at https://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/ (and, as a follow-up, https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container/). It is based on Redhat but the principles of it should apply to other distributions as well (and it gives some more background info on systemd/docker compatibility).

    However, at this point I am wondering if tests conducted on such a setup are still meaningful. It might be better to rely on a local VM for tests.