makedist-docker: new component to push rootfs images to docker hub

This commit is contained in:
Silvan Calarco 2024-04-13 17:05:13 +02:00
parent ffec557d60
commit 90c809f459
3 changed files with 114 additions and 3 deletions

View File

@ -69,7 +69,7 @@ clean:
install: install-locales install: install-locales
@install -d $(DESTDIR)$(datadir);\ @install -d $(DESTDIR)$(datadir);\
cp -a makedist $(DESTDIR)$(datadir)/;\ cp -a makedist $(DESTDIR)$(datadir)/;\
install -d $(DESTDIR)$(sysconfdir)/makedist;\ install -d -m0600 $(DESTDIR)$(sysconfdir)/makedist;\
cp -a config/config $(DESTDIR)$(sysconfdir)/makedist/config;\ cp -a config/config $(DESTDIR)$(sysconfdir)/makedist/config;\
install -d $(DESTDIR)$(sysconfdir)/sysconfig;\ install -d $(DESTDIR)$(sysconfdir)/sysconfig;\
cp -a config/makedist $(DESTDIR)$(sysconfdir)/sysconfig/makedist;\ cp -a config/makedist $(DESTDIR)$(sysconfdir)/sysconfig/makedist;\

107
bin/makedist-docker Executable file
View File

@ -0,0 +1,107 @@
#!/bin/bash
# makedist-docker - push rootfs images to docker hub
# Copyright (c) 2024 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
makedist_me="${0##*/}"
copyleft="\
makedist-docker - push rootfs images to docker hub
Copyright (c) 2024 by Silvan Calarco <silvan.calarco@mambasoft.it>
"
echo "$copyleft"
function usage() {
echo "\
usage: $makedist_me target language
Example:
$makedist_me rootfs-base en
" >&2
}
TARGET=$1
LANGUAGE=$2
[ "${TARGET}" -a "${LANGUAGE}" ] || {
usage
exit 1
}
. /etc/sysconfig/makedist
BASEDIR=${REPODIR_LOCAL}/media/rolling/${TARGET}/${LANGUAGE}
[ "${DOCKER_USER}" -a "${DOCKER_TOKEN}" ] || {
echo "ERROR: missing docker credentials; exiting."
exit 1
}
[ "${DOCKER_REPOSITORY}" ] || {
echo "ERROR: missing DOCKER_REPOSITORY declaration; exiting."
exit 1
}
create_and_push_manifest() {
local MANIFEST_TAG="$1"
local MANIFESTS_LIST="$2"
local SNAPSHOT_VERSION="$3"
local PLATFORM
docker manifest rm ${MANIFEST_TAG}
docker manifest create ${MANIFEST_TAG} ${MANIFESTS_LIST}
for ARCH in x86_64 aarch64 i586; do
if [ "${ARCH}" == "aarch64" ]; then
PLATFORM="arm64"
elif [ "${ARCH}" == "x86_64" ]; then
PLATFORM="amd64"
elif [ "${ARCH}" == "i586" ]; then
PLATFORM="386"
fi
docker manifest annotate ${MANIFEST_TAG} \
${DOCKER_REPOSITORY}:snapshot-${SNAPSHOT_VERSION}-${ARCH} \
--os linux --arch ${PLATFORM}
done
echo "Pushing manifest with tag ${MANIFEST_TAG}..."
docker manifest push ${MANIFEST_TAG}
}
docker login -u ${DOCKER_USER} -p ${DOCKER_TOKEN}
MANIFESTS_LIST=""
for ARCH in x86_64 aarch64 i586; do
if [ "${ARCH}" == "aarch64" ]; then
PLATFORM="linux/arm64"
elif [ "${ARCH}" == "x86_64" ]; then
PLATFORM="linux/amd64"
elif [ "${ARCH}" == "i586" ]; then
PLATFORM="linux/386"
fi
ROOTFS_ARCHIVE=`readlink -f ${BASEDIR}/openmamba-${TARGET}-${LANGUAGE}-snapshot.${ARCH}.tar.xz`
SNAPSHOT_VERSION=`echo ${ROOTFS_ARCHIVE} | sed "s|.*snapshot-\([0-9]*\).*|\1|"`
if [ "$SNAPSHOT_VERSION" == "" ]; then
echo "ERROR: unable to find snapshot version from ${ROOTFS_ARCHIVE}; skipping ${ARCH}..."
continue
fi
IMAGE_TAG="snapshot-${SNAPSHOT_VERSION}-${ARCH}"
if [ -z "$(docker images -q ${DOCKER_REPOSITORY}:${IMAGE_TAG} 2>/dev/null)" ]; then
echo "Importing `basename ${ROOTFS_ARCHIVE}` (arch:${ARCH};version:${SNAPSHOT_VERSION})..."
xzcat ${ROOTFS_ARCHIVE} | docker import --platform ${PLATFORM} - ${DOCKER_REPOSITORY}:${IMAGE_TAG} || exit 1
else
echo "Image ${DOCKER_REPOSITORY}:${IMAGE_TAG} already exists locally"
fi
docker push ${DOCKER_REPOSITORY}:snapshot-${SNAPSHOT_VERSION}-${ARCH}
MANIFESTS_LIST="${MANIFESTS_LIST} ${DOCKER_REPOSITORY}:snapshot-${SNAPSHOT_VERSION}-${ARCH}"
done
# Prepare multiplatform manifest
create_and_push_manifest ${DOCKER_REPOSITORY}:snapshot-${SNAPSHOT_VERSION} "${MANIFESTS_LIST}" ${SNAPSHOT_VERSION}
create_and_push_manifest ${DOCKER_REPOSITORY}:latest "${MANIFESTS_LIST}" ${SNAPSHOT_VERSION}

View File

@ -8,6 +8,10 @@ MILESTONES="milestone3 milestone2 devel"
PROJECTURL=https://openmamba.org PROJECTURL=https://openmamba.org
#TORRENTURL=http://torrent.mambasoft.it:8080/announce #TORRENTURL=http://torrent.mambasoft.it:8080/announce
DOCKER_USER=""
DOCKER_TOKEN=""
DOCKER_REPOSITORY="openmamba/openmamba"
# list of supported languages # list of supported languages
# #
HTML_LANGS="it en" HTML_LANGS="it en"
@ -85,7 +89,7 @@ else
# MEDIA_SUBPLATFORM[3]= # MEDIA_SUBPLATFORM[3]=
# MEDIA_VARIANT[3]= # MEDIA_VARIANT[3]=
# MEDIA_LANGUAGES[3]="it en" # MEDIA_LANGUAGES[3]="it en"
# MEDIA_ARCHS[3]="arm aarch64 i586 x86_64" # MEDIA_ARCHS[3]="aarch64 i586 x86_64"
# MEDIA_MONTHDAY[3]=25 # MEDIA_MONTHDAY[3]=25
# MEDIA_MILESTONE[4]=devel # MEDIA_MILESTONE[4]=devel
@ -95,7 +99,7 @@ else
# MEDIA_SUBPLATFORM[4]= # MEDIA_SUBPLATFORM[4]=
# MEDIA_VARIANT[4]= # MEDIA_VARIANT[4]=
# MEDIA_LANGUAGES[4]="it en" # MEDIA_LANGUAGES[4]="it en"
# MEDIA_ARCHS[4]="arm aarch64 i586 x86_64" # MEDIA_ARCHS[4]="aarch64 i586 x86_64"
# MEDIA_MONTHDAY[4]=20 # MEDIA_MONTHDAY[4]=20
fi fi