Skip to content

Commit

Permalink
Add support for Azure Linux
Browse files Browse the repository at this point in the history
Azure Linux looks a lot like Fedora Linux so we opt to share configuration
between Azure and Fedora/CentOS and inherit the Azure definition from
Fedora.
  • Loading branch information
DaanDeMeyer committed Jul 20, 2024
1 parent b7b5405 commit 2aa4870
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
- fedora
- opensuse
- ubuntu
- azure
tools:
- arch
- debian
Expand Down
15 changes: 15 additions & 0 deletions mkosi.conf.d/20-azure.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

[Match]
Distribution=azure

[Distribution]
Release=3.0

[Content]
# The unsigned-shim package tries to install to the same location as the signed shim package so we can't install and
# test unsigned shim.
ShimBootloader=none
Packages=
kernel
systemd-networkd
1 change: 1 addition & 0 deletions mkosi.conf.d/20-centos/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Release=9
# CentOS Stream 10 does not ship an unsigned shim
ShimBootloader=none
Packages=
kernel-core
linux-firmware
1 change: 1 addition & 0 deletions mkosi.conf.d/20-fedora/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release=rawhide

[Content]
Packages=
kernel-core
qemu-user-static
rpmautospec
systemd-networkd
1 change: 1 addition & 0 deletions mkosi.conf.d/20-fedora/mkosi.conf.d/20-x86_64.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Architecture=x86-64
[Content]
Packages=
amd-ucode-firmware
kernel-uki-virt
shim-unsigned-x64
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Distribution=|centos
Distribution=|alma
Distribution=|rocky
Distribution=|fedora
Distribution=|azure

[Content]
Packages=
bash
iproute
iputils
kernel-core
openssh-clients
openssh-server
perf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Architecture=x86-64
Packages=
grub2-efi-x64-modules
grub2-pc
kernel-uki-virt
microcode_ctl
1 change: 1 addition & 0 deletions mkosi/distributions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Distribution(StrEnum):
openmandriva = enum.auto()
rocky = enum.auto()
alma = enum.auto()
azure = enum.auto()
custom = enum.auto()

def is_centos_variant(self) -> bool:
Expand Down
89 changes: 89 additions & 0 deletions mkosi/distributions/azure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# SPDX-License-Identifier: LGPL-2.1+

from collections.abc import Iterable

from mkosi.config import Architecture
from mkosi.context import Context
from mkosi.distributions import (
fedora,
join_mirror,
)
from mkosi.installer.dnf import Dnf
from mkosi.installer.rpm import RpmRepository, find_rpm_gpgkey, setup_rpm
from mkosi.log import die
from mkosi.util import listify


class Installer(fedora.Installer):
@classmethod
def pretty_name(cls) -> str:
return "Azure Linux"

@classmethod
def default_release(cls) -> str:
return "3.0"

@classmethod
def filesystem(cls) -> str:
return "ext4"

@classmethod
def setup(cls, context: Context) -> None:
Dnf.setup(context, cls.repositories(context), filelists=False)
setup_rpm(context, dbpath="/var/lib/rpm")

@classmethod
def install(cls, context: Context) -> None:
cls.install_packages(context, ["filesystem", "azurelinux-release"], apivfs=False)

@classmethod
@listify
def repositories(cls, context: Context) -> Iterable[RpmRepository]:
gpgkey = find_rpm_gpgkey(context, "MICROSOFT-RPM-GPG-KEY")
if not gpgkey:
die("MICROSOFT-RPM-GPG-KEY GPG key not found in /usr/share/distribution-gpg-keys/azure-linux",
hint="Make sure the distribution-gpg-keys package is installed")

gpgurls = (gpgkey,)

if context.config.local_mirror:
yield RpmRepository("base", f"baseurl={context.config.local_mirror}", gpgurls)
return

mirror = context.config.mirror or "https://packages.microsoft.com/azurelinux"
url = join_mirror(mirror, f"{context.config.release}/preview")

