Skip to content

Commit 707c2d6

Browse files
ravanellijlebon
authored andcommittedMar 5, 2025·
cmd-remote-build-container: Add support for secret, mount-host-ca-certs, and security-opt parameters
- Allow passing secret files and SELinux labels in remote builds. - Enable mounting the host's CA certificates, as they are already available by default on the host. Signed-off-by: Renata Ravanelli <[email protected]>
1 parent 71f5992 commit 707c2d6

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed
 

‎src/cmd-remote-build-container

+26-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ logging.basicConfig(level=logging.INFO,
1515
format="%(asctime)s %(levelname)s - %(message)s")
1616

1717

18-
def build_container_image(labels, buildDir, fromimage, cacheTTL, repo, tag):
18+
def build_container_image(labels, buildDir, fromimage, cacheTTL,
19+
repo, tag, secret, mount_ca, security_opt):
1920
'''
2021
Build the image using podman remote and push to the registry
2122
@param labels list labels to add to image
@@ -30,6 +31,13 @@ def build_container_image(labels, buildDir, fromimage, cacheTTL, repo, tag):
3031
cmd.extend([f"--label={label}"])
3132
if fromimage:
3233
cmd.extend([f"--from={fromimage}"])
34+
if secret:
35+
for s in secret:
36+
cmd.append(f"--secret={s}")
37+
if mount_ca:
38+
cmd.extend(["-v", "/etc/pki/ca-trust:/etc/pki/ca-trust:ro"])
39+
if security_opt:
40+
cmd.extend(["--security-opt", security_opt])
3341
# Long running command. Send output to stdout for logging
3442
runcmd(cmd)
3543

@@ -173,7 +181,9 @@ def main():
173181
logging.info("Building container via podman")
174182
builddir = os.path.join(gitdir, args.git_sub_dir)
175183
build_container_image(args.labels, builddir, args.fromimage,
176-
args.cache_ttl, args.repo, args.tag)
184+
args.cache_ttl, args.repo, args.tag,
185+
args.secret, args.mount_host_ca_certs,
186+
args.security_opt)
177187

178188
# Push to the registry if needed, else save the image to a file
179189
if args.push_to_registry:
@@ -200,6 +210,8 @@ Examples:
200210
--git-ref main \
201211
--git-url https://github.com/coreos/coreos-assembler.git \
202212
--repo quay.io/coreos/coreos-assembler-staging \
213+
--mount-host-ca-certs \
214+
--secret id=yumrepos,src=/path/to/rhel-9.6.repo \
203215
--push-to-registry """)
204216

205217
parser.add_argument(
@@ -212,9 +224,6 @@ Examples:
212224
'--cache-ttl', default="0.1s", required=False,
213225
help="""Pass along --cache-ttl=<value> to `podman build`.
214226
Defaults to 0.1s, which is effectively `--no-cache`""")
215-
parser.add_argument(
216-
'--label', dest="labels", default=[], action='append',
217-
required=False, help='Add image label(s)')
218227
parser.add_argument(
219228
'--force', required=False, action='store_true',
220229
help='Force image overwrite')
@@ -230,9 +239,21 @@ Examples:
230239
parser.add_argument(
231240
'--git-sub-dir', default='', required=False,
232241
help='Git sub directory to use for container build')
242+
parser.add_argument(
243+
'--label', dest="labels", default=[], action='append',
244+
required=False, help='Add image label(s)')
245+
parser.add_argument(
246+
'--mount-host-ca-certs', required=False, action='store_true',
247+
help='Mount the CA certificate from the remote host')
233248
parser.add_argument(
234249
'--repo', default='localhost', required=False,
235250
help='Registry repository')
251+
parser.add_argument(
252+
'--secret', required=False, action='append', default=[],
253+
help='Provide a local secret for remote access. Uses the same syntax as `podman build --secret`')
254+
parser.add_argument(
255+
'--security-opt', required=False,
256+
help='Set SELinux options. Uses the same syntax as `podman build --security-opt`')
236257
parser.add_argument(
237258
'--tag', required=False,
238259
help='Force image tag. The default is arch-commit')

0 commit comments

Comments
 (0)
Please sign in to comment.