|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Script automates the process of creating dCache packages without |
| 4 | +# Jenkins. |
| 5 | +# |
| 6 | +# The purpose is to make binary-only releases of dCache: releases |
| 7 | +# that are used when handling security vulnerabilities. The |
| 8 | +# intention is that we release the affected branches with the changes |
| 9 | +# to the source-code NOT available in github. After some embargo |
| 10 | +# period, the changes are pushed into github, making the details |
| 11 | +# public and regular releases continue. The embargo period gives |
| 12 | +# sites time to upgrade. |
| 13 | + |
| 14 | +set -e |
| 15 | + |
| 16 | +etc=$(cd $(dirname "$0")/../etc; pwd) |
| 17 | +share=$(cd $(dirname "$0")/../share; pwd) |
| 18 | + |
| 19 | +. $etc/machines |
| 20 | +. $share/functions |
| 21 | + |
| 22 | +[ $# -gt 0 ] || fail "Need to specify which tags are to be built" |
| 23 | + |
| 24 | +git rev-parse --git-dir >/dev/null 2>&1 || fail "Current directory not a git repo." |
| 25 | + |
| 26 | +[ $(git status --porcelain | wc -l) -eq 0 ] || fail "git repo isn't clean" |
| 27 | + |
| 28 | +git_remote_branch= $(git remote -v | awk "/[email protected]:dCache\/dcache.git \(fetch\)/{print \$1}") |
| 29 | +if [ "$git_remote_branch" = "" ]; then |
| 30 | + git_remote_branch=$(git remote -v | awk "/https:\/\/github.com\/dCache\/dcache.git/{print \$1}") |
| 31 | +fi |
| 32 | + |
| 33 | +[ "$git_remote_branch" != "" ] || fail "Current git repo is not a dCache clone." |
| 34 | + |
| 35 | +# Validate arguments |
| 36 | +for tag in $*; do |
| 37 | + rc=0 |
| 38 | + check=$(git describe refs/tags/$tag) || rc=1 |
| 39 | + if [ $rc -ne 0 ] || [ "$check" != "$tag" ]; then |
| 40 | + fail "No such tag $tag" |
| 41 | + fi |
| 42 | + |
| 43 | + if [ $(git branch --contains refs/tags/$tag | wc -l) -ne 1 ]; then |
| 44 | + fail "Tag $tag appears in multiple branches" |
| 45 | + fi |
| 46 | + |
| 47 | + branch=$(git branch --contains refs/tags/$tag | cut -c3-) |
| 48 | + |
| 49 | + if [ $(git describe --tags --abbrev=0 $branch) != $tag ]; then |
| 50 | + fail "Tag $tag is not the latest tag in branch $branch" |
| 51 | + fi |
| 52 | +done |
| 53 | + |
| 54 | +target_dir=$(cd ..;pwd) |
| 55 | +echo "Building tags $* and storing packages in $target_dir" |
| 56 | +echo -n "Type \"continue\" to continue: " |
| 57 | +read response |
| 58 | +if [ "$response" != "continue" ]; then |
| 59 | + fail "Aborting at users request" |
| 60 | +fi |
| 61 | + |
| 62 | +function build() { # $1 user, $2 machine, $3 src tarball, $4 tag, $5 package |
| 63 | + |
| 64 | + # We need to work-around the lack of git when building the source |
| 65 | + # tar-ball. To do this we redirect the scmBranch property to one |
| 66 | + # that is ignored and manually set the property. |
| 67 | + branch_option="-DscmBranchPropertyName=ignoreMe -DscmBranch=${4%.*}" |
| 68 | + |
| 69 | + case $5 in |
| 70 | + TGZ) |
| 71 | + module=packages/tar |
| 72 | + profile_option= |
| 73 | + package_file="dcache-$4.tar.gz" |
| 74 | + package_path="packages/tar/target/$package_file" |
| 75 | + ;; |
| 76 | + RPM) |
| 77 | + module=packages/fhs |
| 78 | + profile_option=-Prpm |
| 79 | + package_file="dcache-$4-1.noarch.rpm" |
| 80 | + package_path="packages/fhs/target/rpmbuild/RPMS/noarch/$package_file" |
| 81 | + ;; |
| 82 | + DEB) |
| 83 | + module=packages/fhs |
| 84 | + profile_option=-Pdeb |
| 85 | + package_file="dcache_$4-1_all.deb" |
| 86 | + package_path="packages/fhs/target/$package_file" |
| 87 | + ;; |
| 88 | + *) |
| 89 | + fail "Unknown package $5" |
| 90 | + ;; |
| 91 | + esac |
| 92 | + |
| 93 | + echo "Uploading source package to $5 build machine: $2" |
| 94 | + scp -q $3 $1@$2:/tmp/$3 |
| 95 | + |
| 96 | + target_dir="SpecialBuilds/$4" |
| 97 | + maven_logfile=/tmp/maven-$$-$5.out |
| 98 | + |
| 99 | + script=binary-releases-$$.sh |
| 100 | + cat - > $script <<EOF |
| 101 | +export PATH=$PATH:/opt/tools/apache-maven/bin |
| 102 | +mkdir -p $target_dir |
| 103 | +cd $target_dir |
| 104 | +rm -rf * |
| 105 | +echo Expanding source package |
| 106 | +tar xzf /tmp/$3 |
| 107 | +echo "Building $package_file (see $2:$maven_logfile)" |
| 108 | +mvn -l $maven_logfile -am -pl $module clean package $branch_option -DskipTests $profile_option |
| 109 | +if [ $? -ne 0 ]; then |
| 110 | + echo Build failed |
| 111 | +else |
| 112 | + rm $maven_logfile |
| 113 | +fi |
| 114 | +EOF |
| 115 | + host_script=/tmp/$script |
| 116 | + scp -q $script $1@$2:$host_script |
| 117 | + rm $script |
| 118 | + ssh -T -l $1 $2 chmod 755 $host_script |
| 119 | + ssh -T -l $1 $2 $host_script |
| 120 | + ssh -T -l $1 $2 rm $host_script |
| 121 | + |
| 122 | + echo "Downloading binary package $(basename $package_path)" |
| 123 | + scp -q $1@$2:$target_dir/$package_path .. |
| 124 | +} |
| 125 | + |
| 126 | +# Build the tagged versions of dCache |
| 127 | +for tag in $*; do |
| 128 | + git clean -dfx |
| 129 | + |
| 130 | + branch=$(git branch --contains refs/tags/$tag | cut -c3-) |
| 131 | + jdk=$(jdk_for_branch "$branch") |
| 132 | + src=dcache-$tag-src.tar.gz |
| 133 | + |
| 134 | + echo Building source package: $src |
| 135 | + git checkout -q $tag |
| 136 | + |
| 137 | + # The "git commit id plugin" requires the .git directory, with no |
| 138 | + # way to by-pass this. |
| 139 | + grep -q git-commit-id-plugin pom.xml && dot_git=.git || dot_git= |
| 140 | + |
| 141 | + tar czf $src * $dot_git |
| 142 | + |
| 143 | + for pkg in RPM DEB TGZ; do |
| 144 | + usermachine=$(eval "echo \${BUILD_${pkg}_JDK${jdk}}") |
| 145 | + machine=${usermachine#*@} |
| 146 | + user=${usermachine%@*} |
| 147 | + build $user $machine $src $tag $pkg |
| 148 | + done |
| 149 | +done |
0 commit comments