for repo in ("base", "extended", "ms-oss", "ms-non-oss", "cloud-native", "NVIDIA"):
yield RpmRepository(
repo,
f"baseurl={url}/{repo}/$basearch",
gpgurls,
)

for repo in ("base", "cloud-native", "extended"):
yield RpmRepository(
f"{repo}-debuginfo",
f"baseurl={url}/{repo}/debuginfo/$basearch",
gpgurls,
enabled=False,
)

for repo in ("base", "cloud-native", "extended", "ms-oss"):
yield RpmRepository(
f"{repo}-source",
f"baseurl={url}/{repo}/srpms",
gpgurls,
enabled=False,
)

@classmethod
def architecture(cls, arch: Architecture) -> str:
a = {
Architecture.arm64 : "aarch64",
Architecture.x86_64 : "x86_64",
}.get(arch)

if not a:
die(f"Architecture {a} is not supported by {cls.pretty_name()}")

return a
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ Distribution=|centos
Distribution=|alma
Distribution=|rocky
Distribution=|rhel
Distribution=|azure

[Content]
Packages=
# Various libraries that are dlopen'ed by systemd
libfido2
tpm2-tss

# File system checkers for supported root file systems
e2fsprogs
xfsprogs

# fsck.btrfs is a dummy, checking is done in the kernel.

RemovePackages=
# Various packages pull in shadow-utils to create users, we can remove it afterwards
shadow-utils
8 changes: 8 additions & 0 deletions mkosi/resources/mkosi-initrd/mkosi.conf.d/10-azure.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

[Match]
Distribution=azure

[Content]
Packages=
util-linux
5 changes: 5 additions & 0 deletions mkosi/resources/mkosi-initrd/mkosi.conf.d/10-centos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ Distribution=|rhel

[Content]
Packages=
libfido2
util-linux

RemovePackages=
# Various packages pull in shadow-utils to create users, we can remove it afterwards
shadow-utils
5 changes: 5 additions & 0 deletions mkosi/resources/mkosi-initrd/mkosi.conf.d/10-fedora.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ Distribution=fedora

[Content]
Packages=
libfido2
util-linux-core

RemovePackages=
# Various packages pull in shadow-utils to create users, we can remove it afterwards
shadow-utils
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Distribution=|alma
Distribution=|rocky
Distribution=|rhel
Distribution=|fedora
Distribution=|azure

[Content]
Packages=
Expand Down
15 changes: 15 additions & 0 deletions mkosi/resources/mkosi-tools/mkosi.conf.d/10-azure.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

[Match]
Distribution=azure

[Content]
Packages=
btrfs-progs
distribution-gpg-keys
dnf5
dnf5-plugins
erofs-utils
qemu-system-aarch64-core
qemu-system-s390x-core
systemd-ukify
9 changes: 6 additions & 3 deletions mkosi/resources/mkosi.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
: The distribution to install in the image. Takes one of the following
arguments: `fedora`, `debian`, `ubuntu`, `arch`, `opensuse`, `mageia`,
`centos`, `rhel`, `rhel-ubi`, `openmandriva`, `rocky`, `alma`,
`custom`. If not specified, defaults to the distribution of the host
or `custom` if the distribution of the host is not a supported
distribution.
`azure` or `custom`. If not specified, defaults to the distribution
of the host or `custom` if the distribution of the host is not a
supported distribution.

`Release=`, `--release=`, `-r`
: The release of the distribution to install in the image. The precise
Expand Down Expand Up @@ -437,6 +437,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
| `rhel-ubi` | https://cdn-ubi.redhat.com | |
| `mageia` | https://www.mageia.org | |
| `openmandriva` | http://mirrors.openmandriva.org | |
| `azure` | https://packages.microsoft.com/ | |

`LocalMirror=`, `--local-mirror=`
: The mirror will be used as a local, plain and direct mirror instead
Expand Down Expand Up @@ -1908,6 +1909,8 @@ distributions:

* *Alma Linux*

* *Azure Linux*

* *None* (**Requires the user to provide a pre-built rootfs**)

In theory, any distribution may be used on the host for building images
Expand Down

0 comments on commit 2aa4870

Please sign in to comment.