Skip to content

Commit

Permalink
add build scripts for the project
Browse files Browse the repository at this point in the history
 - openstack_python_bsn_neutronclient*.build are the jenkins
   tasks of the same name
 - *.build files contain the shell script executed by the jenkins
   tasks
  • Loading branch information
wolverineav committed Mar 12, 2018
1 parent 17254fb commit 9c7192c
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build_scripts/build-rhel-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
python setup.py bdist_rpm --spec-only \
--release=2 \
--distribution-name=el7.centos \
--requires=python-neutronclient \
--build-requires=python-pbr \
19 changes: 19 additions & 0 deletions build_scripts/is_version_bumped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python

import sys

from distutils.version import StrictVersion

# read the two git diff lines about version
two_lines = sys.stdin.read()
if 'version' not in two_lines:
sys.exit("version not found in args. Build FAILED")
lines = str(two_lines).split('\n')
version1 = StrictVersion(lines[0].split('=')[1].strip())
version2 = StrictVersion(lines[1].split('=')[1].strip())
print 'version1: ', version1
print 'version2: ', version2
if version2 > version1:
print 'Version update correct.'
else:
sys.exit("new version string is < old version string. Build FAILED")
18 changes: 18 additions & 0 deletions build_scripts/openstack_python_bsn_neutronclient.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
git clean -fxd
GIT_REPO=`pwd`

# get gpg creds in place
GNUPG_DIR=$(mktemp -d)
tar -zxvf $GNUPG_TAR -C $GNUPG_DIR

DOCKER_IMAGE=$DOCKER_REGISTRY'/bosi-builder:latest'

echo "Tagging and uploading to PYPI"
docker pull $DOCKER_IMAGE
docker run -e GIT_BRANCH=$GIT_BRANCH -v $GIT_REPO:/python-bsn-neutronclient -v $PYPIRC_FILE:/root/.pypirc -v $GNUPG_DIR/.gnupg:/root/.gnupg $DOCKER_IMAGE /python-bsn-neutronclient/build_scripts/upload_to_pypi.sh

# remove pypi and gpg creds
sudo rm -rf $GNUPG_DIR

echo "Building RPM packages"
docker run -v $GIT_REPO:/python-bsn-neutronclient $DOCKER_IMAGE /python-bsn-neutronclient/build_scripts/build-rhel-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./build_scripts/precheckin.sh
14 changes: 14 additions & 0 deletions build_scripts/precheckin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -eux
pwd
echo 'git commit is' ${GIT_COMMIT}
git clean -fxd
tox -e pep8
setup_cfg_modified=`git log -m -1 --name-only --pretty="format:" | grep setup.cfg | wc -l`
if [ ${setup_cfg_modified} -ne 1 ];
then echo "Update setup.cfg with new version number. Build FAILED";
exit 1;
else
echo "setup.cfg updated"; fi
# check the new_version > old_version
echo 'checking if version bump is correct'
git log -m -1 ${GIT_COMMIT} --pretty="format:" -p setup.cfg | grep version | python build_scripts/is_version_bumped.py
35 changes: 35 additions & 0 deletions build_scripts/upload_to_pypi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -eux

# RPM runs as root and doesn't like source files owned by a random UID
OUTER_UID=$(stat -c '%u' /python-bsn-neutronclient)
OUTER_GID=$(stat -c '%g' /python-bsn-neutronclient)
trap "chown -R $OUTER_UID:$OUTER_GID /python-bsn-neutronclient" EXIT
chown -R root:root /python-bsn-neutronclient

cd /python-bsn-neutronclient
git config --global user.name "Big Switch Networks"
git config --global user.email "support@bigswitch.com"

CURR_VERSION=$(awk '/^version/{print $3}' setup.cfg)

echo 'CURR_VERSION=' $CURR_VERSION
git tag -f -s $CURR_VERSION -m $CURR_VERSION -u "Big Switch Networks"

python setup.py sdist

# force success. but always check if pip install fails
twine upload dist/* -r pypi -s -i "Big Switch Networks" || true
# delay of 5 seconds
sleep 5
sudo -H pip install --upgrade python-bsn-neutronclient==$CURR_VERSION
if [ "$?" -eq "0" ]
then
echo "PYPI upload successful."
else
echo "PYPI upload FAILED. Check the logs."
fi
# remove the package
sudo -H pip uninstall -y python-bsn-neutronclient

# revert the permissions
chown -R $OUTER_UID:$OUTER_GID /python-bsn-neutronclient
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[metadata]
name = python-bsn-neutronclient
version = 0.0.1
summary = Python bindings for Big Switch Networks Neutron API
description-file =
README.rst
author = Big Switch Networks
author-email = support@bigswitch.com
home-page = http://www.bigswitch.com/
license = ASL 2.0
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Expand Down

0 comments on commit 9c7192c

Please sign in to comment.