Commit: a95b833c
This commit is contained in:
commit
a8d8515b75
71 files changed
+6908
No files matched your search
@@ -0,0 +1,18 @@
|
||||
def intersect(x;y):
|
||||
( (x|unique) + (y|unique) | sort) as $sorted
|
||||
| reduce range(1; $sorted|length) as $i
|
||||
([];
|
||||
if $sorted[$i] == $sorted[$i-1] then . + [$sorted[$i]] else . end) ;
|
||||
|
||||
def difference($a; $b):
|
||||
($a | unique) - $b;
|
||||
|
||||
{
|
||||
cs9: {
|
||||
common: ((intersect($aarch64;$x86_64)) | sort_by(ascii_downcase)),
|
||||
arch: {
|
||||
x86_64: (($x86_64 - $aarch64) | sort_by(ascii_downcase)),
|
||||
aarch64: (($aarch64 - $x86_64) | sort_by(ascii_downcase))
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: MIT-0
|
||||
set -e
|
||||
[ "$DEBUG" == 'true' ] && set -x
|
||||
|
||||
ARGC=$#
|
||||
if [ $ARGC -ne 3 ]; then
|
||||
echo "USAGE: $(basename $0) <Image Path> <S3 Bucket Name> <AMI Image Size in GB>"
|
||||
exit 1
|
||||
fi
|
||||
IMAGE_FILE_PATH=$1
|
||||
IMPORT_BUCKET_NAME=$2
|
||||
AMI_DISK_SIZE_GB=$3
|
||||
|
||||
declare -A ARCHS_MAP=( ["x86_64"]="x86_64" ["aarch64"]="arm64")
|
||||
|
||||
IMAGE_NAME="$(basename -- ${IMAGE_FILE_PATH})"
|
||||
AMI_NAME="${IMAGE_NAME%.*}"
|
||||
IMAGE_ARCH="${AMI_NAME##*.}"
|
||||
|
||||
TMPDIR=$(mktemp -d)
|
||||
IMAGE_IMPORT_JSON_FILE="${TMPDIR}/image-import.json"
|
||||
AMI_REGISTER_JSON_FILE="${TMPDIR}/register-ami.json"
|
||||
|
||||
aws s3 cp "${IMAGE_FILE_PATH}" "s3://${IMPORT_BUCKET_NAME}"
|
||||
|
||||
cat <<EOF > "${IMAGE_IMPORT_JSON_FILE}"
|
||||
{
|
||||
"Description": "CentOS Stream 9 with Container support",
|
||||
"Format": "RAW",
|
||||
"UserBucket": {
|
||||
"S3Bucket": "${IMPORT_BUCKET_NAME}",
|
||||
"S3Key": "${IMAGE_NAME}"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Importing image file into snapshot "
|
||||
IMPORT_TASK_ID=$(aws ec2 import-snapshot --disk-container "file://${IMAGE_IMPORT_JSON_FILE}" | jq -r '.ImportTaskId')
|
||||
|
||||
IMPORT_STATUS=$(aws ec2 describe-import-snapshot-tasks --import-task-ids $IMPORT_TASK_ID | jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail.Status')
|
||||
x=0
|
||||
while [ "$IMPORT_STATUS" = "active" ] && [ $x -lt 120 ]
|
||||
do
|
||||
IMPORT_STATUS=$(aws ec2 describe-import-snapshot-tasks --import-task-ids $IMPORT_TASK_ID | jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail.Status')
|
||||
IMPORT_STATUS_MSG=$(aws ec2 describe-import-snapshot-tasks --import-task-ids $IMPORT_TASK_ID | jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail.StatusMessage')
|
||||
echo "Import Status: ${IMPORT_STATUS} / ${IMPORT_STATUS_MSG}"
|
||||
x=$(( $x + 1 ))
|
||||
sleep 15
|
||||
done
|
||||
if [ $x -eq 120 ]; then
|
||||
echo "ERROR: Import task taking too long, exiting..."; exit 1;
|
||||
elif [ "$IMPORT_STATUS" = "completed" ]; then
|
||||
echo "Import completed Successfully"
|
||||
else
|
||||
echo "Import Failed, exiting"; exit 2;
|
||||
fi
|
||||
|
||||
SNAPSHOT_ID=$(aws ec2 describe-import-snapshot-tasks --import-task-ids $IMPORT_TASK_ID | jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail.SnapshotId')
|
||||
|
||||
aws ec2 wait snapshot-completed --snapshot-ids $SNAPSHOT_ID
|
||||
|
||||
|
||||
echo "Registering AMI with Snapshot $SNAPSHOT_ID"
|
||||
cat <<EOF > "${AMI_REGISTER_JSON_FILE}"
|
||||
{
|
||||
"Architecture": "${ARCHS_MAP[$IMAGE_ARCH]}",
|
||||
"BlockDeviceMappings": [
|
||||
{
|
||||
"DeviceName": "/dev/sda1",
|
||||
"Ebs": {
|
||||
"DeleteOnTermination": true,
|
||||
"SnapshotId": "${SNAPSHOT_ID}",
|
||||
"VolumeSize": ${AMI_DISK_SIZE_GB},
|
||||
"VolumeType": "gp2"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Description": "CS9 image with container support for ${IMAGE_ARCH}",
|
||||
"RootDeviceName": "/dev/sda1",
|
||||
"BootMode": "uefi",
|
||||
"VirtualizationType": "hvm",
|
||||
"EnaSupport": true
|
||||
}
|
||||
EOF
|
||||
|
||||
aws ec2 register-image --name ${AMI_NAME} --cli-input-json="file://${AMI_REGISTER_JSON_FILE}"
|
||||
echo "AMI name: "${AMI_NAME}
|
||||
@@ -0,0 +1,19 @@
|
||||
def basenames:
|
||||
.path | split("/") | last;
|
||||
|
||||
def parseURL:
|
||||
capture("^((?<scheme>[^:/?#]+):)?(//(?<authority>(?<domain>[^/?#:]*)(:(?<port>[0-9]*))?))?(?<path>[^?#]*)(\\?(?<query>([^#]*)))?(#(?<fragment>(.*)))?");
|
||||
|
||||
def splitRPM:
|
||||
capture("(?<name>(.*))\\.(?<arch>[a-zA-Z0-9_]+).rpm");
|
||||
|
||||
def manifestUrls:
|
||||
.sources["org.osbuild.curl"].items | to_entries[] | .value | parseURL;
|
||||
|
||||
def urlsToRpms:
|
||||
basenames | splitRPM;
|
||||
|
||||
def mergeArches:
|
||||
reduce .[] as $item ({}; .[$item.arch][$item.name] = true) | with_entries(.value = (.value | keys));
|
||||
|
||||
manifestUrls | select(.domain == "mirror.stream.centos.org") | urlsToRpms | .name
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Generates single-file from-scratch and delta update files for all or some of the
|
||||
# refs in an OSTree repo.
|
||||
#
|
||||
# To use it run "generate-deltas REPODIR DESTDIR" which will look at all the refs in the
|
||||
# repo and make updates to the latest version putting them in the DESTDIR directory.
|
||||
|
||||
# To apply these on a live system, do something like:
|
||||
# $ ostree static-delta apply-offline cs9-x86_64-qemu-upgrade-demo-79da0b2f1b119e99137eaef9680fae9820a9edcd5cac4f6d7c23279498c578f6.update
|
||||
# $ rpm-ostree rebase 79da0b2f1b119e99137eaef9680fae9820a9edcd5cac4f6d7c23279498c578f6
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
echo "Usage generate-deltas REPODIR DESTDIR [REFS..]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REPO=$1
|
||||
DIR=$2
|
||||
|
||||
shift 2
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
REFS="$@"
|
||||
else
|
||||
REFS=$(ostree --repo=$REPO refs)
|
||||
fi
|
||||
|
||||
mkdir -p $DIR
|
||||
|
||||
NUM_DELTAS=3
|
||||
for REF in $REFS; do
|
||||
REF_AS_FILE=$(echo $REF | sed "s%/%-%g" )
|
||||
HEAD=$(ostree --repo=$REPO rev-parse $REF)
|
||||
|
||||
# Generate full update for HEAD:
|
||||
echo Generating non-delta update for $REF commit $HEAD
|
||||
ostree static-delta generate --repo=$REPO --inline --min-fallback-size=0 --empty --filename=$DIR/$REF_AS_FILE-$HEAD.update $HEAD
|
||||
|
||||
# Generate deltas to HEAD from up to the last 3 parents
|
||||
PARENT=$HEAD
|
||||
for i in seq $NUM_DELTAS; do
|
||||
if ! PARENT=$(ostree --repo=$REPO rev-parse $PARENT^ 2>/dev/null); then
|
||||
break;
|
||||
fi
|
||||
echo Generating delta update for $REF commit $HEAD from commit $PARENT
|
||||
ostree static-delta generate --repo=$REPO --inline --min-fallback-size=0 --from=$PARENT --filename=$DIR/$REF_AS_FILE-$PARENT-$HEAD.update $HEAD
|
||||
done
|
||||
|
||||
done
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is a helper used by the makefile to handle the OSTREE_REPO mpp
|
||||
# support. It creates a json dict mapping all the refs in the repo
|
||||
# (if it exists) to the latest commit. This is then passed to osbuild-mpp
|
||||
# as the ostree_parent_refs variable that is used by the manifests to pick
|
||||
# the right parent commit.
|
||||
|
||||
REPOPATH=$1
|
||||
FIRST=1
|
||||
echo -n "{"
|
||||
if test -d $REPOPATH; then
|
||||
for ref in $(ostree refs --repo=$REPOPATH); do
|
||||
if [ $FIRST == 1 ]; then
|
||||
FIRST=0
|
||||
else
|
||||
echo -n ,
|
||||
fi
|
||||
echo -n \"$ref\":\"$(ostree rev-parse --repo=$REPOPATH $ref)\"
|
||||
done
|
||||
fi
|
||||
echo -n "}"
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is a helper for the makefile rule to build a particular image
|
||||
# from the preprocessed json manifest. It is a shellscript rather
|
||||
# than just some make lines because some of the complexities just
|
||||
# are painful to do in make.
|
||||
#
|
||||
# Features:
|
||||
#
|
||||
# * Knows what target to export based on the extensions.
|
||||
# * Knows what the exported filename based on the extensions.
|
||||
# * Supports building natively or in a VM via osbuildvm.
|
||||
# * Runs only the minimal required commands as root, and
|
||||
# chowns the resulting files to the user
|
||||
# * Supports exporting an extra ostree commit and pulling that
|
||||
# into an existing repo.
|
||||
|
||||
set -e
|
||||
|
||||
DEST="$1"
|
||||
JSON="$2"
|
||||
TARGET="$3"
|
||||
IMAGETYPE="$4"
|
||||
ARCH="$5"
|
||||
EXTENSION="$6"
|
||||
|
||||
# Map extension => export pipeline name
|
||||
declare -A EXPORT_BY_EXT
|
||||
EXPORT_BY_EXT[img]=image
|
||||
EXPORT_BY_EXT[oci.tar]=container
|
||||
EXPORT_BY_EXT[qcow2]=qcow2
|
||||
EXPORT_BY_EXT[repo]=ostree-commit
|
||||
EXPORT_BY_EXT[rootfs]=rootfs
|
||||
EXPORT_BY_EXT[ext4]=ext4
|
||||
EXPORT_BY_EXT[tar]=tar
|
||||
|
||||
# Map extension to name of exported file by pipeline
|
||||
declare -A EXPORT_FILE_BY_EXT
|
||||
EXPORT_FILE_BY_EXT[img]=disk.img
|
||||
EXPORT_FILE_BY_EXT[qcow2]=disk.qcow2
|
||||
EXPORT_FILE_BY_EXT[oci.tar]=container.tar
|
||||
EXPORT_FILE_BY_EXT[repo]=repo
|
||||
EXPORT_FILE_BY_EXT[rootfs]=
|
||||
EXPORT_FILE_BY_EXT[ext4]=rootfs.ext4
|
||||
EXPORT_FILE_BY_EXT[tar]=rootfs.tar
|
||||
|
||||
EXPORT=${EXPORT_BY_EXT[${EXTENSION}]}
|
||||
EXPORT_FILE=${EXPORT_FILE_BY_EXT[${EXTENSION}]}
|
||||
|
||||
HOST_ARCH=$(arch)
|
||||
CURRENT_UIDGID="$(id -u):$(id -g)"
|
||||
|
||||
if [ $ARCH == $HOST_ARCH -a $VM == 0 ]; then
|
||||
SUDO="sudo"
|
||||
OSBUILD="sudo osbuild"
|
||||
else
|
||||
SUDO=
|
||||
OSBUILD="osbuildvm/osbuildvm --arch=$ARCH"
|
||||
fi
|
||||
|
||||
EXPORT_ARGS="--export $EXPORT"
|
||||
|
||||
CHECKPOINT_ARGS=
|
||||
for CP in $CHECKPOINTS; do
|
||||
CHECKPOINT_ARGS="${CHECKPOINT_ARGS} --checkpoint ${CP}"
|
||||
done
|
||||
|
||||
CHOWNARGS=
|
||||
if [ $EXTENSION == repo ]; then
|
||||
CHOWNARGS=-R # Chown entire repo dir as it doesn't care about permissions
|
||||
fi
|
||||
|
||||
EXPORTDIRS=$OUTPUTDIR/$EXPORT
|
||||
|
||||
# If OSTREE_REPO is set, and we're building an image that has an
|
||||
# ostree commit, then we also export that commit to the repo specified
|
||||
# by OSTREE_REPO.
|
||||
ALSO_EXPORT_OSTREE=0
|
||||
if [ "$OSTREE_REPO" != "" -a "$IMAGETYPE" == "ostree" ]; then
|
||||
ALSO_EXPORT_OSTREE=1
|
||||
if [ $EXPORT != "ostree-commit" ]; then
|
||||
EXPORT_ARGS="$EXPORT_ARGS --export ostree-commit"
|
||||
EXPORTDIRS="$EXPORTDIRS $OUTPUTDIR/ostree-commit"
|
||||
fi
|
||||
|
||||
# Ensure we have a repo to export to
|
||||
ostree init --repo=$OSTREE_REPO --mode archive
|
||||
fi
|
||||
|
||||
set -x
|
||||
|
||||
$SUDO rm -rf $EXPORTDIRS
|
||||
mkdir -p $EXPORTDIRS # Own export dirs by user, not root
|
||||
|
||||
$OSBUILD $CHECKPOINT_ARGS --store $STOREDIR --output-directory $OUTPUTDIR $EXPORT_ARGS $OSBUILD_ARGS $JSON
|
||||
|
||||
if [ $ALSO_EXPORT_OSTREE == "1" ]; then
|
||||
ostree pull-local --repo=$OSTREE_REPO $OUTPUTDIR/ostree-commit/repo
|
||||
fi
|
||||
|
||||
# Extract and chown exported file
|
||||
rm -rf $DEST
|
||||
$SUDO chown $CHOWNARGS $CURRENT_UIDGID $OUTPUTDIR/$EXPORT/$EXPORT_FILE
|
||||
$SUDO mv $OUTPUTDIR/$EXPORT/$EXPORT_FILE $DEST
|
||||
|
||||
$SUDO rm -rf $EXPORTDIRS
|
||||
Reference in new issue
Block a user