Skip to content

Commit

Permalink
Merge pull request #292 from SUSE/nextgen
Browse files Browse the repository at this point in the history
DMS - Add Container Workflow Feature
  • Loading branch information
schaefi authored Oct 30, 2024
2 parents 7ef5f3b + 1a6c36c commit 5aae674
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 0 deletions.
77 changes: 77 additions & 0 deletions container/sle15/config.kiwi
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>

<image schemaversion="7.5" name="Migration">
<description type="system">
<author>Public Cloud Team</author>
<contact>[email protected]</contact>
<specification>
DMS system next generation, container based
</specification>
</description>
<preferences>
<version>1.0.1</version>
<packagemanager>zypper</packagemanager>
<rpm-excludedocs>true</rpm-excludedocs>
<rpm-check-signatures>false</rpm-check-signatures>
<type image="docker">
<containerconfig name="migration" tag="latest">
<entrypoint execute="/usr/lib/systemd/systemd"/>
</containerconfig>
</type>
</preferences>
<users>
<user password="$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0" home="/root" name="root" groups="root"/>
</users>
<repository type="rpm-md">
<source path="obsrepositories:/"/>
</repository>
<packages type="image">
<package name="patterns-base-minimal_base"/>
<package name="tar"/>
<package name="timezone"/>
<package name="sudo"/>
<package name="vim"/>
<package name="systemd"/>
<package name="procps"/>
<package name="suseconnect-ng"/>
<package name="ifplugd"/>
<package name="iputils"/>
<package name="tar"/>
<package name="parted"/>
<package name="openssh"/>
<package name="iproute2"/>
<package name="less"/>
<package name="bash-completion"/>
<package name="which"/>
<package name="timezone"/>
<package name="bind-utils"/>
<package name="util-linux"/>
<package name="sudo"/>
<!-- SUSE migration services -->
<package name="suse-migration-services"/>
<!-- support for migration of suse public cloud on demand images -->
<package name="cloud-regionsrv-client"/>
<package name="cloud-regionsrv-client-generic-config"/>
<package name="cloud-regionsrv-client-addon-azure"/>
<package name="cloud-regionsrv-client-plugin-azure"/>
<package name="cloud-regionsrv-client-plugin-ec2"/>
<package name="cloud-regionsrv-client-plugin-gce"/>
<package name="python3-gcemetadata"/>
<package name="python3-ec2metadata"/>
<package name="python3-azuremetadata"/>
<package name="haveged"/>
</packages>
<packages type="bootstrap">
<package name="zypper"/>
<package name="gawk"/>
<package name="grep"/>
<package name="gzip"/>
<package name="udev"/>
<package name="xz"/>
<package name="filesystem"/>
<package name="glibc-locale-base"/>
<package name="ca-certificates"/>
<package name="ca-certificates-mozilla"/>
<package name="shadow"/>
</packages>
</image>
29 changes: 29 additions & 0 deletions container/sle15/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -ex

#======================================
# Autologin
#--------------------------------------
mkdir -p /etc/systemd/system/console-getty.service.d
cat >> /etc/systemd/system/console-getty.service.d/override.conf <<- EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud 115200,38400,9600 console linux
EOF

#======================================
# Create host OS shared mount path
#--------------------------------------
mkdir -p /system-root

#======================================
# Activate migration services
#--------------------------------------
for service in \
suse-migration-container.service \
suse-migration-container-prepare.service \
suse-migration-container-product-setup.service \
suse-migration-container-reboot.service
do
systemctl enable "${service}"
done
36 changes: 36 additions & 0 deletions package/suse-migration-services-spec-template
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ Conflicts: suse-migration-sle15-activation < 2.0.33
%description -n suse-migration-pre-checks
Checks to be performed before starting a distribution migration process

%package -n suse-migration
Summary: The migrate tool for a container based upgrade
Group: System/Management
Requires: podman
Requires: sudo
BuildArch: noarch

%description -n suse-migration
The migrate tool to start the migration as container based process

%prep
%setup -q -n suse_migration_services-%{version}

Expand Down Expand Up @@ -112,6 +122,21 @@ install -D -m 644 systemd/suse-migration-prepare.service \
install -D -m 644 systemd/suse-migration.service \
%{buildroot}%{_unitdir}/suse-migration.service

install -D -m 644 systemd/suse-migration-container.service \
%{buildroot}%{_unitdir}/suse-migration-container.service

install -D -m 644 systemd/suse-migration-container-prepare.service \
%{buildroot}%{_unitdir}/suse-migration-container-prepare.service

install -D -m 644 systemd/suse-migration-container-product-setup.service \
%{buildroot}%{_unitdir}/suse-migration-container-product-setup.service

install -D -m 644 systemd/suse-migration-container-reboot.service \
%{buildroot}%{_unitdir}/suse-migration-container-reboot.service

install -D -m 644 systemd/suse-migration-container-emergency.service \
%{buildroot}%{_unitdir}/suse-migration-container-emergency.service

install -D -m 644 systemd/suse-migration-grub-setup.service \
%{buildroot}%{_unitdir}/suse-migration-grub-setup.service

Expand All @@ -136,6 +161,9 @@ install -D -m 644 systemd/suse-migration-ssh-keys.service \
install -D -m 644 systemd/suse-migration-console-log.service \
%{buildroot}%{_unitdir}/suse-migration-console-log.service

install -D -m 755 tools/migrate \
%{buildroot}%{_sbindir}/migrate

