From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1202796-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id E93D4138359
	for <garchives@archives.gentoo.org>; Fri,  4 Sep 2020 14:49:05 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id DB04BE085A;
	Fri,  4 Sep 2020 14:49:04 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 9471BE085A
	for <gentoo-commits@lists.gentoo.org>; Fri,  4 Sep 2020 14:49:04 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 51CD133BECB
	for <gentoo-commits@lists.gentoo.org>; Fri,  4 Sep 2020 14:49:03 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 00B9833B
	for <gentoo-commits@lists.gentoo.org>; Fri,  4 Sep 2020 14:49:02 +0000 (UTC)
From: "Alexys Jacob" <ultrabug@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Alexys Jacob" <ultrabug@gentoo.org>
Message-ID: <1599230935.8c87ce7de4d696ce595bf497aee42c8b80d8bd9f.ultrabug@gentoo>
Subject: [gentoo-commits] proj/docker-images:master commit in: /
X-VCS-Repository: proj/docker-images
X-VCS-Files: .travis.yml build.sh deploy.sh
X-VCS-Directories: /
X-VCS-Committer: ultrabug
X-VCS-Committer-Name: Alexys Jacob
X-VCS-Revision: 8c87ce7de4d696ce595bf497aee42c8b80d8bd9f
X-VCS-Branch: master
Date: Fri,  4 Sep 2020 14:49:02 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: d6b0871f-b557-4201-ad52-d0c36561df19
X-Archives-Hash: fb31dd87974a4dcc469d7ada1ffb3f9a

commit:     8c87ce7de4d696ce595bf497aee42c8b80d8bd9f
Author:     Konstantinos Smanis <konstantinos.smanis <AT> gmail <DOT> com>
AuthorDate: Mon Aug 31 17:25:13 2020 +0000
Commit:     Alexys Jacob <ultrabug <AT> gentoo <DOT> org>
CommitDate: Fri Sep  4 14:48:55 2020 +0000
URL:        https://gitweb.gentoo.org/proj/docker-images.git/commit/?id=8c87ce7d

Deploy manifest lists along with per-arch images

Signed-off-by: Konstantinos Smanis <konstantinos.smanis <AT> gmail.com>
Signed-off-by: Alexys Jacob <ultrabug <AT> gentoo.org>

 .travis.yml | 16 ++++++++--------
 build.sh    |  1 -
 deploy.sh   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 7661939..754b3d7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,7 +5,7 @@ env:
     - ORG=gentoo
   jobs:
     - TARGET=portage
-    - TARGET=stage3-amd64 LATEST=true
+    - TARGET=stage3-amd64
     - TARGET=stage3-amd64-hardened
     - TARGET=stage3-amd64-hardened-nomultilib
     - TARGET=stage3-amd64-musl-hardened
@@ -55,10 +55,10 @@ after_success:
       fi
       docker run --rm "${ORG}/${TARGET/-/:}" emerge --info
     fi
-  # Push all built images to Docker Hub (cron daily task)
-  - |
-    if [[ "${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}" == "master" && "${TRAVIS_EVENT_TYPE}" == "cron" ]]; then
-      echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
-      REPO="$(cut -d '-' -f 1 <<< ${TARGET})"
-      docker push "${ORG}/${REPO}"
-    fi
+deploy:
+  # Push to Docker Hub (daily cron job)
+  - provider: script
+    script: ./deploy.sh
+    on:
+      branch: master
+      condition: $TRAVIS_EVENT_TYPE = cron

diff --git a/build.sh b/build.sh
index 5fe7411..c3979a3 100755
--- a/build.sh
+++ b/build.sh
@@ -69,7 +69,6 @@ docker buildx build \
 	--build-arg SUFFIX="${SUFFIX}" \
 	--tag "${ORG}/${TARGET/-/:}" \
 	--tag "${ORG}/${TARGET/-/:}${VERSION_SUFFIX}" \
-	${LATEST:+--tag "${ORG}/${NAME}:latest"} \
 	--platform "linux/${DOCKER_ARCH}" \
 	--progress plain \
 	--load \

diff --git a/deploy.sh b/deploy.sh
new file mode 100755
index 0000000..b27d5ab
--- /dev/null
+++ b/deploy.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+if [[ -z "$TARGET" ]]; then
+	echo "TARGET environment variable must be set e.g. TARGET=stage3-amd64."
+	exit 1
+fi
+
+# Split the TARGET variable into three elements separated by hyphens
+IFS=- read -r NAME ARCH SUFFIX <<< "${TARGET}"
+
+# Push built images
+echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
+docker push "${ORG}/${NAME}"
+
+if [[ "${TARGET}" != stage* ]]; then
+	echo "Done! No manifests to push for TARGET=${TARGET}."
+	exit 0
+fi
+
+VERSION=${VERSION:-$(date -u +%Y%m%d)}
+
+declare -A MANIFEST_ARCHES=(
+	[stage3:latest]="amd64;arm64;armv5tel;armv6j_hardfp;armv7a_hardfp;ppc64le;s390x;x86"
+	[stage3:hardened]="amd64;x86"
+	[stage3:hardened-nomultilib]="amd64"
+	[stage3:musl-hardened]="amd64"
+	[stage3:musl-vanilla]="amd64;x86"
+	[stage3:nomultilib]="amd64"
+	[stage3:systemd]="amd64;arm64;x86"
+	[stage3:uclibc-hardened]="amd64;x86"
+	[stage3:uclibc-vanilla]="amd64;x86"
+)
+
+# Latest manifests
+MANIFEST="${NAME}:${SUFFIX:-latest}"
+IFS=';' read -ra ARCHES <<< "${MANIFEST_ARCHES[${MANIFEST}]}"
+
+TAGS=()
+for ARCH in "${ARCHES[@]}"; do
+	TAGS+=("${ORG}/${NAME}:${ARCH}${SUFFIX:+-${SUFFIX}}")
+done
+
+docker manifest create "${ORG}/${MANIFEST}" "${TAGS[@]}"
+docker manifest push "${ORG}/${MANIFEST}"
+
+# Dated manifests
+MANIFEST="${NAME}:${SUFFIX:+${SUFFIX}-}${VERSION}"
+
+TAGS=()
+for ARCH in "${ARCHES[@]}"; do
+	TAGS+=("${ORG}/${NAME}:${ARCH}${SUFFIX:+-${SUFFIX}}-${VERSION}")
+done
+
+docker manifest create "${ORG}/${MANIFEST}" "${TAGS[@]}"
+docker manifest push "${ORG}/${MANIFEST}"