Skip to content

Commit

Permalink
INDY-580: Improve packaging before supporting CentOS (hyperledger#381)
Browse files Browse the repository at this point in the history
* Support older versions of Docker

Signed-off-by: Benoit Donneaux <[email protected]>

* Quote to support spaces

Signed-off-by: Benoit Donneaux <[email protected]>

* Support multibranch PL - can not work on same volume at the same time

Signed-off-by: Benoit Donneaux <[email protected]>

* Transpose previous fixes from Jenkinsfile

Signed-off-by: Benoit Donneaux <[email protected]>

* Adapt usage accordingly

Signed-off-by: Benoit Donneaux <[email protected]>

* Add a default value for new argument

Signed-off-by: Benoit Donneaux <[email protected]>

* Improve readability

Signed-off-by: Benoit Donneaux <[email protected]>

* Fix identation

Signed-off-by: Benoit Donneaux <[email protected]>
  • Loading branch information
btlogy authored and andkononykhin committed Oct 25, 2017
1 parent be8fb2b commit ff57033
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 57 deletions.
11 changes: 8 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ def commonTestUbuntu = {

def buildDebUbuntu = { repoName, releaseVersion, sourcePath ->
def volumeName = "$name-deb-u1604"
sh "docker volume rm -f $volumeName"
if (env.BRANCH_NAME != '' && env.BRANCH_NAME != 'master') {
volumeName = "${volumeName}.${BRANCH_NAME}"
}
if (sh(script: "docker volume ls -q | grep -q '^$volumeName\$'", returnStatus: true) == 0) {
sh "docker volume rm $volumeName"
}
dir('build-scripts/ubuntu-1604') {
sh "./build-$name-docker.sh $sourcePath $releaseVersion"
sh "./build-3rd-parties-docker.sh"
sh "./build-$name-docker.sh \"$sourcePath\" $releaseVersion $volumeName"
sh "./build-3rd-parties-docker.sh $volumeName"
}
return "$volumeName"
}
Expand Down
11 changes: 8 additions & 3 deletions Jenkinsfile.cd
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ def commonTestUbuntu = {

def buildDebUbuntu = { repoName, releaseVersion, sourcePath ->
def volumeName = "$name-deb-u1604"
sh "docker volume rm -f $volumeName"
if (env.BRANCH_NAME != '' && env.BRANCH_NAME != 'master') {
volumeName = "${volumeName}.${BRANCH_NAME}"
}
if (sh(script: "docker volume ls -q | grep -q '^$volumeName\$'", returnStatus: true) == 0) {
sh "docker volume rm $volumeName"
}
dir('build-scripts/ubuntu-1604') {
sh "./build-$name-docker.sh $sourcePath $releaseVersion"
sh "./build-3rd-parties-docker.sh"
sh "./build-$name-docker.sh \"$sourcePath\" $releaseVersion $volumeName"
sh "./build-3rd-parties-docker.sh $volumeName"
}
return "$volumeName"
}
Expand Down
16 changes: 8 additions & 8 deletions build-scripts/ubuntu-1604/build-3rd-parties-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
set -x
set -e

if [ -z $1 ]; then
if [ -z "$2" ]; then
CMD="/root/build-3rd-parties.sh /output"
else
CMD=$1
CMD="$2"
fi

PKG_NAME=indy-node
IMAGE_NAME=${PKG_NAME}-build-u1604
OUTPUT_VOLUME_NAME=${PKG_NAME}-deb-u1604
IMAGE_NAME="${PKG_NAME}-build-u1604"
OUTPUT_VOLUME_NAME="${1:-"${PKG_NAME}-deb-u1604"}"

docker build -t ${PKG_NAME}-build-u1604 -f Dockerfile .
docker volume create --name ${OUTPUT_VOLUME_NAME}
docker build -t "${PKG_NAME}-build-u1604" -f Dockerfile .
docker volume create --name "${OUTPUT_VOLUME_NAME}"

docker run \
-i \
--rm \
-v ${OUTPUT_VOLUME_NAME}:/output \
${IMAGE_NAME} \
-v "${OUTPUT_VOLUME_NAME}:/output" \
"${IMAGE_NAME}" \
$CMD
32 changes: 16 additions & 16 deletions build-scripts/ubuntu-1604/build-3rd-parties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
set -e
set -x

OUTPUT_PATH=${1:-.}
OUTPUT_PATH="${1:-.}"

function build_from_pypi {
PACKAGE_NAME=$1
PACKAGE_NAME="$1"

if [ -z $2 ]; then
if [ -z "$2" ]; then
PACKAGE_VERSION=""
else
PACKAGE_VERSION="==$2"
fi
POSTINST_TMP=postinst-${PACKAGE_NAME}
PREREM_TMP=prerm-${PACKAGE_NAME}
cp postinst ${POSTINST_TMP}
cp prerm ${PREREM_TMP}
sed -i 's/{package_name}/python3-'${PACKAGE_NAME}'/' ${POSTINST_TMP}
sed -i 's/{package_name}/python3-'${PACKAGE_NAME}'/' ${PREREM_TMP}
POSTINST_TMP="postinst-${PACKAGE_NAME}"
PREREM_TMP="prerm-${PACKAGE_NAME}"
cp postinst "${POSTINST_TMP}"
cp prerm "${PREREM_TMP}"
sed -i "s/{package_name}/python3-${PACKAGE_NAME}/" "${POSTINST_TMP}"
sed -i "s/{package_name}/python3-${PACKAGE_NAME}/" "${PREREM_TMP}"

fpm --input-type "python" \
--output-type "deb" \
Expand All @@ -29,16 +29,16 @@ function build_from_pypi {
--exclude "*.pyc" \
--exclude "*.pyo" \
--maintainer "Hyperledger <[email protected]>" \
--after-install ${POSTINST_TMP} \
--before-remove ${PREREM_TMP} \
--package ${OUTPUT_PATH} \
${PACKAGE_NAME}${PACKAGE_VERSION}
--after-install "${POSTINST_TMP}" \
--before-remove "${PREREM_TMP}" \
--package "${OUTPUT_PATH}" \
"${PACKAGE_NAME}${PACKAGE_VERSION}"

rm ${POSTINST_TMP}
rm ${PREREM_TMP}
rm "${POSTINST_TMP}"
rm "${PREREM_TMP}"
}

# build 3rd parties:
# build_from_pypi <pypi-name> <version>

build_from_pypi timeout-decorator
build_from_pypi timeout-decorator
30 changes: 15 additions & 15 deletions build-scripts/ubuntu-1604/build-indy-node-docker.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#!/bin/bash -xe

PKG_SOURCE_PATH=$1
VERSION=$2
PKG_SOURCE_PATH="$1"
VERSION="$2"
PKG_NAME=indy-node
IMAGE_NAME=${PKG_NAME}-build-u1604
OUTPUT_VOLUME_NAME=${PKG_NAME}-deb-u1604
IMAGE_NAME="${PKG_NAME}-build-u1604"
OUTPUT_VOLUME_NAME="${3:-"${PKG_NAME}-deb-u1604"}"

if [[ (-z ${PKG_SOURCE_PATH}) || (-z ${VERSION}) ]]; then
echo "Usage: $0 <path-to-package-sources> <version>"
if [[ (-z "${PKG_SOURCE_PATH}") || (-z "${VERSION}") ]]; then
echo "Usage: $0 <path-to-package-sources> <version> <volume>"
exit 1;
fi

if [ -z $3 ]; then
CMD="/root/build-"${PKG_NAME}".sh /input ${VERSION} /output"
if [ -z "$4" ]; then
CMD="/root/build-${PKG_NAME}.sh /input ${VERSION} /output"
else
CMD=$3
CMD="$4"
fi

docker build -t ${IMAGE_NAME} -f Dockerfile .
docker volume create --name ${OUTPUT_VOLUME_NAME}
docker build -t "${IMAGE_NAME}" -f Dockerfile .
docker volume create --name "${OUTPUT_VOLUME_NAME}"

docker run \
-i \
--rm \
-v ${PKG_SOURCE_PATH}:/input \
-v ${OUTPUT_VOLUME_NAME}:/output \
-e PKG_NAME=${PKG_NAME} \
${IMAGE_NAME} \
-v "${PKG_SOURCE_PATH}:/input" \
-v "${OUTPUT_VOLUME_NAME}:/output" \
-e PKG_NAME="${PKG_NAME}" \
"${IMAGE_NAME}" \
$CMD

24 changes: 12 additions & 12 deletions build-scripts/ubuntu-1604/build-indy-node.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash -xe

INPUT_PATH=$1
VERSION=$2
OUTPUT_PATH=${3:-.}
INPUT_PATH="$1"
VERSION="$2"
OUTPUT_PATH="${3:-.}"

PACKAGE_NAME=indy-node

# copy the sources to a temporary folder
TMP_DIR=$(mktemp -d)
cp -r ${INPUT_PATH}/. ${TMP_DIR}
TMP_DIR="$(mktemp -d)"
cp -r "${INPUT_PATH}/." "${TMP_DIR}"

# prepare the sources
cd ${TMP_DIR}/build-scripts/ubuntu-1604
./prepare-package.sh ${TMP_DIR} ${VERSION}
cd "${TMP_DIR}/build-scripts/ubuntu-1604"
./prepare-package.sh "${TMP_DIR}" "${VERSION}"


sed -i 's/{package_name}/'${PACKAGE_NAME}'/' "prerm"
sed -i "s/{package_name}/${PACKAGE_NAME}/" "prerm"

fpm --input-type "python" \
--output-type "deb" \
Expand All @@ -31,8 +31,8 @@ fpm --input-type "python" \
--before-install "preinst_node" \
--after-install "postinst_node" \
--before-remove "prerm" \
--name ${PACKAGE_NAME} \
--package ${OUTPUT_PATH} \
${TMP_DIR}
--name "${PACKAGE_NAME}" \
--package "${OUTPUT_PATH}" \
"${TMP_DIR}"

rm -rf ${TMP_DIR}
rm -rf "${TMP_DIR}"

0 comments on commit ff57033

Please sign in to comment.