Skip to content

Commit cbafb93

Browse files
authored
Merge pull request #61 from microsoft/stuartpa/package-docker
Docker release package
2 parents 90f48e4 + d3dd489 commit cbafb93

File tree

7 files changed

+153
-0
lines changed

7 files changed

+153
-0
lines changed

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT license.
4+
#------------------------------------------------------------------------------
5+
6+
# Example:
7+
# docker run --rm microsoft/sqlcmd sqlcmd --help
8+
#
9+
10+
FROM scratch
11+
ARG BUILD_DATE
12+
ARG PACKAGE_VERSION
13+
14+
LABEL maintainer="Microsoft" \
15+
org.label-schema.schema-version="1.0" \
16+
org.label-schema.vendor="Microsoft" \
17+
org.label-schema.name="SQLCMD CLI" \
18+
org.label-schema.version=$PACKAGE_VERSION \
19+
org.label-schema.license="https://github.com/microsoft/go-sqlcmd/blob/main/LICENSE" \
20+
org.label-schema.description="The MSSQL SQLCMD CLI tool" \
21+
org.label-schema.url="https://github.com/microsoft/go-sqlcmd" \
22+
org.label-schema.usage="https://docs.microsoft.com/sql/tools/sqlcmd-utility" \
23+
org.label-schema.build-date=$BUILD_DATE \
24+
org.label-schema.docker.cmd="docker run -it microsoft/sqlcmd:$PACKAGE_VERSION"
25+
26+
27+
COPY ./sqlcmd /usr/bin/sqlcmd
28+
29+
CMD ["sqlcmd"]

build/azure-pipelines/build-common.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ steps:
5151
GOOS: ${{ parameters.OS }}
5252
GOARCH: ${{ parameters.Arch }}
5353
GOBIN: $(Build.SourcesDirectory)
54+
CGO_ENABLED: 0 # Enables Docker image based off 'scratch'
5455

5556
- task: CopyFiles@2
5657
inputs:

build/azure-pipelines/package-common-create.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ steps:
3232
BUILD_OUTPUT: $(Pipeline.Workspace)
3333
BUILD_STAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
3434
- task: EsrpCodeSigning@1
35+
condition: ne(variables.Type, 'docker')
3536
inputs:
3637
ConnectedServiceName: 'Code Signing'
3738
FolderPath: $(Build.ArtifactStagingDirectory)

build/azure-pipelines/package-product.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# sqlcmd package pipeline
22

3+
trigger: none
4+
35
pr: none
46

57
variables:
@@ -20,6 +22,10 @@ stages:
2022
imageName: 'ubuntu-latest'
2123
os: linux
2224
type: deb
25+
docker:
26+
imageName: 'ubuntu-latest'
27+
os: linux
28+
type: docker
2329
pool:
2430
vmImage: $(imageName)
2531
steps:

release/linux/docker/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Docker Release
2+
3+
## Building Docker in CI/CD pipeline
4+
5+
Execute the following command from the root directory of this repository:
6+
7+
```bash
8+
./release/linux/docker/pipeline.sh
9+
```
10+
11+
Output will be sent to `./output/docker`
12+
13+
## Verify
14+
15+
```bash
16+
./release/linux/docker/pipeline-test.sh
17+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 docker image test:
13+
#
14+
# Usage:
15+
#
16+
# $ pipeline-test.sh
17+
18+
set -exv
19+
20+
: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
21+
22+
PACKAGE_VERSION=${CLI_VERSION:=0.0.1}
23+
PACKAGE_VERSION_REVISION=${CLI_VERSION_REVISION:=1}
24+
25+
BUILD_ARTIFACTSTAGINGDIRECTORY=${BUILD_ARTIFACTSTAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/docker}
26+
IMAGE_NAME=microsoft/sqlcmd${BUILD_BUILDNUMBER:=''}:latest
27+
TAR_FILE=${BUILD_ARTIFACTSTAGINGDIRECTORY}/sqlcmd-docker-${PACKAGE_VERSION}-${PACKAGE_VERSION_REVISION}.tar
28+
29+
echo "=========================================================="
30+
echo "PACKAGE_VERSION: ${PACKAGE_VERSION}"
31+
echo "PACKAGE_VERSION_REVISION: ${PACKAGE_VERSION_REVISION}"
32+
echo "BUILD_ARTIFACTSTAGINGDIRECTORY: ${BUILD_ARTIFACTSTAGINGDIRECTORY}"
33+
echo "Image name: ${IMAGE_NAME}"
34+
echo "Docker image file: ${TAR_FILE}"
35+
echo "=========================================================="
36+
37+
docker load < ${TAR_FILE}
38+
docker run ${IMAGE_NAME} sqlcmd --help || exit 1

release/linux/docker/pipeline.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
# Build and save the `sqlcmd` image into the bundle:
13+
# `sqlcmd-docker-${PACKAGE_VERSION}.tar`
14+
#
15+
# Usage:
16+
#
17+
# export BUILD_NUMBER=12345 (optional - used to identify the IMAGE_NAME)
18+
# $ pipeline.sh
19+
20+
: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
21+
DIST_DIR=${BUILD_STAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/docker}
22+
IMAGE_NAME=microsoft/sqlcmd${BUILD_BUILDNUMBER:=''}
23+
24+
if [[ "${BUILD_OUTPUT}" != "" ]]; then
25+
cp ${BUILD_OUTPUT}/SqlcmdLinuxAmd64/sqlcmd ${REPO_ROOT_DIR}/sqlcmd
26+
fi
27+
28+
chmod u+x ${REPO_ROOT_DIR}/sqlcmd
29+
30+
PACKAGE_VERSION=${CLI_VERSION:=0.0.1}
31+
PACKAGE_VERSION_REVISION=${CLI_VERSION_REVISION:=1}
32+
33+
echo "=========================================================="
34+
echo "PACKAGE_VERSION: ${PACKAGE_VERSION}"
35+
echo "PACKAGE_VERSION_REVISION: ${PACKAGE_VERSION_REVISION}"
36+
echo "IMAGE_NAME: ${IMAGE_NAME}"
37+
echo "Output location: ${DIST_DIR}"
38+
echo "=========================================================="
39+
40+
docker build --no-cache \
41+
--build-arg BUILD_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" \
42+
--build-arg PACKAGE_VERSION=${PACKAGE_VERSION} \
43+
--build-arg PACKAGE_VERSION_REVISION=${PACKAGE_VERSION_REVISION} \
44+
--tag ${IMAGE_NAME}:latest \
45+
${REPO_ROOT_DIR}
46+
47+
echo "=========================================================="
48+
echo "Done - docker build"
49+
echo "=========================================================="
50+
51+
mkdir -p ${DIST_DIR} || exit 1
52+
docker save -o "${DIST_DIR}/sqlcmd-docker-${PACKAGE_VERSION}-${PACKAGE_VERSION_REVISION}.tar" ${IMAGE_NAME}:latest
53+
54+
echo "=========================================================="
55+
echo "Done - docker save"
56+
echo "=========================================================="
57+
58+
echo "=== Done ================================================="
59+
docker rmi -f ${IMAGE_NAME}:latest
60+
ls ${DIST_DIR}
61+
echo "=========================================================="

0 commit comments

Comments
 (0)