From 89e5ab97531debecd96108358e162790a1810175 Mon Sep 17 00:00:00 2001 From: Richard Glidden Date: Fri, 16 Aug 2024 16:33:47 -0400 Subject: [PATCH] Update project for GitHub --- .github/workflows/publish-container.yaml | 41 ++++++++++++++++ Dockerfile | 47 ++++++++++--------- README.md | 6 +-- azure-pipelines.yml | 60 ------------------------ 4 files changed, 69 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/publish-container.yaml delete mode 100644 azure-pipelines.yml diff --git a/.github/workflows/publish-container.yaml b/.github/workflows/publish-container.yaml new file mode 100644 index 0000000..d2f5343 --- /dev/null +++ b/.github/workflows/publish-container.yaml @@ -0,0 +1,41 @@ +name: Build and Publish Container + +on: + workflow_dispatch: + push: + branches: ["main"] + +permissions: + actions: read + contents: read + packages: write + security-events: write + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Determine Version + id: version + shell: bash + run: echo "sqlcmd=$(gh release view -R microsoft/go-sqlcmd --json tagName -q '.tagName')" >> $GITHUB_OUTPUT + + - name: Download sqlcmd ${{ steps.version.outputs.sqlcmd }} + shell: bash + run: | + gh release download ${{ steps.version.outputs.sqlcmd }} --pattern sqlcmd-linux-amd64.tar.bz2 -R microsoft/go-sqlcmd + tar -xjvf sqlcmd-linux-amd64.tar.bz2 + + - name: "Build and Publish brocksolutions/sqlcmd:${{ steps.version.outputs.sqlcmd }}" + uses: brocksolutions/action-build-container@v3 + with: + dockerfile-path: Dockerfile + image-name: sqlcmd + version: ${{ steps.version.outputs.sqlcmd }} + tag-latest: true + push-to-registry: true diff --git a/Dockerfile b/Dockerfile index 8b4b3b5..3578e11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,28 @@ -ARG DEBIAN_VERSION=11 -FROM debian:$DEBIAN_VERSION-slim +#------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. +#------------------------------------------------------------------------------ -RUN apt-get -qqq update \ - && apt-get install -y curl apt-transport-https locales gnupg2 \ - && locale-gen "en_US.UTF-8" \ - \ - && export `grep "VERSION_ID" /etc/os-release | sed -e 's/^VERSION_ID=\"/VERSION_ID=/' -e 's/\"$//'` \ - && mkdir -p /etc/apt/keyrings/ \ - && curl --fail https://packages.microsoft.com/config/debian/$VERSION_ID/prod.list | \ - sed -E 's#deb\s+\[#deb [signed-by=/etc/apt/keyrings/microsoft.gpg #; t; q1' | \ - tee /etc/apt/sources.list.d/microsoft.list \ - && curl --fail https://packages.microsoft.com/keys/microsoft.asc | \ - gpg --verbose --yes --no-tty --batch --dearmor -o /etc/apt/keyrings/microsoft.gpg \ - \ - && apt-get -qqq update \ - && apt-get install -y sqlcmd \ - && apt-get remove -y curl apt-transport-https gnupg2 \ - && rm -f /etc/apt/sources.list.d/msprod.list \ - && rm -rf /var/lib/apt/lists/* +# Example: +# docker run --rm microsoft/sqlcmd sqlcmd --help +# -## should be set after locale was generated, overwise triggers warnings -ENV LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" LC_ALL="en_US.UTF-8" +FROM scratch +ARG BUILD_DATE +ARG PACKAGE_VERSION -ENTRYPOINT ["/usr/bin/sqlcmd"] +LABEL maintainer="Brock Solutions" \ + org.label-schema.schema-version="1.0" \ + org.label-schema.vendor="Brock Solutions" \ + 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 brocksolutions/sqlcmd:$PACKAGE_VERSION" + +COPY ./sqlcmd /usr/bin/sqlcmd + +ENTRYPOINT ["sqlcmd"] diff --git a/README.md b/README.md index fc595b4..8e250e2 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ This repository contains the Dockerfile for the `brocksolutions/sqlcmd` container image. This image provides the latest version of Microsoft's `sqlcmd` (Go) tool. -Microsoft does not (yet) distribute an official `sqlcmd` container image, so this image is built by installing the `sqlcmd` tool -into a base Debian image. +Microsoft does not currently distribute an official `sqlcmd` container image, so this image simply bundles the `sqlcmd` file into +a minimal container image. ## Available Tags @@ -17,5 +17,5 @@ The entrypoint in the container is set to the `/usr/bin/sqlcmd`. This means you the `sqlcmd` tool locally, and simply pass in any additional parameters you amy need. For example: ``` powershell -docker run --rm brocksolutions/sqlcmd -S myserver -U myuser -P mypassword -Q "SELECT @@VERSION" +docker run --rm brocksolutions/sqlcmd:latest -S myserver -U myuser -P mypassword -Q "SELECT @@VERSION" ``` diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index dfe0661..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,60 +0,0 @@ -variables: - versionNumber: 1.5.0 - containerRegistry: "DockerHub.BrockSolutions" - repository: "brocksolutions/sqlcmd" - build: $[counter(variables['versionNumber'],0)] # DO NOT MODIFY! - -name: $(versionNumber).$(build) # DO NOT MODIFY! - -trigger: - branches: - include: - - main - -stages: - - stage: DockerBuild - displayName: "Build Container" - dependsOn: [] - pool: - name: SmartSuite Deployment - demands: - - Agent.OS -equals Linux - jobs: - - job: Docker_SqlCmd - displayName: "Build & Publish Container" - steps: - # Available versions listed at https://download.docker.com/linux/static/stable/x86_64/ - - task: DockerInstaller@0 - displayName: "Install Docker" - inputs: - dockerVersion: "24.0.7" - releaseType: stable - - # Log in to Docker Hub - Uses account stored in the Service Connection in Azure DevOps - - task: Docker@2 - displayName: "Log In to Docker Hub" - inputs: - command: login - containerRegistry: $(containerRegistry) - - # Build and Push Container - - task: Docker@2 - displayName: "Build Container" - inputs: - command: build - Dockerfile: $(Build.SourcesDirectory)/Dockerfile - buildContext: $(Build.SourcesDirectory) - repository: $(repository) - tags: | - $(Build.BuildNumber) - latest - - - task: Docker@2 - displayName: "Push Container" - inputs: - command: push - Dockerfile: $(Build.SourcesDirectory)/Dockerfile - repository: $(repository) - tags: | - $(Build.BuildNumber) - latest