Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build/azure-pipelines/package-product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ stages:
rpm:
imageName: 'ubuntu-latest'
os: linux
type: rpm
type: rpm
debian:
imageName: 'ubuntu-latest'
os: linux
type: deb
pool:
vmImage: $(imageName)
steps:
Expand All @@ -27,4 +31,3 @@ stages:
parameters:
OS: $(os)
Type: $(type)

84 changes: 84 additions & 0 deletions release/linux/deb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Debian Packaging Release

## Building the Debian package

Execute the following command from the root directory of this repository:

``` bash
./release/linux/debian/pipeline.sh
```

Output will be sent to `./output/debian`

## Dev Installation and Verification

``` bash
./release/linux/debian/pipeline-test.sh
```

## Release Install/Update/Uninstall Steps

> **Note:** Replace `{{HOST}}` and `{{CLI_VERSION}}` with the appropriate values.

### Install sqlcmd with apt (Ubuntu or Debian)

1. Download and install the signing key:

```bash
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
```

2. Add the sqlcmd repository information:

```bash
sudo echo "deb [trusted=yes arch=amd64] http://{{HOST}}/browse/repo/ubuntu/sqlcmd mssql main" | tee /etc/apt/sources.list.d/sqlcmd.list
```

3. Update repository information and install sqlcmd:

```bash
sudo apt-get update
sudo apt-get install sqlcmd
```

5. Verify installation success:

```bash
sqlcmd --help
```

### Update

1. Upgrade sqlcmd only:

```bash
sudo apt-get update && sudo apt-get install --only-upgrade -y sqlcmd
```

### Uninstall

1. Uninstall with apt-get remove:

```bash
sudo apt-get remove -y sqlcmd
```

2. Remove the sqlcmd repository information:

> Note: This step is not needed if you plan on installing sqlcmd in the future

```bash
sudo rm /etc/apt/sources.list.d/sqlcmd.list
```

3. Remove the signing key:

```bash
sudo rm /etc/apt/trusted.gpg.d/dpgswdist.v1.asc.gpg
```

4. Remove any unneeded dependencies that were installed with sqlcmd:

```bash
sudo apt autoremove
```
57 changes: 57 additions & 0 deletions release/linux/deb/build-pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

#------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
#------------------------------------------------------------------------------

# Description:
#
# Build a debian/ubuntu `sqlcmd` package. This script is intended to be ran in a
# container with the respective disto/image laid down.
#
# Usage:
# $ build-pkg.sh

set -exv

: "${CLI_VERSION:?CLI_VERSION environment variable not set.}"
: "${CLI_VERSION_REVISION:?CLI_VERSION_REVISION environment variable not set.}"

WORKDIR=`cd $(dirname $0); cd ../../../; pwd`

ls -la ${WORKDIR}

apt-get -y update || exit 1
export DEBIAN_FRONTEND=noninteractive
apt-get install -y \
debhelper \
dpkg-dev \
locales || exit 1

# Locale
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8

export LANG=en_US.UTF-8
export PATH=$PATH

# Verify
chmod u+x /mnt/workspace/sqlcmd
/mnt/workspace/sqlcmd --help

mkdir /opt/stage
cp /mnt/workspace/sqlcmd /opt/stage/sqlcmd

# Create create directory for debian build
mkdir -p ${WORKDIR}/debian
${WORKDIR}/release/linux/deb/prepare-rules.sh ${WORKDIR}/debian ${WORKDIR}

cd ${WORKDIR}
dpkg-buildpackage -us -uc

ls ${WORKDIR} -R

debPkg=${WORKDIR}/../sqlcmd_${CLI_VERSION}-${CLI_VERSION_REVISION:=1}_all.deb
cp ${debPkg} /mnt/output/
64 changes: 64 additions & 0 deletions release/linux/deb/pipeline-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

#------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
#------------------------------------------------------------------------------

# Description:
#
# Instructions to be invoked under the build CI pipeline in AzureDevOps.
#
# Kickoff Debian package tests against versions:
#
# Usage:
# -----------------------------------
# buster - Debian 10
# stretch - Debian 9
# jessie - Debian 8
# -----------------------------------
# focal - Ubuntu 20.04
# bionic - Ubuntu 18.04
# xenial - Ubuntu 16.04
# -----------------------------------
#
# Usage:
# $ pipeline-test.sh

