Skip to content

Commit

Permalink
[Packaging] Use Python 3.9 in RHEL 8's RPM (#22606)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli authored Jun 3, 2022
1 parent b471cca commit 22bd245
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions scripts/release/rpm/azure-cli.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
%define dist .el%{?rhel}
%endif

%define python_cmd python3
# The Python package name for dnf/yum/tdnf, such as python39, python3
%define python_package %{getenv:PYTHON_PACKAGE}
# The Python executable name, such as python3.9, python3
%define python_cmd %{getenv:PYTHON_CMD}

%define name azure-cli
%define release 1%{?dist}
Expand All @@ -25,12 +28,12 @@ Version: %{version}
Release: %{release}
Url: https://docs.microsoft.com/cli/azure/install-azure-cli
BuildArch: x86_64
Requires: %{python_cmd}
Requires: %{python_package}
Prefix: /usr
Prefix: /etc

BuildRequires: gcc, libffi-devel, openssl-devel, perl
BuildRequires: %{python_cmd}-devel
BuildRequires: %{python_package}-devel

%global _python_bytecompile_errors_terminate_build 0

Expand Down Expand Up @@ -66,6 +69,7 @@ for d in %{buildroot}%{cli_lib_dir}/bin/*; do perl -p -i -e "s#%{buildroot}##g"
# The only solution left is to hard-code 'lib64' as we only release 64-bit RPM packages.
mkdir -p %{buildroot}%{_bindir}
python_version=$(ls %{buildroot}%{cli_lib_dir}/lib/ | head -n 1)
# We make %{python_cmd} the default executable, but if there is a more precise match, such as python3.9, we prefer that.
printf "#!/usr/bin/env bash
bin_dir=\`cd \"\$(dirname \"\$BASH_SOURCE[0]\")\"; pwd\`
python_cmd=%{python_cmd}
Expand Down
4 changes: 3 additions & 1 deletion scripts/release/rpm/centos7.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ WORKDIR /azure-cli

COPY . .

# CentOS 7 only has 'python3' package, which is Python 3.6.
RUN dos2unix ./scripts/release/rpm/azure-cli.spec && \
REPO_PATH=$(pwd) CLI_VERSION=$cli_version rpmbuild -v -bb --clean scripts/release/rpm/azure-cli.spec && \
REPO_PATH=$(pwd) CLI_VERSION=$cli_version PYTHON_PACKAGE=python3 PYTHON_CMD=python3 \
rpmbuild -v -bb --clean scripts/release/rpm/azure-cli.spec && \
cp /root/rpmbuild/RPMS/x86_64/azure-cli-${cli_version}-1.*.x86_64.rpm /azure-cli-dev.rpm

FROM centos:${tag} AS execution-env
Expand Down
10 changes: 7 additions & 3 deletions scripts/release/rpm/mariner.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ FROM ${image}:${tag} AS build-env
ARG cli_version=dev

RUN tdnf update -y
RUN tdnf install -y binutils file rpm-build gcc libffi-devel python3-devel openssl-devel make diffutils patch dos2unix python3-virtualenv perl
RUN tdnf install -y binutils file rpm-build gcc libffi-devel python3-devel openssl-devel make diffutils patch dos2unix perl sed

WORKDIR /azure-cli

COPY . .

# Mariner only has 'python3' package. It has no version-specific packages, like 'python39'.
# - On Mariner 1.0, 'python3' is Python 3.7
# - On Mariner 2.0, 'python3' is Python 3.9
RUN dos2unix ./scripts/release/rpm/azure-cli.spec && \
REPO_PATH=$(pwd) CLI_VERSION=$cli_version rpmbuild -v -bb --clean scripts/release/rpm/azure-cli.spec && \
REPO_PATH=$(pwd) CLI_VERSION=$cli_version PYTHON_PACKAGE=python3 PYTHON_CMD=python3 \
rpmbuild -v -bb --clean scripts/release/rpm/azure-cli.spec && \
cp /usr/src/mariner/RPMS/x86_64/azure-cli-${cli_version}-1.x86_64.rpm /azure-cli-dev.rpm

FROM ${image}:${tag} AS execution-env

RUN tdnf update -y
RUN tdnf install -y python3 python3-virtualenv rpm
RUN tdnf install -y python3 rpm

COPY --from=build-env /azure-cli-dev.rpm ./
RUN rpm -i ./azure-cli-dev.rpm && \
Expand Down
8 changes: 5 additions & 3 deletions scripts/release/rpm/ubi8.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ FROM registry.access.redhat.com/ubi8/ubi:${tag} AS build-env
ARG cli_version=dev

RUN yum update -y
RUN yum install -y wget rpm-build gcc libffi-devel python3-devel openssl-devel make bash diffutils patch dos2unix python3-virtualenv perl
RUN yum install -y wget rpm-build gcc libffi-devel python39-devel openssl-devel make bash diffutils patch dos2unix perl

WORKDIR /azure-cli

COPY . .

# RHEL's 'python3' is Python 3.6. We have to explicitly specify 'python39' to install Python 3.9.
RUN dos2unix ./scripts/release/rpm/azure-cli.spec && \
REPO_PATH=$(pwd) CLI_VERSION=$cli_version rpmbuild -v -bb --clean scripts/release/rpm/azure-cli.spec && \
REPO_PATH=$(pwd) CLI_VERSION=$cli_version PYTHON_PACKAGE=python39 PYTHON_CMD=python3.9 \
rpmbuild -v -bb --clean scripts/release/rpm/azure-cli.spec && \
cp /root/rpmbuild/RPMS/x86_64/azure-cli-${cli_version}-1.*.x86_64.rpm /azure-cli-dev.rpm

FROM registry.access.redhat.com/ubi8/ubi:${tag} AS execution-env

RUN yum update -y
RUN yum install -y python3 python3-virtualenv
RUN yum install -y python39

COPY --from=build-env /azure-cli-dev.rpm ./
RUN rpm -i ./azure-cli-dev.rpm && \
Expand Down

0 comments on commit 22bd245

Please sign in to comment.