Skip to content

Commit

Permalink
Package python in apt-get install (#3186)
Browse files Browse the repository at this point in the history
- remove usage of dh_virtualenv now as we do it manually.
  • Loading branch information
derekbekoe authored May 5, 2017
1 parent 743b4fb commit e065618
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 60 deletions.
6 changes: 3 additions & 3 deletions packaged_releases/debian/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ For example:

First copy the build scripts onto the build machine.
```
$ > debian_build.sh; editor debian_build.sh
$ > debian_dir_creator.sh; editor debian_dir_creator.sh
$ chmod +x debian_build.sh debian_dir_creator.sh
$ > ~/debian_build.sh; editor ~/debian_build.sh
$ > ~/debian_dir_creator.sh; editor ~/debian_dir_creator.sh
$ chmod +x ~/debian_build.sh ~/debian_dir_creator.sh
```

Then execute it with the appropriate environment variable values.
Expand Down
66 changes: 24 additions & 42 deletions packaged_releases/debian/debian_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,8 @@ sudo apt-get update

debian_directory_creator=$1

# Modify dh-virtualenv/debian/control to not include the virtualenv or python-virtualenv
# dependencies as we don't use python-virtualenv but our own.
dh_virtualenv_debian_control=$(mktemp)
cat > $dh_virtualenv_debian_control <<- EOM
Source: dh-virtualenv
Section: python
Priority: extra
Maintainer: Jyrki Pulliainen <jyrki@spotify.com>
Build-Depends: debhelper (>= 9), python(>= 2.6.6-3~),
python-setuptools, python-sphinx, python-mock
Standards-Version: 3.9.8
Homepage: http://www.github.com/spotify/dh-virtualenv
X-Python-Version: >= 2.6
Package: dh-virtualenv
Architecture: all
Depends: \${python:Depends}, \${misc:Depends}, \${sphinxdoc:Depends}
Description: wrap and build python packages using virtualenv
This package provides a dh sequencer that helps you to deploy your
virtualenv wrapped installation inside a Debian package.
EOM

# Install latest versions of pip and virtualenv
sudo apt-get install -y curl
get_pip_py=$(mktemp)
curl "https://bootstrap.pypa.io/get-pip.py" -o $get_pip_py
sudo python $get_pip_py
sudo pip install virtualenvwrapper
# Install dh-virtualenv by building from GitHub repo
sudo apt-get install -y devscripts git equivs
dh_virtualenv_git_dir=$(mktemp -d)
git clone https://github.com/spotify/dh-virtualenv.git $dh_virtualenv_git_dir
cd $dh_virtualenv_git_dir
git checkout tags/1.0
echo "y\n" | sudo mk-build-deps -ri
# Apply dh-virtualenv debian/control patch
mv $dh_virtualenv_debian_control $dh_virtualenv_git_dir/debian/control
# Build dh-virtualenv
dpkg-buildpackage -us -uc -b
sudo dpkg -i ../dh-virtualenv_1.0-1_all.deb
# Install dependencies for the build
sudo apt-get install -y libssl-dev libffi-dev python-dev
sudo apt-get install -y libssl-dev libffi-dev python3-dev debhelper
# Download, Extract, Patch, Build CLI
working_dir=$(mktemp -d)
source_archive=$working_dir/azure-cli-${CLI_VERSION}.tar.gz
Expand All @@ -73,11 +33,33 @@ mkdir $source_dir
archive_extract_dir=$(mktemp -d)
tar -xvzf $source_archive -C $archive_extract_dir
cp -r $archive_extract_dir/azure-cli_packaged_${CLI_VERSION}/* $source_dir
# Build Python from source and include
python_dir=$(mktemp -d)
python_archive=$(mktemp)
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz -qO $python_archive
tar -xvzf $python_archive -C $python_dir
echo "Python dir is $python_dir"
# clean any previous make files
make clean || echo "Nothing to clean"
$python_dir/*/configure --srcdir $python_dir/* --prefix $source_dir/python_env
make
# required to run the 'make install'
sudo apt-get install -y zlib1g-dev
make install
tmp_pkg_dir=$(mktemp -d)

# note: This installation step could happen in debian/rules but was unable to escape $ char.
# It does not affect the built .deb file though.
$source_dir/python_env/bin/pip3 install wheel
for d in $source_dir/src/azure-cli $source_dir/src/azure-cli-core $source_dir/src/azure-cli-nspkg $source_dir/src/azure-cli-command_modules-nspkg $source_dir/src/command_modules/azure-cli-*/; do cd $d; $source_dir/python_env/bin/python3 setup.py bdist_wheel -d $tmp_pkg_dir; cd -; done;
$source_dir/python_env/bin/pip3 install azure-cli --find-links $tmp_pkg_dir
$source_dir/python_env/bin/pip3 install --force-reinstall --upgrade azure-nspkg azure-mgmt-nspkg
# Add the debian files
mkdir $source_dir/debian
# Create temp dir for the debian/ directory used for CLI build.
cli_debian_dir_tmp=$(mktemp -d)
$debian_directory_creator $cli_debian_dir_tmp $source_dir/az.completion

$debian_directory_creator $cli_debian_dir_tmp $source_dir/az.completion $source_dir
cp -r $cli_debian_dir_tmp/* $source_dir/debian
cd $source_dir
dpkg-buildpackage -us -uc
Expand Down
34 changes: 19 additions & 15 deletions packaged_releases/debian/debian_dir_creator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ if [ -z "$2" ]
exit 1
fi

if [ -z "$3" ]
then
echo "No argument supplied for source directory."
exit 1
fi

TAB=$'\t'

debian_dir=$1
completion_script=$2
source_dir=$3
mkdir $debian_dir/source

echo '1.0' > $debian_dir/source/format
Expand All @@ -36,7 +43,7 @@ azure-cli (${CLI_VERSION}-1) unstable; urgency=low
* Debian package release.
-- Azure Python CLI Team <azpycli@microsoft.com> Mon, 01 Jan 2017 00:00:00 -0700
-- Azure Python CLI Team <azpycli@microsoft.com> $(date -R)
EOM

Expand All @@ -45,13 +52,13 @@ Source: azure-cli
Section: python
Priority: extra
Maintainer: Azure Python CLI Team <azpycli@microsoft.com>
Build-Depends: debhelper (>= 9), python, dh-virtualenv (>= 0.8), libssl-dev, libffi-dev, python-dev
Build-Depends: debhelper (>= 9), libssl-dev, libffi-dev, python3-dev
Standards-Version: 3.9.5
Homepage: https://github.com/azure/azure-cli
Package: azure-cli
Architecture: all
Depends: \${python:Depends}, \${misc:Depends}
Depends: \${misc:Depends}
Description: Azure CLI 2.0 - Preview
A great cloud needs great tools; we're excited to introduce Azure CLI 2.0 - Preview,
our next generation multi-platform command line experience for Azure.
Expand Down Expand Up @@ -84,22 +91,16 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
EOM

cat > $debian_dir/rules << EOM
export DH_VIRTUALENV_INSTALL_ROOT=/opt/
#!/usr/bin/make -f
%:
${TAB}dh \$@ --with python-virtualenv
override_dh_virtualenv:
${TAB}dh_virtualenv --sourcedirectory src/azure-cli-nspkg --install-suffix az
${TAB}dh_virtualenv --sourcedirectory src/azure-cli-command_modules-nspkg --install-suffix az
${TAB}dh_virtualenv --sourcedirectory src/azure-cli-core --install-suffix az
${TAB}for d in src/command_modules/azure-cli-*/; do dh_virtualenv --sourcedirectory \$d --install-suffix az; done;
${TAB}dh_virtualenv --sourcedirectory src/azure-cli --install-suffix az
${TAB}echo -n > debian/azure-cli/opt/az/lib/*/site-packages/azure/__init__.py
${TAB}echo -n > debian/azure-cli/opt/az/lib/*/site-packages/azure/mgmt/__init__.py
${TAB}dh \$@ --sourcedirectory $source_dir
override_dh_install:
${TAB}mkdir -p debian/azure-cli/opt/az
${TAB}cp -a python_env/* debian/azure-cli/opt/az
${TAB}mkdir -p debian/azure-cli/usr/bin/
${TAB}echo "\043!/usr/bin/env bash\n/opt/az/bin/python -m azure.cli \"\044\100\"" > debian/azure-cli/usr/bin/az
${TAB}echo "\043!/usr/bin/env bash\n/opt/az/bin/python3 -m azure.cli \"\044\100\"" > debian/azure-cli/usr/bin/az
${TAB}chmod 0755 debian/azure-cli/usr/bin/az
${TAB}mkdir -p debian/azure-cli/etc/bash_completion.d/
${TAB}cat ${completion_script} > debian/azure-cli/etc/bash_completion.d/azure-cli
Expand All @@ -108,3 +109,6 @@ override_dh_strip:
${TAB}dh_strip --exclude=_cffi_backend
EOM

# debian/rules should be executable
chmod 0755 $debian_dir/rules

0 comments on commit e065618

Please sign in to comment.