Skip to content

Commit 4e6e82c

Browse files
authored
Add Alma 9 rpmbuild + bazel environment for examples (#969)
This provides a consistent starting point for running rpmbuild examples using a docker container build on Alma 9. Closes: #968
2 parents df80ac7 + 9906bc7 commit 4e6e82c

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
rpmbuild_docker
2+
===============
3+
4+
This provides an easy way to create an almalinux-based container that can be used
5+
to run `rpmbuild` via `pkg_rpm()` rules.
6+
7+
For example:
8+
9+
```console
10+
[rules_pkg]$ cd examples/rpm/system_rpmbuild_bzlmod/
11+
[system_rpmbuild_bzlmod]$ ../../../contrib/alma9_rpmbuild_docker/run.sh
12+
[+] Building 0.1s (9/9) FINISHED
13+
```
14+
15+
```console
16+
[devuser@fd4cc85e6e5a system_rpmbuild_bzlmod]$ bazel build test-rpm
17+
Starting local Bazel server (8.3.1) and connecting to it...
18+
INFO: Analyzed target //:test-rpm (80 packages loaded, 3318 targets configured).
19+
INFO: Found 1 target...
20+
Target //:test-rpm up-to-date:
21+
bazel-bin/test-rpm.rpm
22+
bazel-bin/test-rpm-all.rpm
23+
bazel-bin/test-rpm-1-0.all.rpm
24+
INFO: Elapsed time: 5.007s, Critical Path: 0.06s
25+
INFO: 1 process: 9 action cache hit, 1 internal.
26+
INFO: Build completed successfully, 1 total action
27+
```
28+
29+
```console
30+
[devuser@fd4cc85e6e5a system_rpmbuild_bzlmod]$ rpm -qlp bazel-bin/test-rpm.rpm
31+
/BUILD
32+
/MODULE.bazel
33+
/README.md
34+
/test_rpm.spec
35+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM almalinux:9.6
2+
3+
ARG USER_ID=1000
4+
ARG GROUP_ID=1000
5+
ARG TARGETARCH
6+
7+
ENV BAZELISK_VERSION=v1.26.0
8+
ENV BAZELISK_URL=https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_VERSION}/bazelisk-linux-${TARGETARCH}
9+
10+
RUN dnf install -y \
11+
ca-certificates \
12+
gcc-c++ \
13+
rpm-build \
14+
&& dnf clean all \
15+
&& curl -sSL -o /usr/local/bin/bazel ${BAZELISK_URL} \
16+
&& chmod +x /usr/local/bin/bazel
17+
18+
RUN groupadd --gid $GROUP_ID devgroup && \
19+
useradd --uid $USER_ID --gid $GROUP_ID --create-home --shell /bin/bash -l devuser
20+
21+
VOLUME /home/devuser/.cache
22+
23+
RUN mkdir -p /home/devuser/.cache && \
24+
chown -R ${USER_ID}:${GROUP_ID} /home/devuser/.cache
25+
26+
USER devuser
27+
WORKDIR /home/devuser
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Copyright 2025 The Bazel Authors. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -ueo pipefail
17+
18+
tag="${TAG:-alma9-bazel}"
19+
volume="${VOLUME:-bazel-cache}"
20+
21+
dir=$(realpath "$(dirname "$0")")
22+
repo_root="$dir/../.."
23+
24+
USER_ID=${USER_ID:-1000}
25+
GROUP_ID=${GROUP_ID:-1000}
26+
(
27+
set -x
28+
docker build -t "$tag" --build-arg USER_ID="$USER_ID" --build-arg GROUP_ID="$GROUP_ID" "$dir/docker"
29+
)
30+
31+
docker_args=(
32+
-v "$volume":/home/devuser/.cache
33+
-v "$repo_root:$repo_root"
34+
-w "$PWD"
35+
--rm
36+
-i
37+
-t
38+
)
39+
40+
set -x
41+
exec docker run "${docker_args[@]}" "$tag" "$@"

0 commit comments

Comments
 (0)