Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm support #490

Merged
merged 8 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:Edge
nm-configurator && \
zypper clean -a

# Make adjustments for running guestfish and image modifications on aarch64
# guestfish looks for very specific locations on the filesystem for UEFI firmware
# and also expects the boot kernel to be a portable executable (PE), not ELF.
RUN zypper install -y qemu-uefi-aarch64 && \
atanasdinov marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p /usr/share/edk2/aarch64 && \
cp /usr/share/qemu/aavmf-aarch64-code.bin /usr/share/edk2/aarch64/QEMU_EFI-pflash.raw && \
cp /usr/share/qemu/aavmf-aarch64-vars.bin /usr/share/edk2/aarch64/vars-template-pflash.raw && \
mv /boot/vmlinux* /boot/backup-vmlinux && \
zypper clean -a

COPY --from=0 /src/eib /bin/eib
COPY config/artifacts.yaml artifacts.yaml

Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Kubernetes manifests are now applied in a systemd service
* Artifact sources origin and metadata are now extracted from a configuration file (`config/artifacts.yaml`)
* Dropped `-chart` suffix from installed Helm chart names
* Added ability to build Arm images on an Arm host machine
atanasdinov marked this conversation as resolved.
Show resolved Hide resolved

## API

Expand Down
2 changes: 2 additions & 0 deletions pkg/build/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (b *Builder) writeModifyScript(imageFilename string, includeCombustion, ren
ConfigureCombustion bool
RenameFilesystem bool
DiskSize string
Arch string
}{
ImagePath: imageFilename,
CombustionDir: b.context.CombustionDir,
Expand All @@ -114,6 +115,7 @@ func (b *Builder) writeModifyScript(imageFilename string, includeCombustion, ren
ConfigureCombustion: includeCombustion,
RenameFilesystem: renameFilesystem,
DiskSize: string(b.context.ImageDefinition.OperatingSystem.RawConfiguration.DiskSize),
Arch: string(b.context.ImageDefinition.Image.Arch),
}

data, err := template.Parse(modifyScriptName, modifyRawImageTemplate, &values)
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestWriteModifyScript(t *testing.T) {
"btrfs filesystem label / INSTALL",
"sed -i '/ignition.platform/ s/$/ alpha beta /' /tmp/grub.cfg",
"truncate -s 64G",
"virt-resize --expand /dev/sda3",
"virt-resize --expand $ROOT_PART",
},
expectedMissing: []string{},
},
Expand Down
13 changes: 12 additions & 1 deletion pkg/build/templates/modify-raw-image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ set -euo pipefail
#
# Guestfish Command Documentation: https://libguestfs.org/guestfish.1.html

# In x86_64, the default root partition is the third partition
ROOT_PART=/dev/sda3

# Make the necessary adaptations for aarch64
if [[ {{ .Arch }} == "aarch64" ]]; then
if ! test -f /dev/kvm; then
export LIBGUESTFS_BACKEND_SETTINGS=force_tcg
fi
ROOT_PART=/dev/sda2
fi

# Test the block size of the base image and adapt to suit either 512/4096 byte images
BLOCKSIZE=512
if ! guestfish -i --blocksize=$BLOCKSIZE -a {{.ImagePath}} echo "[INFO] 512 byte sector check successful."; then
Expand All @@ -26,7 +37,7 @@ fi
{{ if ne .DiskSize "" -}}
truncate -r {{.ImagePath}} {{.ImagePath}}.expanded
truncate -s {{.DiskSize}} {{.ImagePath}}.expanded
virt-resize --expand /dev/sda3 {{.ImagePath}} {{.ImagePath}}.expanded
virt-resize --expand $ROOT_PART {{.ImagePath}} {{.ImagePath}}.expanded
cp {{.ImagePath}}.expanded {{.ImagePath}}
rm -f {{.ImagePath}}.expanded
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eib/eib.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func buildCombustion(ctx *image.Context, rootDir string) (*combustion.Combustion
imgType := ctx.ImageDefinition.Image.ImageType
baseBuilder := resolver.NewTarballBuilder(ctx.BuildDir, imgPath, imgType, p)

combustionHandler.RPMResolver = resolver.New(ctx.BuildDir, p, baseBuilder, "")
combustionHandler.RPMResolver = resolver.New(ctx.BuildDir, p, baseBuilder, "", string(ctx.ImageDefinition.Image.Arch))
combustionHandler.RPMRepoCreator = rpm.NewRepoCreator(ctx.BuildDir)
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/rpm/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ type Resolver struct {
// path to the mounts.conf filepath that overrides the default mounts.conf configuration;
// if left empty the default override path will be used. For more info - https://github.com/containers/common/blob/v0.57/docs/containers-mounts.conf.5.md
overrideMountsPath string
// architecture of the packages the resolver should pull
arch string
}

func New(workDir string, podman Podman, baseImageBuilder BaseResolverImageBuilder, overrideMountsPath string) *Resolver {
func New(workDir string, podman Podman, baseImageBuilder BaseResolverImageBuilder, overrideMountsPath, arch string) *Resolver {
return &Resolver{
dir: workDir,
podman: podman,
baseResolverImageBuilder: baseImageBuilder,
overrideMountsPath: overrideMountsPath,
arch: arch,
}
}

Expand Down Expand Up @@ -185,11 +188,13 @@ func (r *Resolver) writeRPMResolutionScript(localRPMConfig *image.LocalRPMConfig
LocalRPMList string
LocalGPGList string
NoGPGCheck bool
Arch string
}{
RegCode: packages.RegCode,
AddRepo: packages.AdditionalRepos,
CacheDir: r.generateResolverImgRPMRepoPath(),
NoGPGCheck: packages.NoGPGCheck,
Arch: r.arch,
}

if len(packages.PKGList) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/rpm/resolver/templates/prepare-tarball.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ set -euo pipefail
WORK_DIR={{.WorkDir}}
IMG_PATH={{.ImgPath}}

# Make the necessarry adaptations for aarch64
if [[ $(uname -m) == "aarch64" ]]; then
atanasdinov marked this conversation as resolved.
Show resolved Hide resolved
export LIBGUESTFS_BACKEND_SETTINGS=force_tcg
fi

{{ if eq .ImgType "iso" -}}
xorriso -osirrox on -indev $IMG_PATH extract / $WORK_DIR/iso-root/

Expand Down
5 changes: 3 additions & 2 deletions pkg/rpm/resolver/templates/rpm-resolution.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ set -euo pipefail
# LocalRPMList - list of local RPMs for which dependency resolution has to be done
# LocalGPGList - list of local GPG keys that will be imported in the resolver image
# NoGPGCheck - when set to true skips the GPG validation for all third-party repositories and local RPMs
# Arch - sets the architecture of the rpm packages to pull

{{ if ne .RegCode "" }}
suseconnect -r {{ .RegCode }}
SLE_SP=$(cat /etc/rpm/macros.sle | awk '/sle/ {print $2};' | cut -c4) && suseconnect -p PackageHub/15.$SLE_SP/x86_64
SLE_SP=$(cat /etc/rpm/macros.sle | awk '/sle/ {print $2};' | cut -c4) && suseconnect -p PackageHub/15.$SLE_SP/{{ .Arch }}
zypper ref
trap "suseconnect -d" EXIT
{{ end -}}
Expand Down Expand Up @@ -51,4 +52,4 @@ zypper \
--allow-vendor-change \
-n {{.PKGList}} {{.LocalRPMList}}

touch {{.CacheDir}}/zypper-success
touch {{.CacheDir}}/zypper-success