diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18cc39ba..07a74a74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 47d6017c..1e5a6e21 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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: @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..db0ec575 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 26c5d3e1..9132df52 100644 --- a/README.md +++ b/README.md @@ -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'