Skip to content

Commit ae76afc

Browse files
author
Stuart Padley
committed
Package Deb
1 parent 47a414b commit ae76afc

File tree

7 files changed

+407
-3
lines changed

7 files changed

+407
-3
lines changed

build/azure-pipelines/package-product.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ stages:
1515
rpm:
1616
imageName: 'ubuntu-latest'
1717
os: linux
18-
type: rpm
18+
type: rpm
19+
debian:
20+
imageName: 'ubuntu-latest'
21+
os: linux
22+
type: deb
1923
pool:
2024
vmImage: $(imageName)
2125
steps:
@@ -27,4 +31,3 @@ stages:
2731
parameters:
2832
OS: $(os)
2933
Type: $(type)
30-

release/linux/deb/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Debian Packaging Release
2+
3+
## Building the Debian package
4+
5+
Execute the following command from the root directory of this repository:
6+
7+
``` bash
8+
./release/linux/debian/pipeline.sh
9+
```
10+
11+
Output will be sent to `./output/debian`
12+
13+
## Dev Installation and Verification
14+
15+
``` bash
16+
./release/linux/debian/pipeline-test.sh
17+
```
18+
19+
## Release Install/Update/Uninstall Steps
20+
21+
> **Note:** Replace `{{HOST}}` and `{{CLI_VERSION}}` with the appropriate values.
22+
23+
### Install sqlcmd with apt (Ubuntu or Debian)
24+
25+
1. Download and install the signing key:
26+
27+
```bash
28+
sudo curl -sL http://{{HOST}}/browse/repo/ubuntu/dpgswdist.v1.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/dpgswdist.v1.asc.gpg > /dev/null
29+
```
30+
31+
2. Add the sqlcmd repository information:
32+
33+
```bash
34+
sudo echo "deb [trusted=yes arch=amd64] http://{{HOST}}/browse/repo/ubuntu/sqlcmd mssql main" | tee /etc/apt/sources.list.d/sqlcmd.list
35+
```
36+
37+
3. Update repository information and install sqlcmd:
38+
39+
```bash
40+
sudo apt-get update
41+
sudo apt-get install sqlcmd
42+
```
43+
44+
5. Verify installation success:
45+
46+
```bash
47+
sqlcmd --help
48+
```
49+
50+
### Update
51+
52+
1. Upgrade sqlcmd only:
53+
54+
```bash
55+
sudo apt-get update && sudo apt-get install --only-upgrade -y sqlcmd
56+
```
57+
58+
### Uninstall
59+
60+
1. Uninstall with apt-get remove:
61+
62+
```bash
63+
sudo apt-get remove -y sqlcmd
64+
```
65+
66+
2. Remove the sqlcmd repository information:
67+
68+
> Note: This step is not needed if you plan on installing sqlcmd in the future
69+
70+
```bash
71+
sudo rm /etc/apt/sources.list.d/sqlcmd.list
72+
```
73+
74+
3. Remove the signing key:
75+
76+
```bash
77+
sudo rm /etc/apt/trusted.gpg.d/dpgswdist.v1.asc.gpg
78+
```
79+
80+
4. Remove any unneeded dependencies that were installed with sqlcmd:
81+
82+
```bash
83+
sudo apt autoremove
84+
```

release/linux/deb/build-pkg.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+
#------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation.
5+
# Licensed under the MIT license.
6+
#------------------------------------------------------------------------------
7+
8+
# Description:
9+
#
10+
# Build a debian/ubuntu `sqlcmd` package. This script is intended to be ran in a
11+
# container with the respective disto/image laid down.
12+
#
13+
# Usage:
14+
# $ build-pkg.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+
WORKDIR=`cd $(dirname $0); cd ../../../; pwd`
22+
23+
ls -la ${WORKDIR}
24+
25+
apt-get -y update || exit 1
26+
export DEBIAN_FRONTEND=noninteractive
27+
apt-get install -y \
28+
debhelper \
29+
dpkg-dev \
30+
locales || exit 1
31+
32+
# Locale
33+
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
34+
dpkg-reconfigure --frontend=noninteractive locales && \
35+
update-locale LANG=en_US.UTF-8
36+
37+
export LANG=en_US.UTF-8
38+
export PATH=$PATH
39+
40+
# Verify
41+
chmod u+x /mnt/workspace/sqlcmd
42+
/mnt/workspace/sqlcmd --help
43+
44+
mkdir /opt/stage
45+
cp /mnt/workspace/sqlcmd /opt/stage/sqlcmd
46+
47+
# Create create directory for debian build
48+
mkdir -p ${WORKDIR}/debian
49+
${WORKDIR}/release/linux/deb/prepare-rules.sh ${WORKDIR}/debian ${WORKDIR}
50+
51+
cd ${WORKDIR}
52+
dpkg-buildpackage -us -uc
53+
54+
ls ${WORKDIR} -R
55+
56+
debPkg=${WORKDIR}/../sqlcmd_${CLI_VERSION}-${CLI_VERSION_REVISION:=1}_all.deb
57+
cp ${debPkg} /mnt/output/

