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
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
#------------------------------------------------------------------------------

# Example:
# docker run --rm microsoft/sqlcmd sqlcmd --help
#

FROM scratch
ARG BUILD_DATE
ARG PACKAGE_VERSION

LABEL maintainer="Microsoft" \
org.label-schema.schema-version="1.0" \
org.label-schema.vendor="Microsoft" \
org.label-schema.name="SQLCMD CLI" \
org.label-schema.version=$PACKAGE_VERSION \
org.label-schema.license="https://github.com/microsoft/go-sqlcmd/blob/main/LICENSE" \
org.label-schema.description="The MSSQL SQLCMD CLI tool" \
org.label-schema.url="https://github.com/microsoft/go-sqlcmd" \
org.label-schema.usage="https://docs.microsoft.com/sql/tools/sqlcmd-utility" \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.docker.cmd="docker run -it microsoft/sqlcmd:$PACKAGE_VERSION"


COPY ./sqlcmd /usr/bin/sqlcmd

CMD ["sqlcmd"]
1 change: 1 addition & 0 deletions build/azure-pipelines/build-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ steps:
GOOS: ${{ parameters.OS }}
GOARCH: ${{ parameters.Arch }}
GOBIN: $(Build.SourcesDirectory)
CGO_ENABLED: 0 # Enables Docker image based off 'scratch'

- task: CopyFiles@2
inputs:
Expand Down
1 change: 1 addition & 0 deletions build/azure-pipelines/package-common-create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ steps:
BUILD_OUTPUT: $(Pipeline.Workspace)
BUILD_STAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
- task: EsrpCodeSigning@1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code signing is going to vary widely per package type. Perhaps we could move each signing profile into its own yml and include the appropriate yml based on the package type. For a docker package the included yml could have a no-op step.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I'm about to run into this with the next PR for Windows .msi.

condition: ne(variables.Type, 'docker')
inputs:
ConnectedServiceName: 'Code Signing'
FolderPath: $(Build.ArtifactStagingDirectory)
Expand Down
6 changes: 6 additions & 0 deletions build/azure-pipelines/package-product.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sqlcmd package pipeline

trigger: none

pr: none

variables:
Expand All @@ -20,6 +22,10 @@ stages:
imageName: 'ubuntu-latest'
os: linux
type: deb
docker:
imageName: 'ubuntu-latest'
os: linux
type: docker
pool:
vmImage: $(imageName)
steps:
Expand Down
17 changes: 17 additions & 0 deletions release/linux/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Docker Release

## Building Docker in CI/CD pipeline

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

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

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

## Verify

```bash
./release/linux/docker/pipeline-test.sh
```
38 changes: 38 additions & 0 deletions release/linux/docker/pipeline-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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 docker image test:
#
# Usage:
#
# $ pipeline-test.sh

set -exv

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

PACKAGE_VERSION=${CLI_VERSION:=0.0.1}
PACKAGE_VERSION_REVISION=${CLI_VERSION_REVISION:=1}

BUILD_ARTIFACTSTAGINGDIRECTORY=${BUILD_ARTIFACTSTAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/docker}
IMAGE_NAME=microsoft/sqlcmd${BUILD_BUILDNUMBER:=''}:latest
TAR_FILE=${BUILD_ARTIFACTSTAGINGDIRECTORY}/sqlcmd-docker-${PACKAGE_VERSION}-${PACKAGE_VERSION_REVISION}.tar

echo "=========================================================="
echo "PACKAGE_VERSION: ${PACKAGE_VERSION}"
echo "PACKAGE_VERSION_REVISION: ${PACKAGE_VERSION_REVISION}"
echo "BUILD_ARTIFACTSTAGINGDIRECTORY: ${BUILD_ARTIFACTSTAGINGDIRECTORY}"
echo "Image name: ${IMAGE_NAME}"
echo "Docker image file: ${TAR_FILE}"
echo "=========================================================="

docker load < ${TAR_FILE}
docker run ${IMAGE_NAME} sqlcmd --help || exit 1
61 changes: 61 additions & 0 deletions release/linux/docker/pipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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.
#
# Build and save the `sqlcmd` image into the bundle:
# `sqlcmd-docker-${PACKAGE_VERSION}.tar`
#
# Usage:
#
# export BUILD_NUMBER=12345 (optional - used to identify the IMAGE_NAME)
# $ pipeline.sh

: "${REPO_ROOT_DIR:=`cd $(dirname $0); cd ../../../; pwd`}"
DIST_DIR=${BUILD_STAGINGDIRECTORY:=${REPO_ROOT_DIR}/output/docker}
IMAGE_NAME=microsoft/sqlcmd${BUILD_BUILDNUMBER:=''}

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

chmod u+x ${REPO_ROOT_DIR}/sqlcmd

PACKAGE_VERSION=${CLI_VERSION:=0.0.1}
PACKAGE_VERSION_REVISION=${CLI_VERSION_REVISION:=1}

echo "=========================================================="
echo "PACKAGE_VERSION: ${PACKAGE_VERSION}"
echo "PACKAGE_VERSION_REVISION: ${PACKAGE_VERSION_REVISION}"
echo "IMAGE_NAME: ${IMAGE_NAME}"
echo "Output location: ${DIST_DIR}"
echo "=========================================================="

docker build --no-cache \
--build-arg BUILD_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" \
--build-arg PACKAGE_VERSION=${PACKAGE_VERSION} \
--build-arg PACKAGE_VERSION_REVISION=${PACKAGE_VERSION_REVISION} \
--tag ${IMAGE_NAME}:latest \
${REPO_ROOT_DIR}

echo "=========================================================="
echo "Done - docker build"
echo "=========================================================="

mkdir -p ${DIST_DIR} || exit 1
docker save -o "${DIST_DIR}/sqlcmd-docker-${PACKAGE_VERSION}-${PACKAGE_VERSION_REVISION}.tar" ${IMAGE_NAME}:latest

echo "=========================================================="
echo "Done - docker save"
echo "=========================================================="

echo "=== Done ================================================="
docker rmi -f ${IMAGE_NAME}:latest
ls ${DIST_DIR}
echo "=========================================================="