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
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ jobs:
uses: flanksource/action-workflows/.github/workflows/create-release.yml@807c141342c97374e637b4375e3a54e62cd8736e # v1.3.0

binaries:
name: Publish binaries and container images
needs: create-release
if: needs.create-release.outputs.published == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -28,8 +30,22 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: goreleaser/goreleaser-action@v6
with:
version: v2.12.7
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Smoke test the published image
env:
IMAGE: ghcr.io/flanksource/sqlglot-go:${{ needs.create-release.outputs.tag }}
RELEASE_TAG: ${{ needs.create-release.outputs.tag }}
run: |
test "$(docker run --rm "$IMAGE" version)" = "${RELEASE_TAG#v}"
docker run --rm "$IMAGE" validate 'SELECT 1' --json
18 changes: 18 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
version: 2
dist: .tmp/dist

builds:
- main: ./cmd/sqlglot
binary: sqlglot
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.version={{.Version}}
goos:
Expand All @@ -23,5 +26,20 @@ archives:
checksum:
name_template: checksums.txt

dockers_v2:
- images:
- ghcr.io/flanksource/sqlglot-go
tags:
- "v{{ .Version }}"
- latest
platforms:
- linux/amd64
- linux/arm64
labels:
org.opencontainers.image.source: https://github.com/flanksource/sqlglot-go
org.opencontainers.image.revision: "{{ .FullCommit }}"
org.opencontainers.image.version: "{{ .Version }}"
org.opencontainers.image.licenses: Apache-2.0 AND MIT

release:
mode: keep-existing
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM gcr.io/distroless/static-debian12:nonroot
ARG TARGETPLATFORM
COPY ${TARGETPLATFORM}/sqlglot /usr/local/bin/sqlglot
WORKDIR /work
ENTRYPOINT ["/usr/local/bin/sqlglot"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ whose Go executor is the first consumer, is stale.

Build the CLI with `make build` and run `.tmp/sqlglot`, install the current checkout with `make install` into Go's `GOBIN` (or `GOPATH/bin`), or install a tagged release with `go install github.com/flanksource/sqlglot-go/cmd/sqlglot@latest`. Releases attach Linux, macOS, and Windows archives for amd64 and arm64 to the GitHub release.

The same release binaries are published in `ghcr.io/flanksource/sqlglot-go` for Linux amd64 and arm64, tagged with the release version (for example, `v1.0.6`) and `latest`. The image runs as a non-root user and includes CA certificates for database TLS connections.

```sh
docker run --rm ghcr.io/flanksource/sqlglot-go:latest version
docker run --rm ghcr.io/flanksource/sqlglot-go:latest validate 'SELECT 1' --json
docker run --rm -i ghcr.io/flanksource/sqlglot-go:latest format < query.sql
docker run --rm -v "$PWD:/work:ro" ghcr.io/flanksource/sqlglot-go:latest parse --file /work/query.sql --dialect tsql
```

To verify release packaging locally, run `go run github.com/goreleaser/goreleaser/v2@v2.12.7 release --snapshot --clean`. This builds all six binary archives and loads local container images with architecture suffixes, without publishing. GoReleaser supplies the prebuilt binaries to the Dockerfile; `docker build .` alone does not build the CLI.

```sh
sqlglot dialects
sqlglot parse --format json --dialect tsql 'SELECT TOP 2 name FROM users'
Expand Down
Loading