-
Notifications
You must be signed in to change notification settings - Fork 914
/
Copy pathbuild-linux-selfcontained.sh
executable file
·146 lines (107 loc) · 3.28 KB
/
build-linux-selfcontained.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
#
# Builds autonomous Python packages including all available dependencies
# using docker.
#
# This is a tiny linux alternative to cibuildwheel on linux that does
# not rely on Docker volumes to work (such as for docker-in-docker).
#
# The in-docker portion of this script is based on cibuildwheel's counterpart.
#
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <librdkafka_tag> <out-dir>"
exit 1
fi
set -ex
if [[ $1 != "--in-docker" ]]; then
# Outside our docker
LIBRDKAFKA_VERSION=$1
outdir=$2
[[ -d $outdir ]] || mkdir -p $outdir
docker_image=quay.io/pypa/manylinux2010_x86_64
script_in_docker=/tmp/$(basename $0)
# Create container
container=$(basename $(mktemp -u pywhlXXXXXX))
docker create -i --name $container $docker_image $script_in_docker --in-docker $LIBRDKAFKA_VERSION
# Create archive
git archive -o src.tar.gz HEAD
# Copy this script to container
docker cp $0 $container:$script_in_docker
# Copy archive to container
docker cp src.tar.gz $container:/tmp/
# Run this script in docker
docker start -i $container
# Copy artifacts from container
rm -rf $outdir/output
docker cp $container:/output $outdir/
mv $outdir/output/* $outdir/
rm -rf $outdir/output
# Remove container
docker rm $container
echo "Artifacts now available in $outdir:"
ls -la $outdir/
exit 0
fi
#
# Inside our docker
#
if [[ $# -ne 2 ]]; then
echo "Inner usage: $0 --in-docker <librdkafka_tag>"
exit 1
fi
echo "$0: $HOSTNAME: Run"
shift # remove --in-docker
LIBRDKAFKA_VERSION=$1
function install_deps {
echo "# Installing basic system dependencies"
if which apt-get >/dev/null 2>&1; then
sudo apt-get -y install gcc g++ zlib1g-dev
else
yum install -y zlib-devel gcc gcc-c++ libstdc++-devel
fi
}
function build_librdkafka {
local dest=$1
echo "# Building librdkafka ${LIBRDKAFKA_VERSION}"
tools/bootstrap-librdkafka.sh --require-ssl ${LIBRDKAFKA_VERSION} $dest
}
function build {
local workdir=$1
local outdir=/output
mkdir -p $workdir
pushd $workdir
tar xvzf /tmp/src.tar.gz
install_deps
build_librdkafka /usr
mkdir -p $outdir
for PYBIN in /opt/python/cp27-*/bin; do
# Setup
rm -rf /tmp/built_wheel
rm -rf /tmp/delocated_wheel
mkdir /tmp/built_wheel
mkdir /tmp/delocated_wheel
# Build that wheel
PATH="$PYBIN:$PATH" "$PYBIN/pip" wheel . -w /tmp/built_wheel --no-deps
built_wheel=(/tmp/built_wheel/*.whl)
# Delocate the wheel
# NOTE: 'built_wheel' here is a bash array of glob matches; "$built_wheel" returns
# the first element
if [[ "$built_wheel" == *none-any.whl ]]; then
# pure python wheel - just copy
mv "$built_wheel" /tmp/delocated_wheel
else
auditwheel repair "$built_wheel" -w /tmp/delocated_wheel
fi
delocated_wheel=(/tmp/delocated_wheel/*.whl)
# Install the wheel we just built
"$PYBIN/pip" install "$delocated_wheel"
# we're all done here; move it to output
mv "$delocated_wheel" $outdir/
ls -la $outdir/
done
popd # workdir
}
echo "$0: $HOSTNAME: Building in docker"
build /build
echo "$0: $HOSTNAME: Done"