Merge branch '22186-jenkins-docker-mirror' refs #22186
[arvados-dev.git] / jenkins / testing_to_stable_publish_packages.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # This script publishes packages from our testing repo to the prod repo (#11572 and #11878)
7 # Parameters (both are mandatory):
8 #   --packages list of packages, comma separated, to move from dev_repo_dir to prod_repo_dir
9 #   --distros  list of distros, comma separated, to which to publish packages
10
11 RPM_REPO_BASE_DIR="/var/www/rpm.arvados.org"
12
13 ###  MAIN  ####################################################################
14 [ $# -lt 2 ] && {
15   echo "usage: "
16   echo "    $0 --distros <distroA,distroB,...,distroN> --packages <packageA,packageB,...,packageN>"
17   echo "    (both parameters are mandatory)"
18   echo ""
19   exit 1
20 }
21
22 # Parse options
23 while [ ${#} -gt 0 ]; do
24     case ${1} in
25         --packages)   packages="$2";    shift 2 ;;
26         --distros)    distros="$2";     shift 2 ;;
27         *)            echo "$0: Unrecognized option: $1" >&2; exit 1;
28     esac
29 done
30
31 # Make sure the variables are set or provide an example of how to use them
32 if [ -z "${packages}" ]; then
33   echo "You must provide a comma-separated list of packages to publish, ie."
34   echo "* Debian: --packages=arvados-ws:0.1.20170906144951.22418ed6e-1,keep-exercise:1.2.3-1"
35   exit 254
36 fi
37 if [ -z "${distros}" ]; then
38   echo "You must provide a space-separated list of LSB distribution codenames to which you want to publish to, ie."
39   echo "* Debian: --distros=jessie,xenial,stretch,etc."
40   echo "* CentOS/Rocky: --distros=centos7,etc."
41   exit 255
42 fi
43
44 DIST_LIST=$(echo ${distros} | sed s/,/' '/g |tr '[:upper:]' '[:lower:]')
45 CENTOS_PACKAGES=$(echo ${packages} | sed 's/\([a-z-]*\):[[:blank:]]*\([0-9.-]*\)/\1*\2*/g; s/,/ /g;')
46 DEBIAN_PACKAGES=$(echo ${packages} | sed 's/\([a-z-]*\):[[:blank:]]*\([0-9.-]*\)/\1 (= \2)/g;')
47
48 for DISTNAME in ${DIST_LIST}; do
49     echo
50     echo "### Publishing packages for ${DISTNAME} ###"
51     echo
52     if ( echo ${DISTNAME} |grep -q -E '(centos|rocky)' ); then
53         case ${DISTNAME} in
54             'centos7')
55                 DIST_DIR_TEST='7/testing/x86_64'
56                 DIST_DIR_PROD='7/os/x86_64'
57                 ;;
58             'rocky8')
59                 DIST_DIR_TEST='8/testing/x86_64'
60                 DIST_DIR_PROD='8/os/x86_64'
61                 ;;
62             *)
63                 echo "Only centos7 and rocky8 are accepted right now"
64                 exit 253
65                 ;;
66         esac
67         cd ${RPM_REPO_BASE_DIR}
68         mkdir -p ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_PROD}
69         echo "Copying packages ..."
70         for P in ${CENTOS_PACKAGES}; do
71             cp ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_TEST}/${P} ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_PROD}/
72             if [ $? -ne 0 ]; then
73                 FAILED_PACKAGES="${FAILED_PACKAGES} ${P}"
74             fi
75         done
76         echo "Recreating repo CentOS/${DIST_DIR_PROD} ..."
77         createrepo_c ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_PROD}
78     else
79         echo "Copying packages ..."
80         OLDIFS=$IFS
81         IFS=$','
82         for P in ${DEBIAN_PACKAGES}; do
83             aptly repo search ${DISTNAME}-testing "${P}"
84             if [ $? -ne 0 ]; then
85                 echo "ERROR: unable to find a match for '${P}' in ${DISTNAME}-testing"
86                 FAILED_PACKAGES="${FAILED_PACKAGES} ${DISTNAME}-testing:${P}"
87             else
88                 aptly repo copy ${DISTNAME}-testing ${DISTNAME} "${P}"
89                 if [ $? -ne 0 ]; then
90                     echo "ERROR: unable to copy '${P}' from ${DISTNAME}-testing to ${DISTNAME}"
91                     FAILED_PACKAGES="${FAILED_PACKAGES} ${DISTNAME}-testing:${P}"
92                 fi
93             fi
94         done
95         IFS=$OLDIFS
96         echo "Publishing ${DISTNAME} repository..."
97         aptly publish update ${DISTNAME} filesystem:${DISTNAME}:
98     fi
99 done
100
101 if [ "${FAILED_PACKAGES}" != "" ]; then
102   echo "PACKAGES THAT FAILED TO PUBLISH"
103   echo "${FAILED_PACKAGES}"
104   exit 252
105 else
106   echo "All packages published correctly"
107 fi