Add tools to release to repo 39/2039/1
authorMike Marchetti <mmarchetti@sandvine.com>
Tue, 25 Jul 2017 15:54:01 +0000 (11:54 -0400)
committerMike Marchetti <mmarchetti@sandvine.com>
Tue, 25 Jul 2017 15:54:01 +0000 (11:54 -0400)
Change-Id: I40e0be10dd4cbb7239f8f40990763b0e5835e231
Signed-off-by: Mike Marchetti <mmarchetti@sandvine.com>
tools/gen-repo.sh [new file with mode: 0755]
tools/getbuild.py [new file with mode: 0755]

diff --git a/tools/gen-repo.sh b/tools/gen-repo.sh
new file mode 100755 (executable)
index 0000000..8722155
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+function usage() {
+    echo -e "usage: $0 [OPTIONS] BUILD"
+    echo -e "  OPTIONS"
+    echo -e "  -p  <passphrase file>:   gpg passphrase file"
+    echo -e "  -i  <incoming repo>      "
+    echo -e "  -o  <outgoing repo>      "
+    echo -e "  -k  <gpg key>            "
+    echo -e "  -j  <jfrog cli>          "
+    echo -e "  -d  <base dir>           "
+    exit 1
+}
+
+[ $# -lt 1 ] && usage
+
+BUILD="$1"
+
+function FATAL() {
+    echo -e $1
+    exit 1
+}
+
+IN_REPO="unstable"
+OUT_REPO="stable"
+GPGKEY=71C0472C
+JFROG_CLI=~/jfrog
+REPO_BASE=repo
+BASE_DIR=$REPO_BASE/osm/debian/ReleaseTWO
+CURR_DIR=$(pwd)
+
+while getopts ":p:i:o:k:j::d:" o; do
+    case "${o}" in
+        p)
+            PASSPHRASE_FILE=${OPTARG}
+            ;;
+        i)
+            IN_REPO=${OPTARG}
+            ;;
+        o)
+            OUT_REPO=${OPTARG}
+            ;;
+        k)
+            GPGKEY=${OPTARG}
+            ;;
+        j)
+            JFROG_CLI=${OPTARG}
+            ;;
+        d)
+            BASE_DIR=${OPTARG}
+            ;;
+        *)
+            usage
+            exit 1
+            ;;
+    esac
+done
+
+[ -x $JFROG_CLI ] || FATAL "jfrog cli not found. Please install https://www.jfrog.com/getcli/ and use option '-j <jfrog cli location>'"
+
+$JFROG_CLI rt download --build "$BUILD" osm-release || FATAL "Failed to download"
+
+BUILD_NUMBER=$(basename "$BUILD")
+
+[ $PASSPHRASE_FILE ] && GPG_PASSPHRASE="--no-use-agent --passphrase \"$(cat $PASSPHRASE_FILE)\""
+
+mkdir -p $BASE_DIR/dists
+
+cp -R $BUILD_NUMBER/dists/$IN_REPO $BASE_DIR/dists/$OUT_REPO
+cp -R $BUILD_NUMBER/pool $BASE_DIR/
+
+cd $BASE_DIR
+
+for i in RO osmclient openvim SO UI; do
+
+    # gpg sign the packages
+    dpkg-sig -g "$GPG_PASSPHRASE" -k $GPGKEY --sign builder pool/$i/*.deb
+
+    # mkdir -p dists/stable/$i/binary-amd64/
+    apt-ftparchive packages pool/$i > dists/$OUT_REPO/$i/binary-amd64/Packages
+    rm -f dists/$OUT_REPO/$i/binary-amd64/Packages.gz
+    gzip -9fk dists/$OUT_REPO/$i/binary-amd64/Packages
+done
+
+# Generate the root Release
+# pushd dists/
+apt-ftparchive release dists/$OUT_REPO > dists/$OUT_REPO/Release
+#gzip -9fk dists/$OUT_REPO/Release
+
+rm -f dists/$OUT_REPO/InRelease
+eval gpg $GPG_PASSPHRASE --default-key $GPGKEY --clearsign -o dists/$OUT_REPO/InRelease dists/$OUT_REPO/Release
+
+rm -f dists/$OUT_REPO/Release.gpg
+eval gpg $GPG_PASSPHRASE --default-key $GPGKEY -abs -o dists/$OUT_REPO/Release.gpg dists/$OUT_REPO/Release
+
+
+echo "performing rsync to osm-download.etsi.org:/repos/"
+cd $CURR_DIR/$REPO_BASE
+
+rsync -avR . rsync://osmusers@osm-download.etsi.org/repos/
diff --git a/tools/getbuild.py b/tools/getbuild.py
new file mode 100755 (executable)
index 0000000..de4dcdf
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+#
+#   Copyright 2017 Sandvine
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+#
+import requests
+import json
+import pprint
+import argparse
+
+parser=argparse.ArgumentParser(description="Tool to retrieve the latest build from the artifactory server")
+parser.add_argument('branch')
+parser.add_argument('--project',default='osm-stage_3')
+parser.add_argument('--url',default='http://osm1.etsi.org:8081/artifactory/api/build/')
+args = parser.parse_args()
+
+url = args.url + args.project + " :: " + args.branch
+
+resp = requests.get(url)
+jsonData = json.loads(resp.content)
+
+if 'buildsNumbers' not in jsonData:
+    print("Cannot find any valid builds")
+    exit(1)
+
+# first entry is the latest build
+build = sorted(jsonData['buildsNumbers'], key=lambda x: int(x['uri'][1:]),reverse=True)[0]
+
+print "{} :: {}{}".format(args.project,args.branch,build['uri'])