Skip to content

Commit aa10ba7

Browse files
dcermakDmitri Popovdmach
committed
create an osc container for package maintenance
Co-authored-by: Dmitri Popov <dmpop@cameracode.coffee> Co-authored-by: Daniel Mach <daniel.mach@suse.com>
1 parent 6c12d2d commit aa10ba7

4 files changed

Lines changed: 246 additions & 0 deletions

File tree

src/bci_build/package/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
15631563
from .appcontainers import GRAFANA_CONTAINERS # noqa: E402
15641564
from .appcontainers import HELM_CONTAINERS # noqa: E402
15651565
from .appcontainers import NGINX_CONTAINERS # noqa: E402
1566+
from .appcontainers import OSC_CONTAINER # noqa: E402
15661567
from .appcontainers import PCP_CONTAINERS # noqa: E402
15671568
from .appcontainers import PROMETHEUS_CONTAINERS # noqa: E402
15681569
from .appcontainers import REGISTRY_CONTAINERS # noqa: E402
@@ -1636,6 +1637,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
16361637
*TOMCAT_CONTAINERS,
16371638
*GCC_CONTAINERS,
16381639
*SPACK_CONTAINERS,
1640+
OSC_CONTAINER,
16391641
)
16401642
}
16411643

src/bci_build/package/appcontainers.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,94 @@ def _get_nginx_kwargs(os_version: OsVersion):
486486
)
487487
for os_version in (OsVersion.TUMBLEWEED,)
488488
]
489+
490+
491+
_BASE_PODMAN_OSC_CMD = (
492+
"podman run --rm -it --privileged "
493+
+ r"-v \$HOME/.config/osc/oscrc:/root/.config/osc/oscrc:ro,z "
494+
+ r"-v \$HOME/.local/state/osc/cookiejar:/root/.local/state/osc/cookiejar:z"
495+
)
496+
497+
OSC_CONTAINER = ApplicationStackContainer(
498+
name="osc",
499+
pretty_name="Packaging",
500+
package_name="packaging-image",
501+
os_version=OsVersion.TUMBLEWEED,
502+
is_latest=True,
503+
# we want all the recommends from osc & build
504+
no_recommends=False,
505+
version_in_uid=False,
506+
version="%%osc_version%%",
507+
replacements_via_service=[
508+
Replacement(regex_in_build_description="%%osc_version%%", package_name="osc")
509+
],
510+
extra_files={
511+
"entrypoint.sh": (Path(__file__).parent / "osc" / "entrypoint.sh").read_bytes()
512+
},
513+
extra_labels={
514+
"run": f"{_BASE_PODMAN_OSC_CMD} IMAGE",
515+
"runv": f"{_BASE_PODMAN_OSC_CMD} {(_pkg_cache_vol := '-v pkgcache:/var/tmp/osbuild-packagecache')} IMAGE",
516+
"runcwd": f"{_BASE_PODMAN_OSC_CMD} {(_cwd_mount := '-v .:/root/osc-workdir:z')} IMAGE",
517+
"runcwdv": f"{_BASE_PODMAN_OSC_CMD} {_pkg_cache_vol} {_cwd_mount} IMAGE",
518+
},
519+
package_list=[
520+
# osc + osc build
521+
"osc",
522+
"build",
523+
"cpio",
524+
"hostname",
525+
# all the services
526+
"obs-service-appimage",
527+
"obs-service-cargo",
528+
"obs-service-cdi_containers_meta",
529+
"obs-service-compose_kiwi_description",
530+
"obs-service-docker_label_helper",
531+
"obs-service-download_assets",
532+
"obs-service-download_files",
533+
"obs-service-download_url",
534+
"obs-service-extract_file",
535+
"obs-service-format_spec_file",
536+
"obs-service-go_modules",
537+
"obs-service-kiwi_label_helper",
538+
"obs-service-kiwi_metainfo_helper",
539+
"obs-service-kubevirt_containers_meta",
540+
"obs-service-node_modules",
541+
"obs-service-obs_scm",
542+
"obs-service-product_converter",
543+
"obs-service-recompress",
544+
"obs-service-refresh_patches",
545+
"obs-service-replace_using_env",
546+
"obs-service-replace_using_package_version",
547+
"obs-service-set_version",
548+
"obs-service-snapcraft",
549+
"obs-service-source_validator",
550+
"obs-service-tar",
551+
"obs-service-tar_scm",
552+
"obs-service-verify_file",
553+
*OsVersion.TUMBLEWEED.release_package_names,
554+
# for convenience
555+
"bash-completion",
556+
# for scmsync packages
557+
"git",
558+
"obs-scm-bridge",
559+
# IBS access
560+
"openssh-common",
561+
"openssh-clients",
562+
# for building
563+
"podman",
564+
"runc",
565+
],
566+
cmd=["/bin/bash"],
567+
custom_end="""WORKDIR /root/osc-workdir
568+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
569+
RUN chmod +x /usr/local/bin/entrypoint.sh
570+
ENV OSC_VM_TYPE=podman
571+
""",
572+
entrypoint=["/usr/local/bin/entrypoint.sh"],
573+
volumes=[
574+
# default location of the package cache
575+
"/var/tmp/osbuild-packagecache",
576+
# default buildroot path
577+
"/var/tmp/build-root-root",
578+
],
579+
)
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# OSC Packaging Container
2+
3+
{% include 'badges.j2' %}
4+
5+
This is the openSUSE packaging container image that includes all the required
6+
tools for creating and modifying packages in the [Open Build
7+
Service](https://build.opensuse.org/) using
8+
[osc](https://github.com/openSUSE/osc/).
9+
10+
11+
## How to use this container image
12+
13+
The container image is intended for interactive usage with a `.oscrc` configuration file and
14+
the osc cookiejar mounted into the container:
15+
16+
```ShellSession
17+
# podman run --rm -it \
18+
-v ~/.config/osc/oscrc:/root/.config/osc/oscrc:ro,z \
19+
-v ~/.local/state/osc/cookiejar:/root/.local/state/osc/cookiejar:rw,z \
20+
{{ image.pretty_reference }}
21+
```
22+
23+
The command launches an interactive shell environment that uses the local osc
24+
configuration. You can then check out packages, perform modifications, and send
25+
submissions to OBS.
26+
27+
To work on an already checked out package, mount the current working directory:
28+
29+
```ShellSession
30+
# podman run --rm -it \
31+
-v ~/.config/osc/oscrc:/root/.config/osc/oscrc:ro,z \
32+
-v ~/.local/state/osc/cookiejar:/root/.local/state/osc/cookiejar:z \
33+
-v .:/root/osc-workdir:z \
34+
{{ image.pretty_reference }}
35+
```
36+
37+
The container entrypoint recognizes whether you are launching it for interactive
38+
usage or invoking `osc` directly. You can omit the command `osc` in the second
39+
case. For example:
40+
41+
```ShellSession
42+
# podman run --rm -it \
43+
-v ~/.config/osc/oscrc:/root/.config/osc/oscrc:ro,z \
44+
-v ~/.local/state/osc/cookiejar:/root/.local/state/osc/cookiejar:z \
45+
{{ image.pretty_reference }} \
46+
ls openSUSE:Factory
47+
```
48+
49+
The command automatically forwards the arguments to `osc` and calls
50+
`osc ls openSUSE:Factory`.
51+
52+
53+
### Building packages
54+
55+
The container image can be used to build packages using the podman build backend
56+
(the default in this container image). The podman backend can only build RPM
57+
packages, building containers with docker or disk images with kiwi is not
58+
supported at the moment.
59+
60+
`osc` will cache build dependencies in the pre-configured `packagecachedir`. The
61+
`packagecachedir` defaults to `/var/tmp/osbuild-packagecache` and is declared as
62+
a volume in this container image. To speed up package builds, it is recommended
63+
to bind mount the package cache directory onto the host or use a persistent
64+
container volume, e.g. as follows:
65+
66+
```ShellSession
67+
# podman run --rm -it \
68+
-v ~/.config/osc/oscrc:/root/.config/osc/oscrc:ro,z \
69+
-v ~/.local/state/osc/cookiejar:/root/.local/state/osc/cookiejar:z \
70+
-v pkgcache:/var/tmp/osbuild-packagecache \
71+
{{ image.pretty_reference }}
72+
```
73+
74+
The above command only applies if you are using the default package cache
75+
location. Obtain the current setting via:
76+
77+
```ShellSession
78+
# osc config general packagecachedir
79+
'general': 'packagecachedir' is set to '/var/tmp/osbuild-packagecache'
80+
```
81+
82+
83+
### Using the image labels
84+
85+
The image provides four labels: `run`, `runv`, `runcwd`, `runcwdv`. The `run`
86+
label includes the full command, to run the `osc` container, while the `runcwd`
87+
label additionally mounts the current working directory to `/root/osc-workdir`
88+
(the container images' working directory). The labels with the `v` appended
89+
additionally include the directive to mount a container volume called `pkgcache`
90+
to `/var/tmp/osbuild-packagecache`.
91+
92+
To view the labels, use the following command:
93+
94+
```ShellSession
95+
# podman container runlabel run --display {{ image.pretty_reference }}
96+
```
97+
98+
The labels can be used to run the container with Podman version 5.1.0 or later:
99+
100+
```ShellSession
101+
# podman container runlabel run \
102+
{{ image.pretty_reference }} \
103+
ls openSUSE:Factory
104+
```
105+
106+
107+
### Connecting to build.suse.de
108+
109+
build.suse.de uses an SSH-based authentication, which requires additional
110+
resources to be available in the container. You also must provide the internal certificate to the container:
111+
112+
```ShellSession
113+
# podman run --rm -it \
114+
-v ~/.config/osc/oscrc:/root/.config/osc/oscrc:ro,z \
115+
-v ~/.local/state/osc/cookiejar:/root/.local/state/osc/cookiejar:z \
116+
-v /etc/ssl/ca-bundle.pem:/etc/ssl/ca-bundle.pem:ro,z \
117+
-v $SSH_AUTH_SOCK:/run/user/0/ssh-agent.socket:z \
118+
-e SSH_AUTH_SOCK=/var/run/user/0/ssh-agent.socket:z \
119+
-v "$PWD":/root/osc-workdir:z \
120+
{{ image.pretty_reference }}
121+
```
122+
123+
124+
## Limitations
125+
126+
- Currently, it is not possible to build container images or disk images in a
127+
container.
128+
- The `runlabel run` command only works with Podman 5.1.0 and newer.
129+
130+
131+
## Volumes
132+
133+
The container image is preconfigured to put `/var/tmp` into a volume. This
134+
directory is used by `osc` to store the buildroot and the package cache.
135+
136+
{% include 'licensing_and_eula.j2' %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
if [[ ! -e /root/.config/osc/oscrc ]]; then
4+
cat << EOF
5+
This container is expected to be launched with your oscrc mounted to
6+
/root/.config/osc/oscrc
7+
8+
Please consult the README or the label 'run' for the full invocation.
9+
EOF
10+
fi
11+
12+
if [[ "-h --help -v --verbose -q --quiet --debug --debugger --post-mortem --traceback -H --http-debug --http-full-debug -A --apiurl --config --setopt --no-keyring add addchannels addcontainers addremove ar aggregatepac api branch getpac bco branchco browse build wipe shell chroot buildconfig buildhistory buildhist buildinfo buildlog buildlogtail blt bl cat less blame changedevelrequest changedevelreq cr checkconstraints checkout co clean cleanassets ca clone comment commit checkin ci config copypac create-pbuild-config cpc createincident createrequest creq delete remove del rm deleterequest deletereq droprequest dropreq dr dependson detachbranch develproject dp bsdevelproject diff di ldiff linkdiff distributions dists downloadassets da enablechannels enablechannel fork getbinaries help importsrcpkg info init jobhistory jobhist linkpac linktobranch list LL lL ll ls localbuildlog lbl lock log maintainer bugowner maintenancerequest mr mbranch maintained sm meta mkpac mv my patchinfo pdiff prdiff projdiff projectdiff prjresults pr pull pull_request rdelete rdiff rebuild rebuildpac release releaserequest remotebuildlog remotebuildlogtail rbuildlogtail rblt rbuildlog rbl repairlink repairwc repo repositories platforms repos repourls request review rq requestmaintainership reqbs reqms reqmaintainership requestbugownership reqbugownership resolved restartbuild abortbuild results r revert rpmlintlog lint rpmlint rremove search bse se sendsysrq service setdevelproject sdp setlinkrev showlinked signkey staging status st submitrequest submitpac submitreq sr token triggerreason tr undelete unlock update up updatepacmetafromspec updatepkgmetafromspec metafromspec vc version whatdependson whois user who wipebinaries unpublish workerinfo" =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
13+
# looks like the user is executing the container as the osc command
14+
osc "$@"
15+
else
16+
exec "$@"
17+
fi

0 commit comments

Comments
 (0)