Skip to content

Commit

Permalink
Arm support (#490)
Browse files Browse the repository at this point in the history
* Adding aarch64 support

* fixing tests

* Fixing rpm resolution stuff and Dockerfile changes

* Adding aarch64 support

* Fixing rpm resolution stuff and Dockerfile changes

* arm tweaks

* Update RELEASE_NOTES.md

* updates based on feedback

---------

Co-authored-by: Rhys Oxenham <[email protected]>
  • Loading branch information
dbw7 and rdoxenham authored Jul 11, 2024
1 parent cbefca6 commit 173908a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 10 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FROM opensuse/leap:15.6

# Dependency uses by line
# 1. ISO image building
# 2. RAW image modification on x86_64
# 2. RAW image modification on x86_64 and aarch64
# 3. Podman EIB library
# 4. RPM resolution logic
# 5. Embedded artefact registry
Expand All @@ -31,13 +31,21 @@ RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:Edge
zypper --gpg-auto-import-keys refresh && \
zypper install -y \
xorriso squashfs \
libguestfs kernel-default e2fsprogs parted gptfdisk btrfsprogs guestfs-tools lvm2 \
libguestfs kernel-default e2fsprogs parted gptfdisk btrfsprogs guestfs-tools lvm2 qemu-uefi-aarch64 \
podman \
createrepo_c \
helm hauler \
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 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

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 aarch64 images on an aarch64 host machine

## 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
4 changes: 2 additions & 2 deletions pkg/eib/eib.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func buildCombustion(ctx *image.Context, rootDir string) (*combustion.Combustion

imgPath := filepath.Join(ctx.ImageConfigDir, "base-images", ctx.ImageDefinition.Image.BaseImage)
imgType := ctx.ImageDefinition.Image.ImageType
baseBuilder := resolver.NewTarballBuilder(ctx.BuildDir, imgPath, imgType, p)
baseBuilder := resolver.NewTarballBuilder(ctx.BuildDir, imgPath, imgType, string(ctx.ImageDefinition.Image.Arch), 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/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ type TarballImageBuilder struct {
imgPath string
// type of the image that will be used as base (either ISO or RAW)
imgType string
// architecture of the image that will be built
arch string
// imgImporter used to import the tarball archive as a container image
imgImporter ImageImporter
}

func NewTarballBuilder(workDir, imgPath, imgType string, importer ImageImporter) *TarballImageBuilder {
func NewTarballBuilder(workDir, imgPath, imgType, arch string, importer ImageImporter) *TarballImageBuilder {
return &TarballImageBuilder{
dir: workDir,
imgPath: imgPath,
imgType: imgType,
arch: arch,
imgImporter: importer,
}
}
Expand Down Expand Up @@ -94,11 +97,13 @@ func (t *TarballImageBuilder) writeTarballImageScript() error {
ImgPath string
ArchiveName string
ImgType string
Arch string
}{
WorkDir: t.getTarballImgDir(),
ImgPath: t.getBaseISOCopyPath(),
ArchiveName: tarballName,
ImgType: t.imgType,
Arch: t.arch,
}

data, err := template.Parse(prepareTarballScriptName, prepareTraballTemplate, &values)
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 [[ {{ .Arch }} == "aarch64" ]]; then
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

0 comments on commit 173908a

Please sign in to comment.