Skip to content

{Packaging} Unblock installation in customized location for deb and RPM - #17491

Merged
Feng Zhou (fengzhou-msft) merged 7 commits into
Azure:devfrom
fengzhou-msft:linux_custom_install
Apr 7, 2021
Merged

Feng Zhou (fengzhou-msft) merged 7 commits into
Azure:devfrom
fengzhou-msft:linux_custom_install

Conversation

@fengzhou-msft

@fengzhou-msft Feng Zhou (fengzhou-msft) commented Mar 29, 2021

Copy link
Copy Markdown
Member

Description

Resolve #17221

This PR provides a more general az script to unblock customized location install, but it is not aimed to fully support custom install for deb and RPM as custom install is not fully tested and may cause some unknown issues. It is not a recommended way of azure-cli installation.

Testing Guide

  1. Build deb and RPM with the changes in this PR (This build_test branch build has the packages for the same code).
  2. Install deb and run:
$ dpkg-deb --extract azure-cli_*.deb ~
$ ~/usr/bin/az version
  1. Install RPM and run:
$ cd ~
$ rpm -ivh --relocate /usr=`pwd`/usr --relocate /etc=`pwd`/etc azure-cli-*.rpm
$ source ~/etc/bash_completion.d/azure-cli
$ ~/usr/bin/az version

History Notes

[Packaging] BREAKING CHANGE: RPM installed az now uses python3 instead of hard-coded /usr/bin/python3.


This checklist is used to make sure that common guidelines for a pull request are followed.

mkdir -p %{buildroot}%{_bindir}
python_version=$(ls %{buildroot}%{cli_lib_dir}/lib/ | head -n 1)
printf "#!/usr/bin/env bash\nAZ_INSTALLER=RPM PYTHONPATH=%{cli_lib_dir}/lib/${python_version}/site-packages /usr/bin/%{python_cmd} -sm azure.cli \"\$@\"" > %{buildroot}%{_bindir}/az
printf "#!/usr/bin/env bash\nbin_dir=\`cd \"\$(dirname \"\$BASH_SOURCE[0]\")\"; pwd\`\nAZ_INSTALLER=RPM PYTHONPATH=\"\$bin_dir\"/../%{_lib}/az/lib/${python_version}/site-packages %{python_cmd} -sm azure.cli \"\$@\"" > %{buildroot}%{_bindir}/az

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The script becomes:

#!/usr/bin/env bash
bin_dir=`cd "$(dirname "$BASH_SOURCE[0]")"; pwd`
AZ_INSTALLER=RPM PYTHONPATH="$bin_dir"/../lib64/az/lib/python3.6/site-packages python3 -sm azure.cli "$@"

@fengzhou-msft Feng Zhou (fengzhou-msft) Mar 31, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Use python3 instead of hard-coded /usr/bin/python3. This gives users flexibility to use any installed python3 by manipulating the PATH environment variable.

@jiasli Jiashuo Li (jiasli) Dec 1, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

%{_lib} causes problem on Mariner as it is different from that on Fedora/CentOS/RedHat:

> docker run -it --rm fedora rpm --eval '%{_lib}'
lib64

> docker run -it --rm centos rpm --eval '%{_lib}'
lib64

> docker run -it --rm redhat/ubi8-minimal rpm --eval '%{_lib}'
lib64

> docker run -it --rm cblmariner.azurecr.io/base/core:1.0 rpm --eval '%{_lib}'
/usr/lib

${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\nAZ_INSTALLER=DEB /opt/az/bin/python3 -Im azure.cli \"\044\100\"" > debian/azure-cli/usr/bin/az
${TAB}echo "\043!/usr/bin/env bash\nbin_dir=\140cd \"\044(dirname \"\044BASH_SOURCE[0]\")\"; pwd\140\nAZ_INSTALLER=DEB \"\044bin_dir\"/../../opt/az/bin/python3 -Im azure.cli \"\044\100\"" > debian/azure-cli/usr/bin/az

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The script becomes:

#!/usr/bin/env bash
bin_dir=`cd "$(dirname "$BASH_SOURCE[0]")"; pwd`
AZ_INSTALLER=DEB "$bin_dir"/../../opt/az/bin/python3 -Im azure.cli "$@"

_print("Python location '{}'".format(sys.executable))
_print("Extensions directory '{}'".format(EXTENSIONS_DIR))
import os
_print("Python location '{}'".format(os.path.abspath(sys.executable)))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Use abspath so on Ubuntu the bundle python won't show path like /usr/bin/../../opt/az/bin/python3, instead it will just show /opt/az/bin/python3.

Comment on lines +29 to +30
Prefix: /usr
Prefix: /etc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add Prefix to support relocatable package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linux installation doesn't allow azure-cli to be installed at a specified directory.

3 participants