From 9faa504140e77140a41dba27aa87dd8acca98c6d Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Wed, 20 Jul 2022 16:27:42 -0400 Subject: [PATCH] Update main (#30) * fix builds for minimal * Add fetch/branch script --- .github/workflows/build.yml | 8 ++- Makefile | 34 +++++----- tools/fetch-and-branch.sh | 120 ++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 tools/fetch-and-branch.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9fbd9f2..1013f18 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,10 @@ jobs: architecture: - x64 - ARM64 + variant: + - Base + - Minimal + - UBI runs-on: - self-hosted - ${{ matrix.architecture }} @@ -25,10 +29,10 @@ jobs: uses: actions/checkout@v2 - name: Build images - run: make + run: make VARIANT=${{ matrix.variant }} - name: Get image name - run: echo "ARTIFACT_NAME=$(make publish)" >> $GITHUB_ENV + run: echo "ARTIFACT_NAME=$(make publish VARIANT=${{ matrix.variant }})" >> $GITHUB_ENV - name: Upload Artifact uses: actions/upload-artifact@v2 diff --git a/Makefile b/Makefile index a29e499..29ea00e 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,34 @@ ARCH = $(shell uname -m) BUILDDATE = $(shell /bin/date +%Y%m%d_%H%M) -KICKSTART_DIR = kickstarts -KICKSTART_PATH = "${KICKSTART_DIR}/Rocky-8-Container.ks" LOG_DIR = logs OUT = out RELEASE_VER = 8.6 MAJOR = $(shell v='$(RELEASE_VER)'; echo "$${v%.*}") TEMPLATE_DIR = templates TEMPLATE_PATH = "${TEMPLATE_DIR}/tdl-${ARCH}.xml" - -OUTNAME := rocky-${RELEASE_VER}-docker -BASEIMAGE_META := base_image-$(OUTNAME).meta -TARGETIMAGE_META := target_image-$(OUTNAME).meta - STORAGEDIR := /var/lib/imagefactory/storage -.PHONY := all clean setup -.DEFAULT_GOAL := $(OUTNAME).tar.xz - -BASEIMAGEUUID = $(shell awk '$$1=="UUID:"{print $$NF}' $(BASEIMAGE_META)) -TARGETIMAGEUUID = $(shell awk '$$1=="UUID:"{print $$NF}' $(TARGETIMAGE_META)) - ifneq ($(DEBUG),) DEBUGPARAM := --debug endif # Basic type is just 'container' -TYPE=container -CONTAINER_NAME = rocky-$(MAJOR)-$(TYPE)-$(RELEASE_VER).$(BUILDDATE).$(ARCH) +TYPE=Container +VARIANT=Base +CONTAINER_NAME = Rocky-$(MAJOR)-$(TYPE)-$(VARIANT)-$(RELEASE_VER).$(BUILDDATE).$(ARCH) + +KICKSTART_DIR = kickstarts +KICKSTART_PATH = "${KICKSTART_DIR}/Rocky-8-${TYPE}-${VARIANT}.ks" + +OUTNAME := rocky-${RELEASE_VER}-${TYPE}-${VARIANT} +BASEIMAGE_META := base_image-$(OUTNAME).meta +TARGETIMAGE_META := target_image-$(OUTNAME).meta +BASEIMAGEUUID = $(shell awk '$$1=="UUID:"{print $$NF}' $(BASEIMAGE_META)) +TARGETIMAGEUUID = $(shell awk '$$1=="UUID:"{print $$NF}' $(TARGETIMAGE_META)) + + +.PHONY := all clean setup +.DEFAULT_GOAL := $(OUTNAME).tar.xz clean: -rm *.meta @@ -36,7 +37,8 @@ publish: @echo $(OUTNAME)-$(ARCH).tar.xz $(KICKSTART_DIR): - git clone --branch r$(MAJOR) --single-branch https://git.rockylinux.org/rocky/kickstarts.git kickstarts + git clone --branch r$(MAJOR) --single-branch https://git.resf.org/sig_core/kickstarts.git kickstarts + sed -i 's/$$basearch/$(ARCH)/g' kickstarts/*.ks $(BASEIMAGE_META): $(KICKSTART_DIR) sudo imagefactory $(DEBUGPARAM) base_image \ diff --git a/tools/fetch-and-branch.sh b/tools/fetch-and-branch.sh new file mode 100644 index 0000000..909b717 --- /dev/null +++ b/tools/fetch-and-branch.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash + +version=${1} +type=${2} +arch=${3} +date=${4:-$(date +%Y%m%d)} +revision=${5:-0} + +major=${1:0:1} +minor=${1:2:1} +TEMPLATE="library-template" + + +usage() { + printf "%s: RELEASE TYPE ARCH [DATE]\n\n" $0 + log "$1" +} + +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) ;; + *) + usage "Invalid type" + exit 1 + ;; +esac + + + +pattern=$(printf "Rocky-%s.%s-%s-%s" "$version" "$date" "$type" "$arch") + +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 +} + +if has-branch $pattern; then + usage "Branch ${pattern} already exists. Exiting." + exit 1 +fi + +log "Creating branch ${pattern}" + +log-cmd git checkout -b "${pattern}" $TEMPLATE + +branch=$(current-branch) +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 update-ref -d HEAD + +builddir=$(latest-build) +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