Skip to content

Commit 47a414b

Browse files
authored
Merge pull request #62 from microsoft/stuartpa/package-rpm
RPM/Yum/Zypper/Centos/Fedora/Suse packages
2 parents 1b77558 + 48bc3a7 commit 47a414b

File tree

9 files changed

+359
-1
lines changed

9 files changed

+359
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Binaries for programs and plugins
2-
*.exe
2+
output
3+
.exe
34
*.exe~
45
*.dll
56
*.so
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
parameters:
2+
- name: OS
3+
type: string
4+
default:
5+
- name: Type
6+
type: string
7+
8+
steps:
9+
- task: DownloadPipelineArtifact@2
10+
inputs:
11+
source: 'specific'
12+
project: 'ae14e11c-7eb2-46af-b588-471e6116d635'
13+
pipeline: 500
14+
runVersion: 'latest'
15+
targetPath: '$(Pipeline.Workspace)'
16+
- task: PowerShell@2
17+
displayName: Set last tag to variable
18+
inputs:
19+
targetType: 'inline'
20+
script: |
21+
$VERSION_TAG = git describe --tags (git rev-list --tags --max-count=1)
22+
$VERSION_TAG = $VERSION_TAG.substring(1) # Trim initial 'v'
23+
Write-Host("##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG")
24+
Write-Host($VERSION_TAG)
25+
- task: CmdLine@2
26+
displayName: 'Build ${{ parameters.OS }}/${{ parameters.Type }} distribution'
27+
inputs:
28+
script: release/${{ parameters.OS }}/${{ parameters.Type }}/pipeline.sh
29+
workingDirectory: $(Build.SourcesCliDirectory)
30+
env:
31+
CLI_VERSION: $(VERSION_TAG)
32+
BUILD_OUTPUT: $(Pipeline.Workspace)
33+
BUILD_STAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
34+
- task: EsrpCodeSigning@1
35+
inputs:
36+
ConnectedServiceName: 'Code Signing'
37+
FolderPath: $(Build.ArtifactStagingDirectory)
38+
Pattern: '*.${{ parameters.Type }}'
39+
signConfigType: 'inlineSignParams'
40+
inlineOperation: |
41+
[
42+
{
43+
"KeyCode" : "CP-450779-Pgp",
44+
"OperationCode" : "LinuxSign",
45+
"Parameters" : {},
46+
"ToolName" : "sign",
47+
"ToolVersion" : "1.0"
48+
}
49+
]
50+
SessionTimeout: '600'
51+
MaxConcurrency: '50'
52+
MaxRetryAttempts: '20'
53+
- task: PublishPipelineArtifact@0
54+
displayName: 'Publish Artifact: ${{ parameters.Type }}'
55+
inputs:
56+
targetPath: $(Build.ArtifactStagingDirectory)
57+
artifactName: ${{ parameters.Type }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
parameters:
2+
- name: OS
3+
type: string
4+
default:
5+
- name: Type
6+
type: string
7+
8+
steps:
9+
- task: PowerShell@2
10+
displayName: Set last tag to variable
11+
inputs:
12+
targetType: 'inline'
13+
script: |
14+
$VERSION_TAG = git describe --tags (git rev-list --tags --max-count=1)
15+
$VERSION_TAG = $VERSION_TAG.substring(1) # Trim initial 'v'
16+
Write-Host("##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG")
17+
Write-Host($VERSION_TAG)
18+
- task: CmdLine@2
19+
displayName: 'Test ${{ parameters.OS }}/${{ parameters.Type }} distribution'
20+
inputs:
21+
script: release/${{ parameters.OS }}/${{ parameters.Type }}/pipeline-test.sh
22+
workingDirectory: $(Build.SourcesCliDirectory)
23+
env:
24+
CLI_VERSION: $(VERSION_TAG)
25+
BUILD_STAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# sqlcmd package pipeline
2+
3+
pr: none
4+
5+
variables:
6+
Build.SourcesCliDirectory: '$(Build.SourcesDirectory)/'
7+
8+
stages:
9+
- stage: CreatePackages
10+
displayName: Create and Test Package Matrix
11+
jobs:
12+
- job: Package
13+
strategy:
14+
matrix:
15+
rpm:
16+
imageName: 'ubuntu-latest'
17+
os: linux
18+
type: rpm
19+
pool:
20+
vmImage: $(imageName)
21+
steps:
22+
- template: package-common-create.yml
23+
parameters:
24+
OS: $(os)
25+
Type: $(type)
26+
- template: package-common-test.yml
27+
parameters:
28+
OS: $(os)
29+
Type: $(type)
30+

release/linux/rpm/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
RPM Release
2+
3+
## Building RPM in CI/CD pipeline
4+
5+
Execute the following command from the root directory of this repository:
6+
7+
``` bash
8+
./release/linux/rpm/pipeline.sh
9+
```
10+
Output will be sent to `./output/rpm`
11+
12+
To test the packages:
13+
14+
``` bash
15+
./release/linux/rpm/pipeline-test.sh
16+
```
17+
18+

release/linux/rpm/build-rpm.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
#------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation.
5+
# Licensed under the MIT license.
6+
#------------------------------------------------------------------------------
7+
8+
# Description:
9+
#
10+
# Build a rpm `sqlcmd` package. This script is intended to be run in a
11+
# container with the respective distro/image laid down.
12+
#
13+
# Usage:
14+
# $ build-rpm.sh
15+
16+
set -exv
17+
18+
: "${CLI_VERSION:?CLI_VERSION environment variable not set.}"
19+
: "${CLI_VERSION_REVISION:?CLI_VERSION_REVISION environment variable not set.}"
20+
21+
yum update -y
22+
yum install -y rpm-build
23+
24+
export LC_ALL=en_US.UTF-8
25+
export REPO_ROOT_DIR=`cd $(dirname $0); cd ../../../; pwd`
26+
27+
rpmbuild -v -bb --clean ${REPO_ROOT_DIR}/release/linux/rpm/sqlcmd.spec && cp /root/rpmbuild/RPMS/x86_64/* /mnt/output

release/linux/rpm/pipeline-test.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
3+
#------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation.
5+
# Licensed under the MIT license.
6+
#------------------------------------------------------------------------------
7+
8+
# Description:
9+
#
10+
# Instructions to be invoked under the build CI pipeline in AzureDevOps.
11+
#
12+
# Kickoff rpm package tests against versions:
13+
#
14+
# -----------------------------------
15+
# centos:centos8
16+
# centos:centos7
17+
# -----------------------------------
18+
# fedora:31
19+
# fedora:30
20+
# fedora:29
21+
# -----------------------------------
22+
# opensuse/leap:latest
23+
# -----------------------------------
24+
#
25+
# Usage:
26+
# $ pipeline-test.sh
27+
28+
set -exv
29+
30+
: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
31+
32+
CLI_VERSION=${CLI_VERSION:=0.0.1}
33+
CLI_VERSION_REVISION=${CLI_VERSION_REVISION:=1}
34+
35+
BUILD_ARTIFACTSTAGINGDIRECTORY=${BUILD_ARTIFACTSTAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/rpm}
36+
37+
YUM_DISTRO_BASE_IMAGE=( centos:centos7 centos:centos8 fedora:29 fedora:30 fedora:31 )
38+
YUM_DISTRO_SUFFIX=( el7 el7 fc29 fc29 fc29 )
39+
40+
ZYPPER_DISTRO_BASE_IMAGE=( opensuse/leap:latest )
41+
ZYPPER_DISTRO_SUFFIX=( el7 )
42+
43+
echo "=========================================================="
44+
echo "CLI_VERSION: ${CLI_VERSION}"
45+
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION}"
46+
echo "BUILD_ARTIFACTSTAGINGDIRECTORY: ${BUILD_ARTIFACTSTAGINGDIRECTORY}"
47+
echo "Distribution: ${YUM_DISTRO_BASE_IMAGE} ${ZYPPER_DISTRO_BASE_IMAGE}"
48+
echo "=========================================================="
49+
50+
# -- yum installs --
51+
for i in ${!YUM_DISTRO_BASE_IMAGE[@]}; do
52+
image=${YUM_DISTRO_BASE_IMAGE[$i]}
53+
suffix=${YUM_DISTRO_SUFFIX[$i]}
54+
55+
echo "=========================================================="
56+
echo "Test rpm package on ${image} .${suffix}"
57+
echo "=========================================================="
58+
rpmPkg=sqlcmd-${CLI_VERSION}-${CLI_VERSION_REVISION}.${suffix}.x86_64.rpm
59+
60+
# Per: https://techglimpse.com/failed-metadata-repo-appstream-centos-8/
61+
# change the mirrors to vault.centos.org where they will be archived permanently
62+
mirrors=""
63+
if [[ "${image}" == "centos:centos8" ]]; then
64+
mirrors="cd /etc/yum.repos.d/ && \
65+
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
66+
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* && \ "
67+
fi
68+
69+
script="${mirrors}
70+
rpm --import https://packages.microsoft.com/keys/microsoft.asc && \
71+
yum update -y && \
72+
yum localinstall /mnt/artifacts/${rpmPkg} -y && \
73+
sqlcmd --help"
74+
75+
docker pull ${image}
76+
docker run --rm -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}:/mnt/artifacts \
77+
${image} \
78+
/bin/bash -c "${script}"
79+
80+
echo ""
81+
done
82+
83+
# -- zypper installs --
84+
for i in ${!ZYPPER_DISTRO_BASE_IMAGE[@]}; do
85+
image=${ZYPPER_DISTRO_BASE_IMAGE[$i]}
86+
suffix=${ZYPPER_DISTRO_SUFFIX[$i]}
87+
88+
echo "=========================================================="
89+
echo "Test rpm package on ${image} .${suffix}"
90+
echo "=========================================================="
91+
rpmPkg=sqlcmd-${CLI_VERSION}-${CLI_VERSION_REVISION}.${suffix}.x86_64.rpm
92+
# If testing locally w/o signing, use `--allow-unsigned-rpm` but do not commit:
93+
# zypper --non-interactive install --allow-unsigned-rpm /mnt/artifacts/${rpmPkg} && \
94+
95+
script="zypper --non-interactive install curl && \
96+
rpm -v --import https://packages.microsoft.com/keys/microsoft.asc && \
97+
zypper --non-interactive install /mnt/artifacts/${rpmPkg} && \
98+
sqlcmd --help"
99+
100+
docker pull ${image}
101+
docker run --rm -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}:/mnt/artifacts \
102+
${image} \
103+
/bin/bash -c "${script}"
104+
105+
echo ""
106+
done

release/linux/rpm/pipeline.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation.
4+
# Licensed under the MIT license.
5+
#------------------------------------------------------------------------------
6+
7+
# Description:
8+
#
9+
# Instructions to be invoked under the build CI pipeline in AzureDevOps.
10+
#
11+
# Kickoff rpm package build. The build pipeline can then save it as an
12+
# artifact as it sees fit.
13+
#
14+
# Usage:
15+
#
16+
# foundation images: `centos:centos7|fedora:29`
17+
#
18+
# $ pipeline.sh
19+
20+
set -exv
21+
22+
: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
23+
24+
if [[ "${BUILD_OUTPUT}" != "" ]]; then
25+
cp ${BUILD_OUTPUT}/SqlcmdLinuxAmd64/sqlcmd ${REPO_ROOT_DIR}/sqlcmd
26+
fi
27+
28+
DIST_DIR=${BUILD_STAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/rpm}
29+
DISTRO_BASE_IMAGE=( centos:centos7 fedora:29 )
30+
31+
CLI_VERSION=${CLI_VERSION:=0.0.1}
32+
33+
echo "=========================================================="
34+
echo "CLI_VERSION: ${CLI_VERSION}"
35+
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION:=1}"
36+
echo "Distribution Image: ${DISTRO_BASE_IMAGE}"
37+
echo "Output location: ${DIST_DIR}"
38+
echo "=========================================================="
39+
40+
mkdir -p ${DIST_DIR} || exit 1
41+
42+
for i in ${!DISTRO_BASE_IMAGE[@]}; do
43+
image=${DISTRO_BASE_IMAGE[$i]}
44+
45+
echo "=========================================================="
46+
echo "Build rpm on ${image}"
47+
echo "=========================================================="
48+
49+
docker run --rm \
50+
-v "${REPO_ROOT_DIR}":/mnt/repo \
51+
-v "${DIST_DIR}":/mnt/output \
52+
-v "${PIPELINE_WORKSPACE}":/mnt/workspace \
53+
-e CLI_VERSION=${CLI_VERSION} \
54+
-e CLI_VERSION_REVISION=${CLI_VERSION_REVISION:=1} \
55+
"${image}" \
56+
/mnt/repo/release/linux/rpm/build-rpm.sh
57+
done

release/linux/rpm/sqlcmd.spec

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# RPM spec file for sqlcmd
2+
# Definition of macros used - https://fedoraproject.org/wiki/Packaging:RPMMacros?rd=Packaging/RPMMacros
3+
4+
# .el7.centos -> .el7
5+
%if 0%{?rhel}
6+
%define dist .el%{?rhel}
7+
%endif
8+
9+
%define name sqlcmd
10+
%define release 1%{?dist}
11+
%define version %{getenv:CLI_VERSION}
12+
%define repo_path %{getenv:REPO_ROOT_DIR}
13+
%define cli_lib_dir %{_libdir}/sqlcmd
14+
15+
%undefine _missing_build_ids_terminate_build
16+
%global _missing_build_ids_terminate_build 0
17+
18+
Summary: MSSQL SQLCMD CLI Tools
19+
License: https://github.com/microsoft/go-sqlcmd/blob/main/LICENSE
20+
Name: %{name}
21+
Version: %{version}
22+
Release: %{release}
23+
Url: https://github.com/microsoft/go-sqlcmd
24+
BuildArch: x86_64
25+
26+
%description
27+
SQLCMD CLI, a multi-platform command line experience for Microsoft SQL Server and Azure SQL.
28+
29+
%prep
30+
%install
31+
32+
# Create executable
33+
mkdir -p %{buildroot}%{_bindir}
34+
cp %{repo_path}/sqlcmd %{buildroot}%{_bindir}
35+
36+
%files
37+
%attr(0755,root,root) %{_bindir}/sqlcmd

0 commit comments

Comments
 (0)