# preun / postun
# While the package provides services all services are one-shot.
# Additionally this services runs as part of a live ISO migration
Expand Down Expand Up @@ -163,6 +191,11 @@ install -D -m 644 systemd/suse-migration-console-log.service \
%{_unitdir}/suse-migration-setup-host-network.service
%{_unitdir}/suse-migration-prepare.service
%{_unitdir}/suse-migration.service
%{_unitdir}/suse-migration-container.service
%{_unitdir}/suse-migration-container-prepare.service
%{_unitdir}/suse-migration-container-product-setup.service
%{_unitdir}/suse-migration-container-reboot.service
%{_unitdir}/suse-migration-container-emergency.service
%{_unitdir}/suse-migration-console-log.service
%{_unitdir}/suse-migration-grub-setup.service
%{_unitdir}/suse-migration-update-bootloader.service
Expand All @@ -178,4 +211,7 @@ install -D -m 644 systemd/suse-migration-console-log.service \
%{_bindir}/suse-migration-pre-checks
%{_unitdir}/suse-migration-pre-checks.service

%files -n suse-migration
%{_sbindir}/migrate

%changelog
9 changes: 9 additions & 0 deletions systemd/suse-migration-container-emergency.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Reboot System

[Service]
Type=oneshot
ExecStart=/usr/bin/suse-migration-reboot

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions systemd/suse-migration-container-prepare.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Prepare For Migration
OnFailure=suse-migration-container-emergency.service

[Service]
Type=oneshot
ExecStart=/usr/bin/suse-migration-prepare

[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions systemd/suse-migration-container-product-setup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Prepare Product Setup for Migration
After=suse-migration-container-prepare.service
Requires=suse-migration-container-prepare.service
OnFailure=suse-migration-container-emergency.service

[Service]
Type=oneshot
ExecStart=/usr/bin/suse-migration-product-setup

[Install]
WantedBy=multi-user.target
11 changes: 11 additions & 0 deletions systemd/suse-migration-container-reboot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Reboot System
After=suse-migration-container.service
Requires=suse-migration-container.service

[Service]
Type=oneshot
ExecStart=/usr/bin/suse-migration-reboot

[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions systemd/suse-migration-container.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Run Zypper Migration
After=suse-migration-container-product-setup.service
Requires=suse-migration-container-product-setup.service
OnFailure=suse-migration-container-emergency.service

[Service]
Type=oneshot
ExecStart=/usr/bin/suse-migration

[Install]
WantedBy=multi-user.target
153 changes: 153 additions & 0 deletions tools/migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash
# Copyright (c) 2024 SUSE LLC. All rights reserved.
#
# This file is part of suse-migration-services.
#
# suse-migration-services is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# suse-migration-services is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with suse-migration-services. If not, see <http://www.gnu.org/licenses/>
#
set -e

# TODO: this location needs to be changed to an official place
MIGRATION_SYSTEM=registry.opensuse.org/home/marcus.schaefer/dms/containers_sle15/migration:latest

ARGUMENT_LIST=(
"debug"
"reboot"
"use-zypper-dup"
"product:"
)

# Functions
usage() {
echo "migrate [OPTIONS]"
echo " --product <name>"
echo " Set target product e.g. SLES/15.5/x86_64"
echo " If no product is specified the target is"
echo " the same as the base product setup in the"
echo " migration container"
echo " --use-zypper-dup"
echo " Use zypper dup method instead of the zypper"
echo " migration plugin. NOTE: This requires all"
echo " target repos to be setup before migration !"
echo " An eventually given --product option will be"
echo " ignored"
echo " --reboot"
echo " Reboot after successful upgrade"
echo " --debug"
echo " Run attached to the migration container"
}

migrate() {
set -x
local detach="--detach"
touch /var/log/distro_migration.log
# initialize with a failed state
echo 1 > /var/log/distro_migration.exitcode
if [ "${argDebug}" ];then
echo "Running in debug mode..."
detach=""
fi
# shellcheck disable=SC2086
sudo podman run \
${detach} \
--rm \
-ti \
--name migration \
--privileged \
--net host \
--volume /:/system-root \
--volume /var/log:/var/log \
"${MIGRATION_SYSTEM}"
if [ -z "${argDebug}" ];then
sudo tail -f --retry --pid "$(pidof conmon)" \
/var/log/distro_migration.log
read -r exitcode < /var/log/distro_migration.exitcode
if [ "${exitcode}" != "0" ];then
echo "Migration failed"
exit "${exitcode}"
else
echo "Migration succeeded"
cleanup
fi
echo "Find log file at: /var/log/distro_migration.log"
fi
}

cleanup() {
# reset container storage
sudo rm -rf /var/lib/containers/storage/
}

# Read Arguments
if ! opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "$0")" \
--options "" \
-- "$@"
); then
usage
exit 1
fi

eval set --"${opts}"

while [[ $# -gt 0 ]]; do
case "$1" in
--debug)
argDebug=1
shift
;;

--reboot)
argReboot=1
shift
;;

--use-zypper-dup)
argZypperDup=1
shift
;;

--product)
argProduct=$2
shift 2
;;

*)
break
;;
esac
done

cat > /etc/sle-migration-service.yml <<-EOF
soft_reboot: false
EOF

if [ "${argDebug}" ];then
echo "debug: true" >> /etc/sle-migration-service.yml
fi

if [ "${argProduct}" ];then
echo "migration_product: ${argProduct}" >> /etc/sle-migration-service.yml
fi

if [ "${argZypperDup}" ];then
echo "use_zypper_migration: false" >> /etc/sle-migration-service.yml
fi

migrate

if [ "${argReboot}" ];then
sudo reboot -f
fi

0 comments on commit 5aae674

Please sign in to comment.