From 1f04fb18b22081b09e4439bdb8fab8d95076d64d Mon Sep 17 00:00:00 2001 From: Alexander Shekhovtsov Date: Wed, 19 Jul 2017 12:40:18 +0300 Subject: [PATCH] Reproducible build feature --- Jenkinsfile | 11 ++++++- build-scripts/ubuntu-1604/Dockerfile | 24 ++++++++++++++ build-scripts/ubuntu-1604/README.md | 14 ++++++++ .../ubuntu-1604/build-sovrin-docker.sh | 33 +++++++++++++++++++ build-scripts/ubuntu-1604/build-sovrin.sh | 26 +++++++++++++++ build-scripts/ubuntu-1604/postinst | 26 +++++++++++++++ build-scripts/ubuntu-1604/preinst | 5 +++ build-scripts/ubuntu-1604/prerm | 5 +++ 8 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 build-scripts/ubuntu-1604/Dockerfile create mode 100644 build-scripts/ubuntu-1604/README.md create mode 100755 build-scripts/ubuntu-1604/build-sovrin-docker.sh create mode 100755 build-scripts/ubuntu-1604/build-sovrin.sh create mode 100755 build-scripts/ubuntu-1604/postinst create mode 100755 build-scripts/ubuntu-1604/preinst create mode 100755 build-scripts/ubuntu-1604/prerm diff --git a/Jenkinsfile b/Jenkinsfile index 70e3d9b9..f6f39b32 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,15 @@ def name = 'sovrin' +def buildDebUbuntu = { repoName, releaseVersion, sourcePath -> + def volumeName = "sovrin-deb-u1604" + sh "docker volume rm -f $volumeName" + dir('build-scripts/ubuntu-1604') { + sh "./build-sovrin-docker.sh $sourcePath" + } + return "$volumeName" +} + options = new TestAndPublishOptions() options.enable([StagesEnum.PACK_RELEASE_DEPS, StagesEnum.PACK_RELEASE_ST_DEPS]) -testAndPublish(name, [ubuntu: [:]], true, options) +testAndPublish(name, [ubuntu: [:]], true, options, [ubuntu: buildDebUbuntu]) diff --git a/build-scripts/ubuntu-1604/Dockerfile b/build-scripts/ubuntu-1604/Dockerfile new file mode 100644 index 00000000..c3e0742f --- /dev/null +++ b/build-scripts/ubuntu-1604/Dockerfile @@ -0,0 +1,24 @@ +FROM ubuntu:16.04 + +RUN apt-get update -y && apt-get install -y \ + # common stuff + git \ + wget \ + unzip \ + python3.5 \ + python3-pip \ + python-setuptools \ + python3-venv \ + # fmp + ruby \ + ruby-dev \ + rubygems \ + gcc \ + make + +# install fpm +RUN gem install --no-ri --no-rdoc fpm + +WORKDIR /root + +ADD . /root diff --git a/build-scripts/ubuntu-1604/README.md b/build-scripts/ubuntu-1604/README.md new file mode 100644 index 00000000..8b567055 --- /dev/null +++ b/build-scripts/ubuntu-1604/README.md @@ -0,0 +1,14 @@ +### Build a sovrin package using docker + +``` +./build-sovrin-docker.sh +``` +Built package is placed in a docker volume `sovrin-deb-u1604`. + +### Build a sovrin package + +``` +./build-sovrin.sh +``` + +Built package is placed in the `output-path` folder. diff --git a/build-scripts/ubuntu-1604/build-sovrin-docker.sh b/build-scripts/ubuntu-1604/build-sovrin-docker.sh new file mode 100755 index 00000000..9ed15f56 --- /dev/null +++ b/build-scripts/ubuntu-1604/build-sovrin-docker.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -x +set -e + +PKG_SOURCE_PATH=$1 +PKG_NAME=sovrin +OUTPUT_VOLUME_NAME=${PKG_NAME}-deb-u1604 +IMAGE_NAME=${PKG_NAME}-build-u1604 + +if [ -z ${PKG_SOURCE_PATH} ]; then + echo "Usage: $0 path-to-package-sources" + exit 1; +fi + +if [ -z $2 ]; then + CMD="/root/build-"${PKG_NAME}".sh /input /output" +else + CMD=$2 +fi + +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} \ + $CMD + diff --git a/build-scripts/ubuntu-1604/build-sovrin.sh b/build-scripts/ubuntu-1604/build-sovrin.sh new file mode 100755 index 00000000..ed8afb44 --- /dev/null +++ b/build-scripts/ubuntu-1604/build-sovrin.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -x +set -e + +INPUT_PATH=$1 +OUTPUT_PATH=${2:-.} + +PACKAGE_NAME=sovrin + +fpm --input-type "python" \ + --output-type "deb" \ + --architecture "amd64" \ + --verbose \ + --python-package-name-prefix "python3" \ + --python-bin "/usr/bin/python3" \ + --exclude "*.pyc" \ + --exclude "*.pyo" \ + --maintainer "Sovrin Foundation " \ + --before-install "preinst" \ + --after-install "postinst" \ + --before-remove "prerm" \ + --no-python-fix-dependencies \ + --name ${PACKAGE_NAME} \ + --package ${OUTPUT_PATH} \ + ${INPUT_PATH} diff --git a/build-scripts/ubuntu-1604/postinst b/build-scripts/ubuntu-1604/postinst new file mode 100755 index 00000000..16ddd34b --- /dev/null +++ b/build-scripts/ubuntu-1604/postinst @@ -0,0 +1,26 @@ +#!/bin/bash + +# it should be fixed + +# workaround when .sovrin become regular file +if [ -f /home/sovrin/.sovrin ]; then + rm /home/sovrin/.sovrin +fi +mkdir -p /home/sovrin/.sovrin + +cp -nr /usr/local/lib/python3.5/dist-packages/sovrin/transactions_local /home/sovrin/.sovrin 2>/dev/null +cp -nr /usr/local/lib/python3.5/dist-packages/sovrin/transactions_sandbox /home/sovrin/.sovrin 2>/dev/null +cp -nr /usr/local/lib/python3.5/dist-packages/sovrin/transactions_live /home/sovrin/.sovrin 2>/dev/null +cp -nr /usr/local/lib/python3.5/dist-packages/sovrin/pool_transactions_local /home/sovrin/.sovrin 2>/dev/null +cp -nr /usr/local/lib/python3.5/dist-packages/sovrin/pool_transactions_sandbox /home/sovrin/.sovrin 2>/dev/null +cp -nr /usr/local/lib/python3.5/dist-packages/sovrin/pool_transactions_live /home/sovrin/.sovrin 2>/dev/null + +chown -R sovrin:sovrin /home/sovrin/.sovrin + + +# Automatically added from template: +if which py3compile >/dev/null 2>&1; then + py3compile -O -p sovrin /usr/local/lib/python3.5/dist-packages/ +fi + +# End automatically added section diff --git a/build-scripts/ubuntu-1604/preinst b/build-scripts/ubuntu-1604/preinst new file mode 100755 index 00000000..12f2dae4 --- /dev/null +++ b/build-scripts/ubuntu-1604/preinst @@ -0,0 +1,5 @@ +#!/bin/bash + +if ! id -u sovrin > /dev/null 2>&1; then + useradd -r -m -s /bin/bash -U sovrin +fi diff --git a/build-scripts/ubuntu-1604/prerm b/build-scripts/ubuntu-1604/prerm new file mode 100755 index 00000000..c1f12b46 --- /dev/null +++ b/build-scripts/ubuntu-1604/prerm @@ -0,0 +1,5 @@ +# Automatically added from template: + +dpkg -L sovrin | perl -ne 's,/([^/]*)\.py$,/__pycache__/\1.*, or next; unlink $_ or die $! foreach glob($_)' + +# End automatically added section \ No newline at end of file