Skip to content

Commit 9e3909b

Browse files
committed
container: Add export --format=tar command
Some people want to use container build tools, but for compatibility with older systems export a tar format of the OS state e.g. Anaconda liveimg expects this. Basically this is only *slightly* more than just `tar cf`; we need to handle SELinux labeling and move the kernel. Ref: #1957 Assisted-by: OpenCode (Sonnet 4.5) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 99820c1 commit 9e3909b

File tree

13 files changed

+1671
-9
lines changed

13 files changed

+1671
-9
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,45 @@ jobs:
304304
name: tmt-log-PR-${{ github.event.number }}-fedora-43-coreos-${{ env.ARCH }}
305305
path: /var/tmp/tmt
306306

307+
# Test the container export -> Anaconda liveimg install path.
308+
# Builds localhost/bootc, exports as tarball, installs via Anaconda in QEMU,
309+
# and verifies the resulting disk boots.
310+
test-container-export:
311+
needs: package
312+
runs-on: ubuntu-24.04
313+
314+
steps:
315+
- uses: actions/checkout@v6
316+
- name: Bootc Ubuntu Setup
317+
uses: bootc-dev/actions/bootc-ubuntu-setup@main
318+
with:
319+
libvirt: true
320+
321+
- name: Setup env
322+
run: |
323+
echo "BOOTC_base=quay.io/centos-bootc/centos-bootc:stream10" >> $GITHUB_ENV
324+
325+
- name: Download package artifacts
326+
uses: actions/download-artifact@v7
327+
with:
328+
name: packages-centos-10
329+
path: target/packages/
330+
331+
- name: Build and run container export test
332+
run: |
333+
BOOTC_SKIP_PACKAGE=1 just test-container-export
334+
335+
- name: Archive test logs
336+
if: always()
337+
uses: actions/upload-artifact@v6
338+
with:
339+
name: container-export-test-${{ env.ARCH }}
340+
path: target/anaconda-test/*.log
341+
307342
# Sentinel job for required checks - configure this job name in repository settings
308343
required-checks:
309344
if: always()
310-
needs: [cargo-deny, validate, package, test-integration, test-coreos]
345+
needs: [cargo-deny, validate, package, test-integration, test-coreos, test-container-export]
311346
runs-on: ubuntu-latest
312347
steps:
313348
- run: exit 1
@@ -316,4 +351,5 @@ jobs:
316351
needs.validate.result != 'success' ||
317352
needs.package.result != 'success' ||
318353
needs.test-integration.result != 'success' ||
319-
needs.test-coreos.result != 'success'
354+
needs.test-coreos.result != 'success' ||
355+
needs.test-container-export.result != 'success'

Cargo.lock

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Justfile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ test-tmt *ARGS: build
108108
[group('core')]
109109
test-container: build build-units
110110
podman run --rm --read-only localhost/bootc-units /usr/bin/bootc-units
111-
podman run --rm --env=BOOTC_variant={{variant}} --env=BOOTC_base={{base}} {{base_img}} bootc-integration-tests container
111+
podman run --rm --env=BOOTC_variant={{variant}} --env=BOOTC_base={{base}} --mount=type=image,source={{base_img}},target=/run/target {{base_img}} bootc-integration-tests container
112112

113113
# Build and test sealed composefs images
114114
[group('core')]
@@ -138,6 +138,28 @@ test-composefs-grub filesystem:
138138
validate:
139139
podman build {{base_buildargs}} --target validate .
140140

141+
# Test container export via Anaconda liveimg install in a QEMU VM
142+
[group('testing')]
143+
test-container-export: build
144+
#!/bin/bash
145+
set -xeuo pipefail
146+
iso=target/anaconda-test/boot.iso
147+
if [ ! -f "$iso" ]; then
148+
# Determine the ISO download URL from the base image's os-release
149+
eval $(podman run --rm {{base_img}} bash -c '. /etc/os-release && echo "ID=$ID VERSION_ID=$VERSION_ID"')
150+
case "${ID}-${VERSION_ID}" in
151+
centos-10)
152+
url="https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/iso/CentOS-Stream-10-latest-x86_64-boot.iso" ;;
153+
fedora-*)
154+
url="https://download.fedoraproject.org/pub/fedora/linux/releases/${VERSION_ID}/Everything/x86_64/iso/Fedora-Everything-netinst-x86_64-${VERSION_ID}-1.1.iso" ;;
155+
*)
156+
echo "Unsupported OS: ${ID}-${VERSION_ID}" >&2; exit 1 ;;
157+
esac
158+
mkdir -p target/anaconda-test
159+
curl -L --retry 3 --progress-bar -o "$iso" "$url"
160+
fi
161+
cargo xtask anaconda-test --iso "$iso" {{base_img}}
162+
141163
# ============================================================================
142164
# Testing variants and utilities
143165
# ============================================================================

crates/lib/src/cli.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,41 @@ pub(crate) enum ContainerOpts {
419419
#[clap(last = true)]
420420
args: Vec<OsString>,
421421
},
422+
/// Export container filesystem as a tar archive.
423+
///
424+
/// This command exports the container filesystem in a bootable format with proper
425+
/// SELinux labeling. The output is written to stdout by default or to a specified file.
426+
///
427+
/// Example:
428+
/// bootc container export /target > output.tar
429+
#[clap(hide = true)]
430+
Export {
431+
/// Format for export output
432+
#[clap(long, default_value = "tar")]
433+
format: ExportFormat,
434+
435+
/// Output file (defaults to stdout)
436+
#[clap(long, short = 'o')]
437+
output: Option<Utf8PathBuf>,
438+
439+
/// Copy kernel and initramfs from /usr/lib/modules to /boot for legacy compatibility.
440+
/// This is useful for installers that expect the kernel in /boot.
441+
#[clap(long)]
442+
kernel_in_boot: bool,
443+
444+
/// Disable SELinux labeling in the exported archive.
445+
#[clap(long)]
446+
disable_selinux: bool,
447+
448+
/// Path to the container filesystem root
449+
target: Utf8PathBuf,
450+
},
451+
}
452+
453+
#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
454+
pub(crate) enum ExportFormat {
455+
/// Export as tar archive
456+
Tar,
422457
}
423458

424459
/// Subcommands which operate on images.
@@ -1631,6 +1666,22 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
16311666
allow_missing_verity,
16321667
args,
16331668
} => crate::ukify::build_ukify(&rootfs, &kargs, &args, allow_missing_verity),
1669+
ContainerOpts::Export {
1670+
format,
1671+
target,
1672+
output,
1673+
kernel_in_boot,
1674+
disable_selinux,
1675+
} => {
1676+
crate::container_export::export(
1677+
&format,
1678+
&target,
1679+
output.as_deref(),
1680+
kernel_in_boot,
1681+
disable_selinux,
1682+
)
1683+
.await
1684+
}
16341685
},
16351686
Opt::Completion { shell } => {
16361687
use clap_complete::aot::generate;

0 commit comments

Comments
 (0)