Skip to content

Build and publish containers with OBS

Why use the Open Build Service?

  • it will host the latest successful build
  • it automatically rebuilds containers if included packages or dependencies get updates

General prerequisites:


Browser web interface

Direct link to video, in case it does not show up below


Command-line interface

1. Create new project


1.1. Meta configuration

Run

> osc meta prj home:eroca:test --edit

and add a containers repository for your new project:

<project name="home:eroca:test">

  <title/>
  <description/>

  <person userid="eroca" role="bugowner"/>
  <person userid="eroca" role="maintainer"/>

  <repository name="containers">
    <path project="openSUSE:Containers:Tumbleweed" repository="containers"/>
    <arch>x86_64</arch>
  </repository>

</project>

This way you have created a new project and configured a repository.


1.2. Project configuration

Run

> osc meta prjconf home:eroca:test --edit

and add the following configuration:

%if "%_repository" == "containers"
Type: docker
Prefer: openSUSE-release-appliance-docker
%endif

After this step you have enabled container builds in the repository.


2. Create new package


2.1. Checkout project

> osc checkout home:eroca:test
> cd home:eroca:test

2.2. Create new package

> osc mkpac container-hello
> cd container-hello


3. Add Dockerfile


Open your favorite editor, use the following as template:

#!BuildTag: hello

FROM opensuse/tumbleweed

# add repositories as needed
# RUN zypper addrepo https://download.opensuse.org/repositories/home:eroca:test/openSUSE_Tumbleweed/ "home:eroca:test"
# RUN zypper modifyrepo -p 97 "home:eroca:test"
# RUN zypper --gpg-auto-import-keys refresh

# install packages
RUN zypper --non-interactive install hello

CMD hello

then run:

> osc add Dockerfile

Noticed the #!BuildTag line at the beginning? That's specific to OBS; it's your container name.


4. Build locally


Building locally lets you fix any errors before commiting, which also saves server resources.

> osc build

You can of course just use docker or podman for that as well.


5. Commit changes


Commiting changes triggers building and publishing on the server.

> osc commit -m "Initial commit of container-hello"

Check results, will take a few minutes to finish:

> osc results --watch
containers           x86_64     building
containers           x86_64     finished*
containers           x86_64     succeeded*
^C


6. Start using your container!


> docker pull registry.opensuse.org/home/eroca/test/containers/hello:latest
> docker run --rm registry.opensuse.org/home/eroca/test/containers/hello:latest
Hello, world!



Last update: April 28, 2023