Linux Kamarada

Integrating the Open Build Service with GitLab

As we’ve seen in the previous post, Linux Kamarada is moving to GitLab. If you follow me for some time, you know that the distribution development took place not only at GitHub, but also at the Open Build Service (OBS). While Git manages the source code, OBS builds the packages and ISO images of the distribution. I already wrote a text explaining how to integrate the Open Build Service with GitHub. With the migration from GitHub to GitLab, a question arises: is it possible to integrate the Open Build Service with GitLab?

Actually, before starting the migration, I had already done this test and the answer is: yes!

I write this text to share how to do this, just in case anyone else has that same question. I’m going to repeat some information from the OBS and GitHub how-to to make this new how-to self-contained. If you haven’t read the previous how-to, you don’t need to. If you have, feel free to skip parts that looks familiar to you.

Meet the Open Build Service (OBS)

If you develop software for Linux, you should know the Open Build Service (OBS). What does it do that makes it such an interesting tool? Let me quote its website:

The Open Build Service (OBS) is a generic system to build and distribute binary packages from sources in an automatic, consistent and reproducible way. You can release packages as well as updates, add-ons, appliances and entire distributions for a wide range of operating systems and hardware architectures.

In practice, you software developer can upload your software souce to OBS and build ready to install packages for openSUSE, Fedora, Debian, Ubuntu and other distributions, as well as packages for i586, x86_64, ARM and other architectures. Your software users can download those packages directly from OBS. It is also able to build Live images, so users can try your software on a clean and controlled system prior to actually installing anything.

OBS is free software, so you can download, install and run it on a server of your own. Or (easier) you can use the reference server publicly and freely available at build.opensuse.org. That server is used mainly for development of the openSUSE distribution, but it also hosts many community projects. Among them, the Linux Kamarada distribution.

OBS offers its own source code management system, analogous to Git, and you can store and manage your source code right in OBS. Or, if you already use Git with a service such as GitLab, you can set up OBS to get the source code from that service, so that your software is always built, packaged and made available for download right after a git push. Now you are going to see how to set up that integration.

OBS basics

I’m not going to dive into OBS basics here, I’ll write an entire post about them someday. By now, you can find how to get started with OBS here:

I assume that you are able to login with your openSUSE account at build.opensuse.org (if you don’t have an account yet, click the Sign Up link at the top of the page to create one).

Create an empty package for your software at OBS. Here I’m going to use as example the Linux Kamarada’s patterns GitLab repository, which by now has just a PNG image and a spec file.

If you don’t know what a spec file is and/or are new to RPM packaging, read these:

I also assume that you have installed osc, the OBS command-line client, on your machine. If you are using openSUSE, you can do that running:

1
# zypper install osc

Checkout your OBS home project using:

1
$ osc checkout home:username

Enter the package directory:

1
$ cd home:username/packagename

Now let’s integrate OBS with GitLab.

OBS: retrieving sources from GitLab

Set up the source service to retrieve sources from GitLab using osc:

1
$ osc add https://gitlab.com/kamarada/patterns.git

Edit the generated _service file and exchange its contents with:

1
2
3
4
5
6
7
8
9
<services>
    <service name="obs_scm">
        <param name="scm">git</param>
        <param name="url">https://gitlab.com/kamarada/patterns.git</param>
        <param name="revision">15.3-dev</param>
        <param name="extract">pattern-kamarada-gnome.png</param>
        <param name="extract">patterns-kamarada-gnome.spec</param>
    </service>
</services>

Note that I’m using the 15.3-dev branch. If you are going to use the master branch for your package, you can just omit the revision parameter.

Commit changes:

1
$ osc commit

Commiting to OBS automatically triggers the source service and the build process. If you go to build.opensuse.org, your project is already building:

In order for GitLab to trigger your package build you need to generate an authorization token using osc:

1
$ osc token --create --operation runservice home:username packagename

The command will return the token and its id:

1
2
3
4
5
<status code="ok">
  <summary>Ok</summary>
  <data name="token">AcRaZyStRiNgWhIcHiSyOuRtOkeN</data>
  <data name="id">4321</data>
</status>

As a test, you can manually trigger your package build using the generated token:

1
$ osc token --trigger AcRaZyStRiNgWhIcHiSyOuRtOkeN

If you go to build.opensuse.org, your project is building.

GitLab: alerting OBS of new commits

We want to update our package sources in OBS whenever they change in GitLab. We can have GitLab trigger that update automatically setting up a GitLab webhook.

To do this, execute the following steps.

Sign in to GitLab and go to your repository (in my case, https://gitlab.com/kamarada/patterns). Go to Settings > Webhooks:

Provide the following parameters:

  • URL: https://build.opensuse.org/trigger/runservice?project=home:username&package=packagename
  • Secret token: AcRaZyStRiNgWhIcHiSyOuRtOkeN
  • Under Trigger, enable Push events (actually, it is already enabled by default) and enter the branch name 15.3-dev

Scroll down the page and, by the end, under SSL verification, check Enable SSL verification (actually, it is also already checked by default). To finish, click the Add webhook green button:

Back to the previous page, you can see the added webhook:

You can test the webhook by clicking Test and then Push events:

If you go to build.opensuse.org, your project is building.

From now on, each git push to GitLab will automatically trigger a package rebuild in OBS. Your username will appear in the osc log source history.

Have a lot of fun!

References

Would you buy me a coffee?
If you really liked it, if it was really helpful for you, is it worth a coffee? If you want, you can "buy me a coffee" with PayPal or contribute to the project in other ways.

Comments

About

The Linux Kamarada Project aims to spread and promote Linux as a robust, secure, versatile and easy to use operating system, suitable for everyday use be at home, at work or on the server. The project focuses mainly on distribution and documentation.

Ads

Facebook

Author