release/linux/deb/pipeline-test.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 Debian package tests against versions:
13+
#
14+
# Usage:
15+
# -----------------------------------
16+
# buster - Debian 10
17+
# stretch - Debian 9
18+
# jessie - Debian 8
19+
# -----------------------------------
20+
# focal - Ubuntu 20.04
21+
# bionic - Ubuntu 18.04
22+
# xenial - Ubuntu 16.04
23+
# -----------------------------------
24+
#
25+
# Usage:
26+
# $ pipeline-test.sh
27+
28+
set -e #xv
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+
BUILD_ARTIFACTSTAGINGDIRECTORY=${BUILD_ARTIFACTSTAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/debian}
35+
36+
DISTROS=( buster focal ) # TODO: Should we validate against more distros?: buster stretch jessie bionic xenial focal
37+
BASE_IMAGES=( debian:buster ubuntu:focal ) # TODO: debian:buster debian:stretch debian:jessie ubuntu:bionic ubuntu:xenial ubuntu:focal
38+
39+
echo "=========================================================="
40+
echo "CLI_VERSION: ${CLI_VERSION}"
41+
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION}"
42+
echo "BUILD_ARTIFACTSTAGINGDIRECTORY: ${BUILD_ARTIFACTSTAGINGDIRECTORY}"
43+
echo "Distribution: ${DISTROS}"
44+
echo "=========================================================="
45+
46+
for i in ${!DISTROS[@]}; do
47+
echo "=========================================================="
48+
echo "Test debian package on ${DISTROS[$i]}"
49+
echo "=========================================================="
50+
51+
debPkg=sqlcmd_${CLI_VERSION}-${CLI_VERSION_REVISION}~${DISTROS[$i]}_all.deb
52+
53+
script="apt-get update && \
54+
dpkg -i /mnt/artifacts/${debPkg} && \
55+
apt-get -f install && \
56+
sqlcmd --help"
57+
58+
docker pull ${BASE_IMAGES[$i]}
59+
docker run --rm -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}:/mnt/artifacts \
60+
${BASE_IMAGES[$i]} \
61+
/bin/bash -c "${script}"
62+
63+
echo ""
64+
done

release/linux/deb/pipeline.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 debian package build in docker and copy the .deb package artifact
13+
# back to the local filesystem. The build pipeline can then save it as an
14+
# artifact as it sees fit.
15+
#
16+
# Note: Intended to be ran under ubuntu.
17+
#
18+
# Usage:
19+
# -----------------------------------
20+
# buster - Debian 10
21+
# stretch - Debian 9
22+
# jessie - Debian 8
23+
# -----------------------------------
24+
# focal - Ubuntu 20.04
25+
# bionic - Ubuntu 18.04
26+
# xenial - Ubuntu 16.04
27+
# -----------------------------------
28+
#
29+
# Example:
30+
#
31+
# export DISTRO=xenial
32+
# export DISTRO_BASE_IMAGE=ubuntu:xenial
33+
#
34+
# $ pipeline.sh
35+
36+
set -exv
37+
38+
DISTRO=${DISTRO:=buster}
39+
DISTRO_BASE_IMAGE=${DISTRO_BASE_IMAGE:=debian:buster}
40+
41+
: "${DISTRO:?DISTRO environment variable not set.}"
42+
: "${DISTRO_BASE_IMAGE:?DISTRO_BASE_IMAGE environment variable not set.}"
43+
: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
44+
DIST_DIR=${BUILD_STAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/debian}
45+
46+
PIPELINE_WORKSPACE=${REPO_ROOT_DIR}
47+
48+
if [[ "${BUILD_OUTPUT}" != "" ]]; then
49+
cp ${BUILD_OUTPUT}/SqlcmdLinuxAmd64/sqlcmd ${REPO_ROOT_DIR}/sqlcmd
50+
fi
51+
52+
CLI_VERSION=${CLI_VERSION:=0.0.1}
53+
54+
echo "=========================================================="
55+
echo "CLI_VERSION: ${CLI_VERSION}"
56+
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION:=1}"
57+
echo "Distribution: ${DISTRO}"
58+
echo "Distribution Image: ${DISTRO_BASE_IMAGE}"
59+
echo "=========================================================="
60+
61+
mkdir -p ${DIST_DIR} || exit 1
62+
63+
echo ${REPO_ROOT_DIR}
64+
65+
docker run --rm \
66+
-v "${REPO_ROOT_DIR}":/mnt/repo \
67+
-v "${DIST_DIR}":/mnt/output \
68+
-v "${PIPELINE_WORKSPACE}":/mnt/workspace \
69+
-e CLI_VERSION=${CLI_VERSION} \
70+
-e CLI_VERSION_REVISION=${CLI_VERSION_REVISION:=1}~${DISTRO} \
71+
"${DISTRO_BASE_IMAGE}" \
72+
/mnt/repo/release/linux/deb/build-pkg.sh

0 commit comments

Comments
 (0)