Skip to content

Commit dac2446

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
docs: start a developers guide with a tip on sambacc builds
Start a developers guide document by documenting a process I use to test out development branches of sambacc in a proper samba-container image. Signed-off-by: John Mulligan <[email protected]>
1 parent 0c7d6d9 commit dac2446

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

docs/development.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Development Guide
2+
3+
4+
## Building samba containers with unreleased sambacc code
5+
6+
Changes to `sambacc` are validated by a suite of unit tests to ensure a minium
7+
level of quality, but that is often not enough to fully validate a
8+
work-in-progress feature, especially one that needs to interact with components
9+
from Samba in complex ways. One may want to try out an unreleased branch of
10+
sambacc code as part of a samba container image. Two methods of doing this are:
11+
* Build sambacc RPMs and put them in a yum/dnf repo
12+
* Customize the Containerfile to use a sambacc build stage
13+
14+
Both methods make use of the sambacc build image. The files needed to build the
15+
image are part of the [sambacc
16+
repo](https://github.com/samba-in-kubernetes/sambacc) and already-created
17+
images are available at quay.io:
18+
[quay.io/samba.org/sambacc](https://quay.io/repository/samba.org/sambacc).
19+
20+
### RPMs
21+
22+
One can build rpms using the sambacc test-and-build container.
23+
In this example we assume you have a git checkout of sambacc as the
24+
local path. Create a new directory to store build artifacts in:
25+
```
26+
mkdir -p _build
27+
```
28+
29+
Then run the container command like follows:
30+
```
31+
podman run -v $PWD:/var/tmp/build/sambacc -v $PWD/_build:/srv/dist/:z -e SAMBACC_DISTNAME=dev quay.io/samba.org/sambacc:latest
32+
```
33+
34+
Breaking it down, we're mounting the current dir at `/var/tmp/build/sambacc`,
35+
mounting the build dir at `/srv/dist` and telling the build container
36+
to store artifacts under the "distribution name" of `dev`. This should
37+
result in rpms, whl files and other artifacts in `_build/dev`. You can
38+
name your "dist" anything.
39+
40+
Now you have a directory with rpms in it you can run `createrepo` on them
41+
and/or publish them on the web. Managing the rpms is an exercise left to the
42+
reader.
43+
44+
To get them into a samba-container image, like the samba-server or
45+
samba-ad-server image, we need to get or create a repo file pointing to the
46+
repo hosting your rpms. The repo file must be saved into the build container at
47+
a path named like `/tmp/sambacc-dist-latest/sambacc*.repo`, so that the
48+
`install-sambacc.sh` script that is run during the image build can find it.
49+
50+
Typically this means modifying the Containerfile. Here's an example modification
51+
to the `images/server/Containerfile.fedora` file:
52+
```
53+
COPY .common/install-sambacc-common.sh /usr/local/bin/install-sambacc-common.sh
54+
COPY install-sambacc.sh /usr/local/bin/install-sambacc.sh
55+
# Add an ADD command to copy our repofile into the build
56+
ADD https://my-cool-repo.example.org/mystuff/sambacc.repo /tmp/sambacc-dist-latest
57+
RUN /usr/local/bin/install-sambacc.sh \
58+
"/tmp/sambacc-dist-latest" \
59+
"${SAMBACC_VERSION_SUFFIX}"
60+
```
61+
62+
Now build the image the usual way. It should contain your specific sambacc rpms.
63+
64+
65+
### Build Stage
66+
67+
Rather than building the sambacc RPMs and creating a repo for them, the build
68+
steps can be combined by modifying the `Containerfile`s to add a specific build
69+
stage. First add the build stage to the top of the Containerfile:
70+
```
71+
# --- new stuff ---
72+
FROM quay.io/samba.org/sambacc:latest AS sccbuilder
73+
ARG SAMBACC_VER=my-cool-branch
74+
ARG SAMBACC_REPO=https://github.com/example-user/sambacc
75+
RUN SAMBACC_DISTNAME=latest \
76+
/usr/local/bin/build.sh ${SAMBACC_VER} ${SAMBACC_REPO}
77+
# --- end new stuff ---
78+
79+
FROM registry.fedoraproject.org/fedora:38
80+
```
81+
82+
The variables `SAMBACC_VER` and `SAMBACC_REPO` can be overridden on the command
83+
line so you don't have to keep modifying the Containerfile to set them, unless
84+
you want to. `SAMBACC_VER` takes a git ref and that can be a barnch name or a
85+
commit hash. Using a commit hash can be handy to avoid caching issues.
86+
87+
Next, we need to make a modification to the RUN command that executes
88+
`install-sambacc.sh`:
89+
```
90+
# add the --mount argument to map the dist dir of the sccbuilder
91+
# container to the /tmp/sambacc-dist-latest dir in the current build
92+
# container.
93+
RUN --mount=type=bind,from=sccbuilder,source=/srv/dist/latest,destination=/tmp/sambacc-dist-latest bash -x /usr/local/bin/install-sambacc.sh \
94+
"/tmp/sambacc-dist-latest" \
95+
"${SAMBACC_VERSION_SUFFIX}"
96+
```
97+
98+
Very old versions of podman and docker may not support `--mount`. As an
99+
alternative, you can add a `COPY` command to copy the rpms from one container
100+
to the other.

0 commit comments

Comments
 (0)