Merge branch '21521-aptly-flock'
[arvados-dev.git] / jenkins / upload_packages_testing_to_stable.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
7 # (#11572)
8 # Parameters: list of packages, space separated, to copy from *-testing to *
9
10 APT_REPO_SERVER="apt.arvados.org"
11 RPM_REPO_SERVER="rpm.arvados.org"
12
13 DEBUG=1
14 SSH_PORT=2222
15 ECODE=0
16
17 # Convert package list into a regex for publising
18 # Make sure the variables are set or provide an example of how to use them
19 if [ -z "${PACKAGES_TO_PUBLISH}" ]; then
20   echo "You must provide a list of packages to publish, as obtained with https://dev.arvados.org/projects/ops/wiki/Updating_clusters#Gathering-package-versions."
21   exit 254
22 fi
23 if [ -z "${LSB_DISTRIB_CODENAMES}" ]; then
24   echo "You must provide a space-separated list of LSB distribution codenames to which you want to publish to, ie."
25   echo "* Debian/Ubuntu: buster, bullseye, focal"
26   echo "* Redhat: centos7 rocky8"
27   exit 255
28 fi
29
30 # Only numbered package versions are supposed to go into the stable repositories
31 TMP=$(echo "$PACKAGES_TO_PUBLISH" | sed 's/versions://g;')
32 VERPATTERN='[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?-[0-9]+'
33 VALIDATED_PACKAGES_TO_PUBLISH=`echo "$TMP" | sed -nE '/^.*: '"$VERPATTERN"'$/p'`
34
35 if [[ "$TMP" != "$VALIDATED_PACKAGES_TO_PUBLISH" ]]; then
36   echo "The list of packages has invalid syntax. each line must be of the format:"
37   echo
38   echo "packagename: $VERPATTERN"
39   echo
40   exit 253
41 fi
42
43 # Sanitize the vars in a way suitable to be used by the remote 'publish_packages.sh' script
44 # Just to make copying a single line, and not having to loop over it
45 PACKAGES_LIST=$(echo ${PACKAGES_TO_PUBLISH} | sed 's/versions://g; s/\([a-z-]*\):[[:blank:]]*\([0-9.-]*\)/\1:\2,/g; s/[[:blank:]]//g; s/,$//g;')
46
47 DISTROS=$(echo "${LSB_DISTRIB_CODENAMES}"|sed s/[[:space:]]/,/g |tr '[:upper:]' '[:lower:]')
48
49 if ( echo ${LSB_DISTRIB_CODENAMES} |grep -q -E '(centos|rocky)' ); then
50   REPO_SERVER=${RPM_REPO_SERVER}
51 else
52   REPO_SERVER=${APT_REPO_SERVER}
53 fi
54
55 # Make sure jenkins scripts are up to date
56 ssh -t \
57     -l jenkinsapt \
58     -p $SSH_PORT \
59     -o "StrictHostKeyChecking no" \
60     -o "ConnectTimeout 5" \
61     ${REPO_SERVER} \
62     "cd ~/arvados-dev && git fetch -a && git reset --hard origin/main"
63
64 # Now we execute it remotely
65 TMP_FILE=`mktemp`
66
67 REMOTE_CMD="~/arvados-dev/jenkins/testing_to_stable_publish_packages.sh --distros ${DISTROS} --packages ${PACKAGES_LIST}"
68
69 ssh -t \
70     -l jenkinsapt \
71     -p $SSH_PORT \
72     -o "StrictHostKeyChecking no" \
73     -o "ConnectTimeout 5" \
74     ${REPO_SERVER} \
75     "${REMOTE_CMD}"
76 ECODE=$?
77
78 exit ${ECODE}