Skip to content

Build manylinux1 OS-specific binary wheels in Travis (CI) and publish them to PyPI (CD) #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b470b1a
let's give this a try
beniwohli Apr 29, 2016
89d62fd
vars
webknjaz Jan 31, 2019
5023308
Rearrange travis config
webknjaz Jan 31, 2019
a0c2679
Bump libgit2 source to v0.27
webknjaz Feb 10, 2019
5d184dd
Fix building manylinux1 wheels
webknjaz Feb 11, 2019
94edb05
Don't execute install step in docker jobs
webknjaz Feb 11, 2019
fbcef81
Fix referring pip bin var
webknjaz Feb 11, 2019
eaedbf8
Fix env vars in travis
webknjaz Feb 11, 2019
976d544
Upgrade PyPy to v6.0
webknjaz Feb 11, 2019
948872c
Run pip in parallel
webknjaz Feb 11, 2019
7a5bc52
Adjust tests to succeed under PyPy v6.0
webknjaz Feb 11, 2019
8db38f7
Put manylinux1 jobs into a separate stage
webknjaz Feb 11, 2019
5f2c250
Add deploy step stub to travis
webknjaz Feb 11, 2019
ae1ee1c
Undo async in wheel build script
webknjaz Feb 12, 2019
dc801b7
Create wheelhouse dir on build start
webknjaz Feb 12, 2019
548ecf4
Be more precise during wheel processing
webknjaz Feb 12, 2019
518984d
Add a wrapper script for building several archs
webknjaz Feb 12, 2019
029165c
Add a deploy step stub to Travis
webknjaz Feb 12, 2019
d9d40d2
Save final wheels to dist dir directly
webknjaz Feb 12, 2019
e184187
Add deploy stage conditional stub
webknjaz Feb 12, 2019
ee78fde
List the whole wheelhouse folder
webknjaz Feb 12, 2019
6b55b79
List full dist folder in travis
webknjaz Feb 12, 2019
b530d20
Copy travis config owner to dist dir
webknjaz Feb 12, 2019
18abf68
Compile libgit2 in threadsafe mode
webknjaz Feb 13, 2019
e1ebe52
Compile libgit2 in "Release" build type mode
webknjaz Feb 13, 2019
457b1d1
Detect custom OpenSSL properly
webknjaz Feb 13, 2019
57da1d5
Extend build flags
webknjaz Feb 13, 2019
4a50c76
Build libgit2 with libssh2 v1.8.0
webknjaz Feb 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/sh

LIBGIT2_VERSION="$1"
if [ -z "$LIBGIT2_VERSION" ]
then
>&2 echo "Please pass libgit2 version as a first argument of this script ($0)"
exit 1
fi

cd ~

git clone --depth=1 -b maint/v0.27 https://github.com/libgit2/libgit2.git
git clone --depth=1 -b "maint/v${LIBGIT2_VERSION}" https://github.com/libgit2/libgit2.git
cd libgit2/

mkdir build && cd build
Expand Down
65 changes: 58 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: xenial
language: python

cache: pip
Expand All @@ -7,22 +8,72 @@ python:
- "3.4"
- "3.5"
- "3.6"
- "pypy"
- "3.7"
- "pypy2.7-6.0"
- "pypy3.5-6.0"

matrix:
env:
global:
LIBGIT2: ~/libgit2/_install/
LD_LIBRARY_PATH: ${LIBGIT2}/lib:${LD_LIBRARY_PATH}
LIBGIT2_VERSION: "0.27"