set -e #xv

: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"

CLI_VERSION=${CLI_VERSION:=0.0.1}
CLI_VERSION_REVISION=${CLI_VERSION_REVISION:=1}
BUILD_ARTIFACTSTAGINGDIRECTORY=${BUILD_ARTIFACTSTAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/debian}

DISTROS=( buster buster ) # TODO: Should we validate against more distros?: buster stretch jessie bionic xenial focal
BASE_IMAGES=( debian:buster ubuntu:focal ) # TODO: debian:buster debian:stretch debian:jessie ubuntu:bionic ubuntu:xenial ubuntu:focal

echo "=========================================================="
echo "CLI_VERSION: ${CLI_VERSION}"
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION}"
echo "BUILD_ARTIFACTSTAGINGDIRECTORY: ${BUILD_ARTIFACTSTAGINGDIRECTORY}"
echo "Distribution: ${DISTROS}"
echo "=========================================================="

for i in ${!DISTROS[@]}; do
echo "=========================================================="
echo "Test debian package on ${DISTROS[$i]}"
echo "=========================================================="

debPkg=sqlcmd_${CLI_VERSION}-${CLI_VERSION_REVISION}~${DISTROS[$i]}_all.deb

script="apt-get update && \
dpkg -i /mnt/artifacts/${debPkg} && \
apt-get -f install && \
sqlcmd --help"

docker pull ${BASE_IMAGES[$i]}
docker run --rm -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}:/mnt/artifacts \
${BASE_IMAGES[$i]} \
/bin/bash -c "${script}"

echo ""
done
72 changes: 72 additions & 0 deletions release/linux/deb/pipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

#------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
#------------------------------------------------------------------------------

# Description:
#
# Instructions to be invoked under the build CI pipeline in AzureDevOps.
#
# Kickoff debian package build in docker and copy the .deb package artifact
# back to the local filesystem. The build pipeline can then save it as an
# artifact as it sees fit.
#
# Note: Intended to be ran under ubuntu.
#
# Usage:
# -----------------------------------
# buster - Debian 10
# stretch - Debian 9
# jessie - Debian 8
# -----------------------------------
# focal - Ubuntu 20.04
# bionic - Ubuntu 18.04
# xenial - Ubuntu 16.04
# -----------------------------------
#
# Example:
#
# export DISTRO=xenial
# export DISTRO_BASE_IMAGE=ubuntu:xenial
#
# $ pipeline.sh

set -exv

DISTRO=${DISTRO:=buster}
DISTRO_BASE_IMAGE=${DISTRO_BASE_IMAGE:=debian:buster}

: "${DISTRO:?DISTRO environment variable not set.}"
: "${DISTRO_BASE_IMAGE:?DISTRO_BASE_IMAGE environment variable not set.}"
: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
DIST_DIR=${BUILD_STAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/debian}

PIPELINE_WORKSPACE=${REPO_ROOT_DIR}

if [[ "${BUILD_OUTPUT}" != "" ]]; then
cp ${BUILD_OUTPUT}/SqlcmdLinuxAmd64/sqlcmd ${REPO_ROOT_DIR}/sqlcmd
fi

CLI_VERSION=${CLI_VERSION:=0.0.1}

echo "=========================================================="
echo "CLI_VERSION: ${CLI_VERSION}"
echo "CLI_VERSION_REVISION: ${CLI_VERSION_REVISION:=1}"
echo "Distribution: ${DISTRO}"
echo "Distribution Image: ${DISTRO_BASE_IMAGE}"
echo "=========================================================="

mkdir -p ${DIST_DIR} || exit 1

echo ${REPO_ROOT_DIR}

docker run --rm \
-v "${REPO_ROOT_DIR}":/mnt/repo \
-v "${DIST_DIR}":/mnt/output \
-v "${PIPELINE_WORKSPACE}":/mnt/workspace \
-e CLI_VERSION=${CLI_VERSION} \
-e CLI_VERSION_REVISION=${CLI_VERSION_REVISION:=1}~${DISTRO} \
"${DISTRO_BASE_IMAGE}" \
/mnt/repo/release/linux/deb/build-pkg.sh
Loading