-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from SUSE/nextgen
DMS - Add Container Workflow Feature
- Loading branch information
Showing
9 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |