refactor tools and add script to generate official-images configs
This commit is contained in:
parent
8d5a54d156
commit
f9d109b6ff
|
@ -0,0 +1,75 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
log() {
|
||||||
|
printf "[%s] :: %s\n" "$(date -Isec)" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
log-cmd() {
|
||||||
|
set -x
|
||||||
|
command $@
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -z "$version" || ! "$version" =~ [0-9]+.[0-9]+ ]]; then
|
||||||
|
usage "Invalid or empty version"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$type" in
|
||||||
|
Base|Minimal|UBI) ;;
|
||||||
|
*)
|
||||||
|
usage "Invalid type"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
has-branch(){
|
||||||
|
local res=$(log-cmd git branch --list "$1")
|
||||||
|
if [[ -z $res ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
current-branch() {
|
||||||
|
local res=$(log-cmd git branch --show-current)
|
||||||
|
ret=0
|
||||||
|
if [[ ! -z $res ]]; then
|
||||||
|
ret=1
|
||||||
|
fi
|
||||||
|
echo $res
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
generate-packagelist() {
|
||||||
|
log "Generating package list"
|
||||||
|
if [[ -f build.meta ]]; then
|
||||||
|
log-cmd xmllint --xpath "//packages/*/@name" <(printf "$(jq '.icicle' < build.meta)\n" | tr -d '\\' | tail -c +2 | head -c -2) | \
|
||||||
|
awk -F\= '{print substr($2,2,length($2)-2)}' | \
|
||||||
|
sort > packages.txt
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
log "No build.meta found. Skipping packagelist generation"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
generate-filelist() {
|
||||||
|
log "Generating filelist"
|
||||||
|
if [[ -f layer.tar.xz ]]; then
|
||||||
|
log-cmd tar -tf layer.tar.xz > filelist.txt
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
log "No layer.tar.xz found. Skipping filelist generation"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
latest-build() {
|
||||||
|
local path=$(printf "s3://resf-empanadas/buildimage-%s-%s/Rocky-%s-Container-%s-%s-%s.%s.%s" $version $arch $major $type $version $date $revision $arch)
|
||||||
|
local res=$(log-cmd aws --region us-east-2 --profile resf-peridot-prod s3 ls --recursive "$path" | sort | tail -1 | awk '{print $4}' | sed 's,^\(.*\)/.*$,\1,g')
|
||||||
|
echo "$res"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern=$(printf "Rocky-%s.%s-%s-%s" "$version" "$date" "$type" "$arch")
|
||||||
|
manifest_tag="$(printf "localhost/rocky/%s/%s/%s:latest" $version $date $type)"
|
||||||
|
manifest_tag="${manifest_tag,,}" # convert to lowercase
|
|
@ -10,123 +10,109 @@ major=${1:0:1}
|
||||||
minor=${1:2:1}
|
minor=${1:2:1}
|
||||||
TEMPLATE="library-template"
|
TEMPLATE="library-template"
|
||||||
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "%s: RELEASE TYPE ARCH [DATE]\n\n" $0
|
printf "%s: RELEASE TYPE ARCH [DATE]\n\n" $0
|
||||||
log "$1"
|
log "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
# shellcheck disable=SC2046,1091,1090
|
||||||
printf "[%s] :: %s\n" "$(date -Isec)" "$1"
|
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
|
||||||
}
|
|
||||||
|
|
||||||
log-cmd() {
|
|
||||||
set -x
|
|
||||||
command $@
|
|
||||||
set +x
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ -z "$version" || ! "$version" =~ [0-9]+.[0-9]+ ]]; then
|
|
||||||
usage "Invalid or empty version"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$type" in
|
|
||||||
Base|Minimal|UBI) ;;
|
|
||||||
*)
|
|
||||||
usage "Invalid type"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
has-branch(){
|
|
||||||
local res=$(log-cmd git branch --list "$1")
|
|
||||||
if [[ -z $res ]]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
current-branch() {
|
|
||||||
local res=$(log-cmd git branch --show-current)
|
|
||||||
ret=0
|
|
||||||
if [[ ! -z $res ]]; then
|
|
||||||
ret=1
|
|
||||||
fi
|
|
||||||
echo $res
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
generate-packagelist() {
|
|
||||||
log "Generating package list"
|
|
||||||
if [[ -f build.meta ]]; then
|
|
||||||
log-cmd xmllint --xpath "//packages/*/@name" <(printf "$(jq '.icicle' < build.meta)\n" | tr -d '\\' | tail -c +2 | head -c -2) | \
|
|
||||||
awk -F\= '{print substr($2,2,length($2)-2)}' | \
|
|
||||||
sort > packages.txt
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
log "No build.meta found. Skipping packagelist generation"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
generate-filelist() {
|
|
||||||
log "Generating filelist"
|
|
||||||
if [[ -f layer.tar.xz ]]; then
|
|
||||||
log-cmd tar -tf layer.tar.xz > filelist.txt
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
log "No layer.tar.xz found. Skipping filelist generation"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
latest-build() {
|
|
||||||
local path=$(printf "s3://resf-empanadas/buildimage-%s-%s/Rocky-%s-Container-%s-%s-%s.%s.%s" $version $arch $major $type $version $date $revision $arch)
|
|
||||||
local res=$(log-cmd aws --region us-east-2 --profile resf-peridot-prod s3 ls --recursive "$path" | sort | tail -1 | awk '{print $4}' | sed 's,^\(.*\)/.*$,\1,g')
|
|
||||||
echo "$res"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
build-container-manifests() {
|
build-container-manifests() {
|
||||||
local destinations=("docker.io/rockylinux/rockylinux" "quay.io/rockylinux/rockylinux")
|
|
||||||
local tags=("$version" "${version}.${date}")
|
case "$arch" in
|
||||||
local final_tags=""
|
x86_64)
|
||||||
for d in "${destinations[@]}"; do
|
build_args="--os linux --arch amd64 " ;;
|
||||||
for t in "${tags[@]}"; do
|
aarch64)
|
||||||
final_tags="$(printf '%s,%s:%s' $d $t)"
|
build_args="--os linux --arch arm64 --variant v8" ;;
|
||||||
done
|
*) echo "invalid arch"; exit;;
|
||||||
done
|
esac
|
||||||
echo $final_tags
|
|
||||||
|
# don't bother tagging the intermediary container as we will just capture its shasum
|
||||||
|
container_shasum=$(podman build -q $build_args .)
|
||||||
|
pRes=$?
|
||||||
|
if [[ $pRes -gt 0 ]]; then
|
||||||
|
echo "failed to build container. exiting"
|
||||||
|
exit $pRes
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Manifest tags need one per type (base/minimal/etc), and contain two architectures (for 8, 9 will ultimately have 4+)
|
||||||
|
if ! podman manifest exists "$manifest_tag"; then
|
||||||
|
podman manifest create "$manifest_tag"
|
||||||
|
pRes=$?
|
||||||
|
if [[ $pRes -gt 0 ]]; then
|
||||||
|
echo "Failed to create manifest"
|
||||||
|
exit $pRes
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "manifest exists. adding will overwrite existing platform tuple in manifest, if exists."
|
||||||
|
fi
|
||||||
|
|
||||||
|
podman manifest add $manifest_tag containers-storage:$container_shasum $build_args
|
||||||
|
pRes=$?
|
||||||
|
if [[ $pRes -gt 0 ]]; then
|
||||||
|
echo "Failed to add container image to manifest"
|
||||||
|
exit $pRes
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "when all images have been added to the manifest, the manifests must be pushed to their locations."
|
||||||
|
echo "***Only push the bar MAJOR version tag (8,9) when the OS has been fully released.***"
|
||||||
|
echo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern=$(printf "Rocky-%s.%s-%s-%s" "$version" "$date" "$type" "$arch")
|
manifest-push-commands (){
|
||||||
|
local destinations=("docker.io/rockylinux/rockylinux" "quay.io/rockylinux/rockylinux")
|
||||||
|
local tags=("$version" "${version}.${date}")
|
||||||
|
local final_tags=()
|
||||||
|
for d in "${destinations[@]}"; do
|
||||||
|
for t in "${tags[@]}"; do
|
||||||
|
final_tags=(${final_tags[@]} "$d:$t")
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
if has-branch $pattern; then
|
for t in "${final_tags[@]}"; do
|
||||||
usage "Branch ${pattern} already exists. Exiting."
|
printf "podman manifest push %s %s\n" $manifest_tag $t
|
||||||
exit 1
|
done
|
||||||
fi
|
}
|
||||||
|
|
||||||
log "Creating branch ${pattern}"
|
|
||||||
|
|
||||||
log-cmd git checkout -b "${pattern}" $TEMPLATE
|
check-and-download (){
|
||||||
|
if has-branch $pattern; then
|
||||||
|
usage "Branch ${pattern} already exists. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
branch=$(current-branch)
|
log "Creating branch ${pattern}"
|
||||||
if [[ "${branch}" != "${pattern}" ]]; then
|
|
||||||
log "Not on the proper branch after creation. Exiting for safety."
|
|
||||||
exit 127
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clear the history of the branch (Required for Docker Hub Official Images to only have one commit on the branch)
|
log-cmd git checkout -b "${pattern}" $TEMPLATE
|
||||||
log-cmd git update-ref -d HEAD
|
|
||||||
|
|
||||||
builddir=$(latest-build)
|
branch=$(current-branch)
|
||||||
if [[ -z "$builddir" ]]; then
|
if [[ "${branch}" != "${pattern}" ]]; then
|
||||||
log "Builddir not found. Exiting"
|
log "Not on the proper branch after creation. Exiting for safety."
|
||||||
exit 3
|
exit 127
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log-cmd aws --region us-east-2 --profile resf-peridot-prod s3 sync "s3://resf-empanadas/$builddir" $PWD
|
# Clear the history of the branch (Required for Docker Hub Official Images to only have one commit on the branch)
|
||||||
|
log-cmd git update-ref -d HEAD
|
||||||
|
|
||||||
generate-packagelist
|
builddir=$(latest-build)
|
||||||
generate-filelist
|
if [[ -z "$builddir" ]]; then
|
||||||
|
log "Builddir not found. Exiting"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
log-cmd aws --region us-east-2 --profile resf-peridot-prod s3 sync "s3://resf-empanadas/$builddir" $PWD
|
||||||
|
|
||||||
|
generate-packagelist
|
||||||
|
generate-filelist
|
||||||
|
}
|
||||||
|
|
||||||
|
check-and-download
|
||||||
build-container-manifests
|
build-container-manifests
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -S -m "Rocky Linux Container Image - $branch"
|
||||||
|
|
||||||
|
manifest-push-commands
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
version=${1}
|
||||||
|
type=${2}
|
||||||
|
date=${3:-$(date +%Y%m%d)}
|
||||||
|
revision=${4:-0}
|
||||||
|
|
||||||
|
major=${1:0:1}
|
||||||
|
minor=${1:2:1}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
printf "%s: RELEASE TYPE [DATE]\n\n" $0
|
||||||
|
log "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2046,1091,1090
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
|
||||||
|
|
||||||
|
|
||||||
|
# find branches LIKE pattern
|
||||||
|
# generate template
|
||||||
|
name="Rocky-${version}.${date}-${type}"
|
||||||
|
|
||||||
|
arches=(x86_64 aarch64)
|
||||||
|
if [[ $major -ge 9 ]]; then
|
||||||
|
arches=(${arches[@]} s390x ppc64le)
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $type in
|
||||||
|
UBI|Minimal)
|
||||||
|
suffix="-${type,,}" ;;
|
||||||
|
*)
|
||||||
|
suffix='';;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
declare -A shasums
|
||||||
|
|
||||||
|
for a in "${arches[@]}"; do
|
||||||
|
pt="${name}-${a}"
|
||||||
|
if has-branch $pt; then
|
||||||
|
shasums[$a]="$(git rev-parse $pt)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
Tags: ${version}.${date}${suffix}, ${major}${suffix}, ${version}${suffix}
|
||||||
|
GitFetch: refs/heads/${name}-x86_64
|
||||||
|
GitCommit: ${shasums[x86_64]}
|
||||||
|
arm64v8-GitFetch: refs/heads/${name}-aarch64
|
||||||
|
arm64v8-GitCommit: ${shasums[aarch64]}
|
||||||
|
Architectures: amd64, arm64v8
|
||||||
|
EOF
|
||||||
|
|
Loading…
Reference in New Issue