Skip to content

Commit a9e87ca

Browse files
author
Dmytro Bondar
authored
Chore updates (#20)
* Added .dockerignore * Use one curl command to download release artifact * Set image user compatible with K8s 'securityContext' by default * Added examples to readme
1 parent b9f5add commit a9e87ca

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ FROM --platform=${BUILDPLATFORM} alpine:3 AS tools
22
ARG SQLCMD_VERSION=v1.8.0
33
ARG TARGETARCH
44
RUN apk add --update-cache --no-cache curl jq xz && \
5-
curl -sSL $(curl -sSL "https://api.github.com/repos/microsoft/go-sqlcmd/releases/tags/${SQLCMD_VERSION}" | \
6-
jq -r --arg arch "${TARGETARCH}" '.assets[] | select(.name | test(".*linux.*" + $arch + ".*")).browser_download_url') \
5+
curl -sSL https://github.com/microsoft/go-sqlcmd/releases/download/${SQLCMD_VERSION}/sqlcmd-linux-${TARGETARCH}.tar.bz2 \
76
| tar -xj
87

98
FROM gcr.io/distroless/static:nonroot@sha256:d71f4b239be2d412017b798a0a401c44c3049a3ca454838473a4c32ed076bfea
109
COPY --from=tools /sqlcmd /sqlcmd
11-
USER nonroot:nonroot
10+
USER 65532:65532
1211
ENTRYPOINT ["/sqlcmd"]

README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
[docker-hub]: https://hub.docker.com/r/bonddim/go-sqlcmd
44
[![Docker](https://github.com/bonddim/go-sqlcmd/actions/workflows/docker.yaml/badge.svg)](https://github.com/bonddim/go-sqlcmd/actions/workflows/docker.yaml)
5-
[![Docker Image Version](https://img.shields.io/docker/v/bonddim/go-sqlcmd)][docker-hub]
6-
[![Docker Image Size](https://img.shields.io/docker/image-size/bonddim/go-sqlcmd)][docker-hub]
7-
[![Docker Pulls](https://img.shields.io/docker/pulls/bonddim/go-sqlcmd)][docker-hub]
5+
[![Docker Image Version](https://img.shields.io/docker/v/bonddim/go-sqlcmd?logo=docker&label=latest)][docker-hub]
6+
[![Docker Image Size](https://img.shields.io/docker/image-size/bonddim/go-sqlcmd?logo=docker)][docker-hub]
7+
[![Docker Pulls](https://img.shields.io/docker/pulls/bonddim/go-sqlcmd?logo=docker&label=pulls)][docker-hub]
88
[![GitHub License](https://img.shields.io/github/license/bonddim/go-sqlcmd)](https://github.com/bonddim/go-sqlcmd?tab=MIT-1-ov-file)
99

1010
## About
1111

12-
- Uses [gcr.io/distroless/static:nonroot](https://github.com/GoogleContainerTools/distroless) as image base
1312
- Supported architectures: **amd64**, **arm64**, **s390x**
13+
- Uses [gcr.io/distroless/static:nonroot](https://github.com/GoogleContainerTools/distroless) as image base
1414
- Uses [released sqlcmd](https://github.com/microsoft/go-sqlcmd/releases) binary
15-
- Automated release process
15+
- Updated automatically by Renovate
1616

1717
## Usage
1818

@@ -23,6 +23,47 @@ docker pull bonddim/go-sqlcmd
2323
docker pull ghcr.io/bonddim/go-sqlcmd
2424
```
2525

26+
Docker container with mounted scripts to run:
27+
28+
```bash
29+
docker run \
30+
--rm \
31+
-v $(pwd)/sql_scripts:/mnt/sql \
32+
-e SQLCMDPASSWORD={{ password }} \
33+
ghcr.io/bonddim/go-sqlcmd \
34+
-i /mnt/sql \
35+
-S {{ server }} \
36+
-d {{ database }} \
37+
-u {{ user }}
38+
```
39+
40+
K8s pod with Entra ID authentication:
41+
42+
```yaml
43+
apiVersion: v1
44+
kind: Pod
45+
metadata:
46+
name: go-sqlcmd
47+
labels:
48+
azure.workload.identity/use: "true"
49+
spec:
50+
serviceAccountName: go-sqlcmd
51+
containers:
52+
- name: go-sqlcmd
53+
image: bonddim/go-sqlcmd
54+
args:
55+
- --use-aad
56+
- --server
57+
- {{ server }}.database.windows.net
58+
- --database-name
59+
- {{ database }}
60+
- --query
61+
- {{ query }}
62+
securityContext:
63+
runAsNonRoot: true
64+
...
65+
```
66+
2667
Refer to official [docs](https://docs.microsoft.com/sql/tools/go-sqlcmd-utility) for syntax and command line arguments
2768

2869
## License

0 commit comments

Comments
 (0)