From 74c2205a58342047d7c786d962ffdf5bca57442e Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Thu, 6 Jan 2022 21:11:29 +0800 Subject: [PATCH 1/9] el8 --- azure-pipelines.yml | 12 ++++++++-- .../{Dockerfile.centos => Dockerfile.centos7} | 0 scripts/release/rpm/Dockerfile.centos_stream8 | 24 +++++++++++++++++++ scripts/release/rpm/pipeline.sh | 24 +++++++++++-------- 4 files changed, 48 insertions(+), 12 deletions(-) rename scripts/release/rpm/{Dockerfile.centos => Dockerfile.centos7} (100%) create mode 100644 scripts/release/rpm/Dockerfile.centos_stream8 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ab0971455ae..c00f9bd3183 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -700,17 +700,25 @@ jobs: displayName: Build Yum Package pool: vmImage: 'ubuntu-20.04' + strategy: + matrix: + CentOS7: + image: centos7 + CentOSStream8: + image: centos_stream8 steps: - task: Bash@3 displayName: 'Build Rpm Package' inputs: targetType: 'filePath' filePath: scripts/release/rpm/pipeline.sh + env: + IMAGE: $(image) - task: PublishPipelineArtifact@0 displayName: 'Publish Artifact: yum' inputs: TargetPath: $(Build.ArtifactStagingDirectory) - ArtifactName: yum + ArtifactName: yum-$(image) - job: TestYumPackage @@ -732,7 +740,7 @@ jobs: displayName: 'Download Build Artifacts' inputs: TargetPath: '$(Build.ArtifactStagingDirectory)/yum' - artifactName: yum + artifactName: yum-centos7 - bash: | diff --git a/scripts/release/rpm/Dockerfile.centos b/scripts/release/rpm/Dockerfile.centos7 similarity index 100% rename from scripts/release/rpm/Dockerfile.centos rename to scripts/release/rpm/Dockerfile.centos7 diff --git a/scripts/release/rpm/Dockerfile.centos_stream8 b/scripts/release/rpm/Dockerfile.centos_stream8 new file mode 100644 index 00000000000..c1883ca30d9 --- /dev/null +++ b/scripts/release/rpm/Dockerfile.centos_stream8 @@ -0,0 +1,24 @@ +ARG tag=stream8 + +FROM quay.io/centos/centos:${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 + +WORKDIR /azure-cli + +COPY . . + +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 && \ + cp /root/rpmbuild/RPMS/x86_64/azure-cli-${cli_version}-1.*.x86_64.rpm /azure-cli-dev.rpm + +FROM quay.io/centos/centos:${tag} AS execution-env + +RUN yum update -y +RUN yum install -y python3 python3-virtualenv + +COPY --from=build-env /azure-cli-dev.rpm ./ +RUN rpm -i ./azure-cli-dev.rpm && \ + az --version diff --git a/scripts/release/rpm/pipeline.sh b/scripts/release/rpm/pipeline.sh index 237335bcb16..9564c4b968b 100755 --- a/scripts/release/rpm/pipeline.sh +++ b/scripts/release/rpm/pipeline.sh @@ -6,34 +6,38 @@ set -exv : "${BUILD_STAGINGDIRECTORY:?BUILD_STAGINGDIRECTORY environment variable not set.}" +# IMAGE should be one of 'centos7', 'centos_stream8' +: "${IMAGE:?IMAGE environment variable not set.}" + CLI_VERSION=`cat src/azure-cli/azure/cli/__main__.py | grep __version__ | sed s/' '//g | sed s/'__version__='// | sed s/\"//g` # Create a container image that includes the source code and a built RPM using this file. docker build \ --target build-env \ --build-arg cli_version=${CLI_VERSION} \ - -f ./scripts/release/rpm/Dockerfile.centos \ - -t azure/azure-cli:centos7-builder \ + -f ./scripts/release/rpm/Dockerfile.${IMAGE} \ + -t azure/azure-cli:${IMAGE}-builder \ . # Continue the previous build, and create a container that has the current azure-cli build but not the source code. docker build \ --build-arg cli_version=${CLI_VERSION} \ - -f ./scripts/release/rpm/Dockerfile.centos \ - -t azure/azure-cli:centos7 \ + -f ./scripts/release/rpm/Dockerfile.${IMAGE} \ + -t azure/azure-cli:${IMAGE} \ . # Extract the built RPM so that it can be distributed independently. -docker run \ - azure/azure-cli:centos7-builder \ - cat /root/rpmbuild/RPMS/x86_64/azure-cli-${CLI_VERSION}-1.el7.x86_64.rpm \ - > ${BUILD_STAGINGDIRECTORY}/azure-cli-${CLI_VERSION}-1.el7.x86_64.rpm +# The RPM file looks like azure-cli-2.32.0-1.el7.x86_64.rpm +id=$(docker create azure/azure-cli:centos7-builder) +# https://docs.docker.com/engine/reference/commandline/cp/ +# Append /. so that the x86_64 folder's content is copied, instead of x86_64 folder itself. +docker cp $id:/root/rpmbuild/RPMS/x86_64/. ${BUILD_STAGINGDIRECTORY} # Save these too a staging directory so that later build phases can choose to save them as Artifacts or publish them to # a registry. # # The products of `docker save` can be rehydrated using `docker load`. mkdir -p ${BUILD_STAGINGDIRECTORY}/docker -docker save azure/azure-cli:centos7-builder | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_centos7-builder.tar.gz & -docker save azure/azure-cli:centos7 | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_centos7.tar.gz & +docker save azure/azure-cli:${IMAGE}-builder | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_${IMAGE}-builder.tar.gz & +docker save azure/azure-cli:${IMAGE} | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_${IMAGE}.tar.gz & wait From 521ceeac72f5fb0b9e7b028c3ddfe1e40ceae33f Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Thu, 6 Jan 2022 22:22:06 +0800 Subject: [PATCH 2/9] update --- scripts/release/rpm/pipeline.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release/rpm/pipeline.sh b/scripts/release/rpm/pipeline.sh index 9564c4b968b..ecc4e1dbd83 100755 --- a/scripts/release/rpm/pipeline.sh +++ b/scripts/release/rpm/pipeline.sh @@ -28,7 +28,7 @@ docker build \ # Extract the built RPM so that it can be distributed independently. # The RPM file looks like azure-cli-2.32.0-1.el7.x86_64.rpm -id=$(docker create azure/azure-cli:centos7-builder) +id=$(docker create azure/azure-cli:${IMAGE}-builder) # https://docs.docker.com/engine/reference/commandline/cp/ # Append /. so that the x86_64 folder's content is copied, instead of x86_64 folder itself. docker cp $id:/root/rpmbuild/RPMS/x86_64/. ${BUILD_STAGINGDIRECTORY} From 36d3389424ea56be3e8d9573bbcedb330cce24ea Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:01:51 +0800 Subject: [PATCH 3/9] Add comment --- scripts/release/rpm/Dockerfile.centos_stream8 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/release/rpm/Dockerfile.centos_stream8 b/scripts/release/rpm/Dockerfile.centos_stream8 index c1883ca30d9..dbeec42fc8b 100644 --- a/scripts/release/rpm/Dockerfile.centos_stream8 +++ b/scripts/release/rpm/Dockerfile.centos_stream8 @@ -1,3 +1,6 @@ +# CentOS Stream 8 docker image is distributed as quay.io/centos/centos:stream8 at +# https://quay.io/repository/centos/centos?tab=tags. See https://wiki.centos.org/FAQ/CentOSStream + ARG tag=stream8 FROM quay.io/centos/centos:${tag} AS build-env From ec44277ff5dd5d7cecb2eff9ffd298c25bced021 Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:57:41 +0800 Subject: [PATCH 4/9] comment out docker save --- scripts/release/rpm/pipeline.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/release/rpm/pipeline.sh b/scripts/release/rpm/pipeline.sh index ecc4e1dbd83..cce6a558343 100755 --- a/scripts/release/rpm/pipeline.sh +++ b/scripts/release/rpm/pipeline.sh @@ -37,7 +37,7 @@ docker cp $id:/root/rpmbuild/RPMS/x86_64/. ${BUILD_STAGINGDIRECTORY} # a registry. # # The products of `docker save` can be rehydrated using `docker load`. -mkdir -p ${BUILD_STAGINGDIRECTORY}/docker -docker save azure/azure-cli:${IMAGE}-builder | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_${IMAGE}-builder.tar.gz & -docker save azure/azure-cli:${IMAGE} | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_${IMAGE}.tar.gz & -wait +# mkdir -p ${BUILD_STAGINGDIRECTORY}/docker +# docker save azure/azure-cli:${IMAGE}-builder | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_${IMAGE}-builder.tar.gz & +# docker save azure/azure-cli:${IMAGE} | gzip > ${BUILD_STAGINGDIRECTORY}/docker/azure_azure-cli_${IMAGE}.tar.gz & +# wait From 3ca5d20940986100cc69c499fe74cacd4865feaa Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Wed, 9 Feb 2022 14:59:43 +0800 Subject: [PATCH 5/9] Rename yum to rpm --- azure-pipelines.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2555f844017..f06c7c87c14 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -680,8 +680,8 @@ jobs: displayName: 'Test Homebrew Package' -- job: BuildYumPackageMariner - displayName: Build Yum Package Mariner +- job: BuildRpmPackageMariner + displayName: Build Rpm Package Mariner pool: vmImage: 'ubuntu-20.04' steps: @@ -691,14 +691,14 @@ jobs: targetType: 'filePath' filePath: scripts/release/rpm/pipeline_mariner.sh - task: PublishPipelineArtifact@0 - displayName: 'Publish Artifact: yum-mariner' + displayName: 'Publish Artifact: rpm-mariner' inputs: TargetPath: $(Build.ArtifactStagingDirectory) - ArtifactName: yum-mariner + ArtifactName: rpm-mariner -- job: BuildYumPackage - displayName: Build Yum Package +- job: BuildRpmPackage + displayName: Build Rpm Package pool: vmImage: 'ubuntu-20.04' strategy: @@ -716,16 +716,16 @@ jobs: env: IMAGE: $(image) - task: PublishPipelineArtifact@0 - displayName: 'Publish Artifact: yum' + displayName: 'Publish Artifact: rpm' inputs: TargetPath: $(Build.ArtifactStagingDirectory) - ArtifactName: yum-$(image) + ArtifactName: rpm-$(image) -- job: TestYumPackage - displayName: Test Yum Package +- job: TestRpmPackage + displayName: Test Rpm Package timeoutInMinutes: 120 - dependsOn: BuildYumPackage + dependsOn: BuildRpmPackage condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')) pool: vmImage: 'ubuntu-20.04' @@ -740,24 +740,24 @@ jobs: - task: DownloadPipelineArtifact@1 displayName: 'Download Build Artifacts' inputs: - TargetPath: '$(Build.ArtifactStagingDirectory)/yum' - artifactName: yum-centos7 + TargetPath: '$(Build.ArtifactStagingDirectory)/rpm' + artifactName: rpm-centos7 - bash: | set -ex CLI_VERSION=`cat $SYSTEM_ARTIFACTSDIRECTORY/metadata/version` - YUM_NAME=azure-cli-$CLI_VERSION-1.el7.x86_64.rpm - YUM_FILE=$SYSTEM_ARTIFACTSDIRECTORY/yum/$YUM_NAME + RPM_NAME=azure-cli-$CLI_VERSION-1.el7.x86_64.rpm + RPM_FILE=$SYSTEM_ARTIFACTSDIRECTORY/rpm/RPM_NAME - echo "== Test yum package on CentOS ==" + echo "== Test rpm package on CentOS ==" IMAGE=centos:centos7 docker pull $IMAGE - docker run --rm -e YUM_NAME=$YUM_NAME -v $SYSTEM_ARTIFACTSDIRECTORY/yum:/mnt/yum -v $(pwd):/azure-cli $IMAGE /bin/bash "/azure-cli/scripts/release/rpm/test_rpm_in_docker.sh" + docker run --rm -e RPM_NAME=$RPM_NAME -v $SYSTEM_ARTIFACTSDIRECTORY/rpm:/mnt/rpm -v $(pwd):/azure-cli $IMAGE /bin/bash "/azure-cli/scripts/release/rpm/test_rpm_in_docker.sh" - displayName: 'Test Yum Package' + displayName: 'Test Rpm Package' - job: BuildDebPackages displayName: Build Deb Packages From 340c4bee027785d8c7eb90cba4f992b1814126d5 Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Wed, 9 Feb 2022 15:49:23 +0800 Subject: [PATCH 6/9] Do not use matrix --- azure-pipelines.yml | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bba817fc10e..cc6ec76b537 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -698,16 +698,29 @@ jobs: ArtifactName: rpm-mariner -- job: BuildRpmPackage - displayName: Build Rpm Package +- job: BuildRpmPackageCentOS7 + displayName: Build Rpm Package CentOS 7 + pool: + vmImage: 'ubuntu-20.04' + steps: + - task: Bash@3 + displayName: 'Build Rpm Package' + inputs: + targetType: 'filePath' + filePath: scripts/release/rpm/pipeline.sh + env: + IMAGE: centos7 + - task: PublishPipelineArtifact@0 + displayName: 'Publish Artifact: rpm' + inputs: + TargetPath: $(Build.ArtifactStagingDirectory) + ArtifactName: rpm-centos7 + + +- job: BuildRpmPackageCentOSStream8 + displayName: Build Rpm Package CentOS Stream 8 pool: vmImage: 'ubuntu-20.04' - strategy: - matrix: - CentOS7: - image: centos7 - CentOSStream8: - image: centos_stream8 steps: - task: Bash@3 displayName: 'Build Rpm Package' @@ -715,18 +728,18 @@ jobs: targetType: 'filePath' filePath: scripts/release/rpm/pipeline.sh env: - IMAGE: $(image) + IMAGE: centos_stream8 - task: PublishPipelineArtifact@0 displayName: 'Publish Artifact: rpm' inputs: TargetPath: $(Build.ArtifactStagingDirectory) - ArtifactName: rpm-$(image) + ArtifactName: rpm-centos_stream8 - job: TestRpmPackage displayName: Test Rpm Package timeoutInMinutes: 120 - dependsOn: BuildRpmPackage + dependsOn: BuildRpmPackageCentOS7 condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')) pool: vmImage: 'ubuntu-20.04' From 0b6287ce14dfee8d7b9888dd3eca90a50bacecd5 Mon Sep 17 00:00:00 2001 From: Jiashuo Li <4003950+jiasli@users.noreply.github.com> Date: Wed, 9 Feb 2022 15:58:25 +0800 Subject: [PATCH 7/9] Update azure-pipelines.yml Co-authored-by: ZelinWang --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cc6ec76b537..ed660bf0153 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -763,7 +763,7 @@ jobs: CLI_VERSION=`cat $SYSTEM_ARTIFACTSDIRECTORY/metadata/version` RPM_NAME=azure-cli-$CLI_VERSION-1.el7.x86_64.rpm - RPM_FILE=$SYSTEM_ARTIFACTSDIRECTORY/rpm/RPM_NAME + RPM_FILE=$SYSTEM_ARTIFACTSDIRECTORY/rpm/$RPM_NAME echo "== Test rpm package on CentOS ==" From 7a6e98cc42c3cfdf4155dd941a338c104fb661a0 Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:47:31 +0800 Subject: [PATCH 8/9] update --- azure-pipelines.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 154527df389..26a150877bd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -725,6 +725,8 @@ jobs: - job: BuildRpmPackageCentOS7 displayName: Build Rpm Package CentOS 7 + # Uncomment this line to disable this job on Pull Requests + # condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')) pool: vmImage: 'ubuntu-20.04' steps: @@ -745,9 +747,12 @@ jobs: TargetPath: $(Build.ArtifactStagingDirectory) ArtifactName: rpm-centos7 - +# rpmbuild on CentOS Stream 8 is slow, we use a separate job for CentOS Stream 8 instead of strategy.matrix so that +# TestRpmPackage can start right after BuildRpmPackageCentOS7 finishes. - job: BuildRpmPackageCentOSStream8 displayName: Build Rpm Package CentOS Stream 8 + # Do not run this job for Pull Requests due to the slowness + condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')) pool: vmImage: 'ubuntu-20.04' steps: @@ -758,6 +763,10 @@ jobs: filePath: scripts/release/rpm/pipeline.sh env: IMAGE: centos_stream8 + - task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0 + displayName: 'SBOM' + inputs: + BuildDropPath: $(Build.ArtifactStagingDirectory) - task: PublishPipelineArtifact@0 displayName: 'Publish Artifact: rpm' inputs: From 5050e7eec41d78a16d3a7fc80f53f42b7d951f31 Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Fri, 11 Mar 2022 14:57:49 +0800 Subject: [PATCH 9/9] Update test_rpm_in_docker.sh --- scripts/release/rpm/test_rpm_in_docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release/rpm/test_rpm_in_docker.sh b/scripts/release/rpm/test_rpm_in_docker.sh index 9804a04209a..79784d2335d 100644 --- a/scripts/release/rpm/test_rpm_in_docker.sh +++ b/scripts/release/rpm/test_rpm_in_docker.sh @@ -5,7 +5,7 @@ set -exv export USERNAME=azureuser -yum --nogpgcheck localinstall /mnt/yum/$YUM_NAME -y +yum --nogpgcheck localinstall /mnt/rpm/$RPM_NAME -y yum install git gcc python3-devel -y