Skip to content

Commit a837ff3

Browse files
author
Stuart Padley
committed
Package RPM
1 parent fef1a31 commit a837ff3

File tree

8 files changed

+348
-0
lines changed

8 files changed

+348
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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: CmdLine@2
17+
displayName: 'Build ${{ parameters.OS }}/${{ parameters.Type }} distribution'
18+
inputs:
19+
script: release/${{ parameters.OS }}/${{ parameters.Type }}/pipeline.sh
20+
workingDirectory: $(Build.SourcesCliDirectory)
21+
env:
22+
BUILD_OUTPUT: $(Pipeline.Workspace)
23+
BUILD_STAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
24+
- task: EsrpCodeSigning@1
25+
inputs:
26+
ConnectedServiceName: 'Code Signing'
27+
FolderPath: $(Build.ArtifactStagingDirectory)
28+
Pattern: '*.${{ parameters.Type }}'
29+
signConfigType: 'inlineSignParams'
30+
inlineOperation: |
31+
[
32+
{
33+
"KeyCode" : "CP-450779-Pgp",
34+
"OperationCode" : "LinuxSign",
35+
"Parameters" : {},
36+
"ToolName" : "sign",
37+
"ToolVersion" : "1.0"
38+
}
39+
]
40+
SessionTimeout: '600'
41+
MaxConcurrency: '50'
42+
MaxRetryAttempts: '20'
43+
- task: PublishPipelineArtifact@0
44+
displayName: 'Publish Artifact: ${{ parameters.Type }}'
45+
inputs:
46+
targetPath: $(Build.ArtifactStagingDirectory)
47+
artifactName: ${{ parameters.Type }}
48+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
buildType: 'current'
12+
targetPath: '$(Pipeline.Workspace)'
13+
- task: CmdLine@2
14+
displayName: 'Test ${{ parameters.OS }}/${{ parameters.Type }} distribution'
15+
inputs:
16+
script: release/${{ parameters.OS }}/${{ parameters.Type }}/pipeline-test.sh
17+
workingDirectory: $(Build.SourcesCliDirectory)
18+
env:
19+
BUILD_STAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# sqlcmd package pipeline
2+
3+
trigger:
4+
tags:
5+
include:
6+
- v0.*
7+
8+
pr: none
9+
10+
variables:
11+
VERSION: '0.0.1'
12+
Build.SourcesCliDirectory: '$(Build.SourcesDirectory)/'
13+
14+
stages:
15+
- stage: CreatePackages
16+
displayName: Create and Test Package Matrix
17+
jobs:
18+
- job: CreateAndTestPackages
19+
strategy:
20+
matrix:
21+
rpm:
22+
imageName: 'ubuntu-latest'
23+
os: linux
24+
type: rpm
25+
pool:
26+
vmImage: $(imageName)
27+
steps:
28+
- template: package-common-create.yml
29+
parameters:
30+
OS: $(os)
31+
Type: $(type)
32+
- template: package-common-test.yml
33+
parameters:
34+
OS: $(os)
35+
Type: $(type)

release/linux/rpm/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+

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: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
find .. -iname "*.*" -type f
33+
34+
CLI_VERSION=${CLI_VERSION:=0.0.1}
35+
CLI_VERSION_REVISION=${CLI_VERSION_REVISION:=1}
36+
37+
BUILD_ARTIFACTSTAGINGDIRECTORY=${BUILD_ARTIFACTSTAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/rpm}
38+
39+
YUM_DISTRO_BASE_IMAGE=( centos:centos7 centos:centos8 fedora:29 fedora:30 fedora:31 )
40+
YUM_DISTRO_SUFFIX=( el7 el7 fc29 fc29 fc29 )
41+
42+
ZYPPER_DISTRO_BASE_IMAGE=( opensuse/leap:latest )
43+
ZYPPER_DISTRO_SUFFIX=( el7 )
44+
45+
echo "=========================================================="
46+
echo "__CLI_VERSION: ${CLI_VERSION}"
47+
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION}"
48+
echo "BUILD_ARTIFACTSTAGINGDIRECTORY: ${BUILD_ARTIFACTSTAGINGDIRECTORY}"
49+
echo "Distribution: ${YUM_DISTRO_BASE_IMAGE} ${ZYPPER_DISTRO_BASE_IMAGE}"
50+
echo "=========================================================="
51+
52+
# -- yum installs --
53+
for i in ${!YUM_DISTRO_BASE_IMAGE[@]}; do
54+
image=${YUM_DISTRO_BASE_IMAGE[$i]}
55+
suffix=${YUM_DISTRO_SUFFIX[$i]}
56+
57+
echo "=========================================================="
58+
echo "Test rpm package on ${image} .${suffix}"
59+
echo "=========================================================="
60+
rpmPkg=sqlcmd-${CLI_VERSION}-${CLI_VERSION_REVISION}.${suffix}.x86_64.rpm
61+
62+
# Per: https://techglimpse.com/failed-metadata-repo-appstream-centos-8/
63+
# change the mirrors to vault.centos.org where they will be archived permanently
64+
mirrors=""
65+
if [[ "${image}" == "centos:centos8" ]]; then
66+
mirrors="cd /etc/yum.repos.d/ && \
67+
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
68+
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* && \ "
69+
fi
70+
71+
script="${mirrors}
72+
rpm --import https://packages.microsoft.com/keys/microsoft.asc && \
73+
yum update -y && \
74+
yum localinstall /mnt/artifacts/${rpmPkg} -y && \
75+
sqlcmd --help"
76+
77+
docker pull ${image}
78+
docker run --rm -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}:/mnt/artifacts \
79+
${image} \
80+
/bin/bash -c "${script}"
81+
82+
echo ""
83+
done
84+
85+
# -- zypper installs --
86+
for i in ${!ZYPPER_DISTRO_BASE_IMAGE[@]}; do
87+
image=${ZYPPER_DISTRO_BASE_IMAGE[$i]}
88+
suffix=${ZYPPER_DISTRO_SUFFIX[$i]}
89+
90+
echo "=========================================================="
91+
echo "Test rpm package on ${image} .${suffix}"
92+
echo "=========================================================="
93+
rpmPkg=sqlcmd-${CLI_VERSION}-${CLI_VERSION_REVISION}.${suffix}.x86_64.rpm
94+
# If testing locally w/o signing, use `--allow-unsigned-rpm` but do not commit:
95+
# zypper --non-interactive install --allow-unsigned-rpm /mnt/artifacts/${rpmPkg} && \
96+
97+
script="zypper --non-interactive install curl && \
98+
rpm -v --import https://packages.microsoft.com/keys/microsoft.asc && \
99+
zypper --non-interactive install --allow-unsigned-rpm /mnt/artifacts/${rpmPkg} && \
100+
sqlcmd --help"
101+
102+
docker pull ${image}
103+
docker run --rm -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}:/mnt/artifacts \
104+
${image} \
105+
/bin/bash -c "${script}"
106+
107+
echo ""
108+
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+
find .. -iname "*.*" -type f
25+
26+
cp ${BUILD_OUTPUT}/SqlcmdLinuxAmd64/sqlcmd ${REPO_ROOT_DIR}/sqlcmd
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)