jobs:
include:
- python: 3.7
dist: xenial
sudo: true
- stage: &deploy_stage Publish to PyPI (runs only for tagged commits)
name: >-
OS-specific manylinux1 wheels
python: "3.7"
services:
- docker
install: skip
script: &docker-script
- travis/build-all-manylinux1-wheels.sh "pygit2" "${LIBGIT2_VERSION}"
before_deploy:
- ls dist
- pip install twine
- twine check dist/*
deploy:
provider: pypi
# `skip-cleanup: true` is required to preserve binary wheels, built
# inside of manylinux1 docker container during `script` step above.
skip-cleanup: true
# `skip-existing: true` is required to skip uploading dists, already
# present in PYPI instead of failing the whole process.
# This happens when other CI (AppVeyor etc.) has already uploaded
# the very same dist (usually sdist).
skip-existing: true
user: jdavid
password:
# Encrypted with `travis encrypt -r aio-libs/aiohttp --api-endpoint 'https://api.travis-ci.com/'`:
secure: >-
TODO: REPLACE THIS WITH AN ENCRYPTED PASSWORD
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdavid please generate the encrypted string using travis encrypt -r libgit2/pygit2 command.

And then you can use this page to update in via UI right in this PR: https://github.com/webknjaz/pygit2/edit/feature/manylinux1-binary-wheels/.travis.yml?pr=%2Flibgit2%2Fpygit2%2Fpull%2F869

# Although Travis CI instructs `setup.py` to build source distribution,
# which is default value for distribution option (`distribution: sdist`),
# it will also upload all wheels we've previously built in manylinux1
# docker container using `twine upload -r pypi dist/*` command.
# Also since commit https://github.com/travis-ci/dpl/commit/90b5e39
# it is default that Travis PYPI provider has `skip_upload_docs: true`
# set by default.
# Besides above, we don't do cleanup of `dist/*`, because it's being done
# by Travis CI PYPI deployment provider after upload, unconditionally.
on:
tags: true
all_branches: true

env: LIBGIT2=~/libgit2/_install/ LD_LIBRARY_PATH=~/libgit2/_install/lib

before_install:
- sudo apt-get install cmake
- "./.travis.sh"
- ./.travis.sh "${LIBGIT2_VERSION}"

install:
- pip install .

script:
- pytest

stages:
- test
- name: *deploy_stage
if: 1=1 OR tag IS present OR type IN (cron, api)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdavid
We'll need to apply

Suggested change
if: 1=1 OR tag IS present OR type IN (cron, api)
if: tag IS present OR type IN (cron, api)

once password is updated.

11 changes: 5 additions & 6 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,11 @@ def test_modify_commit(self):

commit = self.repo[COMMIT_SHA]

error_type = AttributeError if not pypy2 else TypeError
with pytest.raises(error_type): setattr(commit, 'message', message)
with pytest.raises(error_type): setattr(commit, 'committer', committer)
with pytest.raises(error_type): setattr(commit, 'author', author)
with pytest.raises(error_type): setattr(commit, 'tree', None)
with pytest.raises(error_type): setattr(commit, 'parents', None)
with pytest.raises(AttributeError): setattr(commit, 'message', message)
with pytest.raises(AttributeError): setattr(commit, 'committer', committer)
with pytest.raises(AttributeError): setattr(commit, 'author', author)
with pytest.raises(AttributeError): setattr(commit, 'tree', None)
with pytest.raises(AttributeError): setattr(commit, 'parents', None)


class GpgSignatureTestCase(utils.GpgSignedRepoTestCase):
Expand Down
9 changes: 4 additions & 5 deletions test/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def test_modify_tag(self):
tagger = ('John Doe', '[email protected]', 12347)

tag = self.repo[TAG_SHA]
error_type = AttributeError if not pypy2 else TypeError
with pytest.raises(error_type): setattr(tag, 'name', name)
with pytest.raises(error_type): setattr(tag, 'target', target)
with pytest.raises(error_type): setattr(tag, 'tagger', tagger)
with pytest.raises(error_type): setattr(tag, 'message', message)
with pytest.raises(AttributeError): setattr(tag, 'name', name)
with pytest.raises(AttributeError): setattr(tag, 'target', target)
with pytest.raises(AttributeError): setattr(tag, 'tagger', tagger)
with pytest.raises(AttributeError): setattr(tag, 'message', message)

def test_get_object(self):
repo = self.repo
Expand Down
51 changes: 51 additions & 0 deletions travis/build-all-manylinux1-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /usr/bin/env bash
if [ -n "$DEBUG" ]
then
set -x
fi

package_name="$1"
LIBGIT2_VERSION="$2"

set -euo pipefail

if [ -z "$package_name" ]
then
>&2 echo "Please pass package name as a first argument of this script ($0)"
exit 1
fi

if [ -z "$LIBGIT2_VERSION" ]
then
>&2 echo "Please pass libgit2 version as a second argument of this script ($0)"
exit 1
fi

manylinux1_image_prefix="quay.io/pypa/manylinux1_"
manylinux1_image_prefix="pyca/cryptography-manylinux1:"
dock_ext_args=""
declare -A docker_pull_pids=() # This syntax requires at least bash v4

for arch in x86_64 i686
do
docker pull "${manylinux1_image_prefix}${arch}" &
docker_pull_pids[$arch]=$!
done

for arch in x86_64 i686
do
echo
echo
arch_pull_pid=${docker_pull_pids[$arch]}
echo Waiting for docker pull PID $arch_pull_pid to complete downloading container for $arch arch...
wait $arch_pull_pid # await for docker image for current arch to be pulled from hub
[ $arch == "i686" ] && dock_ext_args="linux32"

echo Building wheel for $arch arch
docker run --rm -v `pwd`:/io "${manylinux1_image_prefix}${arch}" $dock_ext_args /io/travis/build-manylinux1-wheels.sh "$package_name" "$LIBGIT2_VERSION" &

dock_ext_args="" # Reset docker args, just in case
done
wait

set +u
104 changes: 104 additions & 0 deletions travis/build-manylinux1-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
if [ -n "$DEBUG" ]
then
set -x
fi

DIST_NAME="$1"
LIBGIT2_VERSION="$2"

set -euo pipefail

if [ -z "$DIST_NAME" ]
then
>&2 echo "Please pass package name as a first argument of this script ($0)"
exit 1
fi

if [ -z "$LIBGIT2_VERSION" ]
then
>&2 echo "Please pass libgit2 version as a second argument of this script ($0)"
exit 1
fi

PYTHONS=`ls /opt/python/`

SRC_DIR=/io
BUILD_DIR=`mktemp -d "/tmp/${DIST_NAME}-manylinux1-build.XXXXXXXXXX"`
LIBGIT2_CLONE_DIR="${BUILD_DIR}/libgit2"
LIBGIT2_BUILD_DIR="${LIBGIT2_CLONE_DIR}/build"
export LIBGIT2="${LIBGIT2_CLONE_DIR}/_install"

ORIG_WHEEL_DIR="${BUILD_DIR}/original-wheelhouse"
WHEEL_DEP_DIR="${BUILD_DIR}/deps-wheelhouse"
WHEELHOUSE_DIR="${SRC_DIR}/dist"

mkdir -p "$WHEELHOUSE_DIR"

export PYCA_OPENSSL_PATH=/opt/pyca/cryptography/openssl
export OPENSSL_PATH=/opt/openssl

export CFLAGS="-I${PYCA_OPENSSL_PATH}/include -I${OPENSSL_PATH}/include"
export LDFLAGS="-L${PYCA_OPENSSL_PATH}/lib -L${OPENSSL_PATH}/lib -L/usr/local/lib/"
export LD_LIBRARY_PATH="${LIBGIT2}/lib:$LD_LIBRARY_PATH"

ARCH=`uname -m`


>&2 echo Installing system deps...
# Install a system package required by our library
# libgit2 needs cmake 2.8, which can be found in EPEL
yum -y install \
git libssh2-devel libffi-devel \
openssl-devel pkgconfig \
cmake28

>&2 echo downloading source of libgit2 v${LIBGIT2_VERSION}:
git clone \
--depth=1 \
-b "maint/v${LIBGIT2_VERSION}" \
https://github.com/libgit2/libgit2.git \
"${LIBGIT2_CLONE_DIR}"

>&2 echo Building libgit2...
mkdir -p "${LIBGIT2_BUILD_DIR}"
pushd "${LIBGIT2_BUILD_DIR}"
cmake28 "${LIBGIT2_CLONE_DIR}" -DCMAKE_INSTALL_PREFIX="${LIBGIT2}" -DBUILD_CLAR=OFF
cmake28 --build "${LIBGIT2_BUILD_DIR}" --target install
popd

>&2 echo Building wheels:
for PIP_BIN in /opt/python/*/bin/pip; do
>&2 echo Using "${PIP_BIN}"...
${PIP_BIN} wheel "${SRC_DIR}" -w "${ORIG_WHEEL_DIR}"
done

>&2 echo Reparing wheels:
# Bundle external shared libraries into the wheels
for PY in $PYTHONS; do
for whl in ${ORIG_WHEEL_DIR}/${DIST_NAME}-*-${PY}-linux_${ARCH}.whl; do
>&2 echo Reparing "${whl}"...
auditwheel repair "${whl}" -w ${WHEELHOUSE_DIR}
done
done

# Download deps
>&2 echo Downloading dependencies:
for PY in $PYTHONS; do
PIP_BIN="/opt/python/${PY}/bin/pip"
WHEEL_FILE=`ls ${WHEELHOUSE_DIR}/${DIST_NAME}-*-${PY}-manylinux1_${ARCH}.whl`
>&2 echo Downloading ${WHEEL_FILE} deps using ${PIP_BIN}...
${PIP_BIN} download -d "${WHEEL_DEP_DIR}" "${WHEEL_FILE}"
done

# Install packages
>&2 echo Testing wheels installation:
for PIP_BIN in /opt/python/*/bin/pip; do
>&2 echo Using ${PIP_BIN}...
${PIP_BIN} install "${DIST_NAME}" --no-index -f ${WHEEL_DEP_DIR} &
done
wait

chown -R 1000:1000 ${WHEELHOUSE_DIR}
>&2 echo Final OS-specific wheels for ${DIST_NAME}:
ls -l ${WHEELHOUSE_DIR}/*.whl