Skip to content

Commit 7a18efc

Browse files
committed
extension intro
0 parents  commit 7a18efc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+8475
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ui/node_modules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "CI - Docker image build"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Build the Docker image
19+
run: docker build . --file Dockerfile --tag drewsk/docker-sql-extension:$(date +%s)

.github/workflows/ci-go-test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "CI - go tests"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
11+
gotest:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: 'run go tests'
19+
working-directory: ./backend
20+
run: go test -v ./...
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Docker image publish
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
vTag:
12+
required: true
13+
type: string
14+
15+
env:
16+
REGISTRY: docker.io
17+
IMAGE_NAME: drewsk/docker-sql-extension
18+
19+
20+
jobs:
21+
build:
22+
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
# This is used to complete the identity challenge
28+
# with sigstore/fulcio when running outside of PRs.
29+
id-token: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
# https://github.com/sigstore/cosign-installer
36+
- name: Install cosign
37+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
38+
with:
39+
cosign-release: 'v2.2.4'
40+
41+
# Set up BuildKit Docker container builder to be able to build
42+
# multi-platform images and export cache
43+
# https://github.com/docker/setup-buildx-action
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
46+
47+
# Login against a Docker registry
48+
# https://github.com/docker/login-action
49+
- name: Log into dockerhub
50+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
51+
with:
52+
username: ${{ secrets.DH_USER }}
53+
password: ${{ secrets.DH_PAT }}
54+
55+
# Extract metadata (tags, labels) for Docker
56+
# https://github.com/docker/metadata-action
57+
- name: Extract Docker metadata
58+
id: meta
59+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
60+
with:
61+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
62+
63+
# Build and push Docker image with Buildx
64+
# https://github.com/docker/build-push-action
65+
- name: Build and push Docker image
66+
id: build-and-push
67+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
68+
with:
69+
context: .
70+
push: true
71+
platforms: linux/amd64,linux/arm64
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}
74+
cache-from: type=gha
75+
cache-to: type=gha,mode=max
76+
77+
# Sign the resulting Docker image digest except on PRs.
78+
# This will only write to the public Rekor transparency log when the Docker
79+
# repository is public to avoid leaking data. If you would like to publish
80+
# transparency data even for private images, pass --force to cosign below.
81+
# https://github.com/sigstore/cosign
82+
- name: Sign the published Docker image
83+
env:
84+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
85+
TAGS: ${{ steps.meta.outputs.tags }}
86+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
87+
# This step uses the identity token to provision an ephemeral certificate
88+
# against the sigstore community Fulcio instance.
89+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
ui/build

Database.png

364 KB
Loading

Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM golang:1.23-alpine3.20 AS builder
2+
ENV CGO_ENABLED=0
3+
WORKDIR /backend
4+
COPY backend/go.* .
5+
RUN --mount=type=cache,target=/go/pkg/mod \
6+
--mount=type=cache,target=/root/.cache/go-build \
7+
go mod download
8+
COPY backend/. .
9+
RUN --mount=type=cache,target=/go/pkg/mod \
10+
--mount=type=cache,target=/root/.cache/go-build \
11+
go build -trimpath -ldflags="-s -w" -o bin/service
12+
13+
FROM --platform=$BUILDPLATFORM node:20.18-alpine3.20 AS client-builder
14+
WORKDIR /ui
15+
# cache packages in layer
16+
COPY ui/package.json /ui/package.json
17+
COPY ui/package-lock.json /ui/package-lock.json
18+
RUN --mount=type=cache,target=/usr/src/app/.npm \
19+
npm set cache /usr/src/app/.npm && \
20+
npm ci
21+
# install
22+
COPY ui /ui
23+
RUN npm run build
24+
25+
26+
FROM debian:bullseye AS cli-stage
27+
ARG TARGETARCH
28+
COPY cli-${TARGETARCH}.sh .
29+
RUN apt-get update && apt-get install -y curl bzip2 && \
30+
chmod +x cli-${TARGETARCH}.sh
31+
RUN ./cli-${TARGETARCH}.sh
32+
33+
FROM debian:bullseye-slim
34+
LABEL org.opencontainers.image.title="Docker SQL Dev: SQL dev container manager" \
35+
org.opencontainers.image.description="SQL databases on demand, locally and easily" \
36+
org.opencontainers.image.vendor="DrewSK.Tech" \
37+
com.docker.desktop.extension.api.version="0.3.4" \
38+
com.docker.extension.screenshots="[{\"alt\":\"SQL extension with container details expanded.\", \"url\":\"https://raw.githubusercontent.com/dzsquared/docker-sql-extension/main/images/screenshot2.png\"}, {\"alt\":\"SQL extension with two containers listed.\", \"url\":\"https://raw.githubusercontent.com/dzsquared/docker-sql-extension/main/images/screenshot1.png\"}]" \
39+
com.docker.desktop.extension.icon="https://raw.githubusercontent.com/dzsquared/docker-sql-extension/main/Database.png" \
40+
com.docker.extension.detailed-description="With the SQL extension you can create a new SQL container quickly in Docker Desktop. Select the version of SQL Server you want to use, enter a container name, SQL port, and generate a password before clicking the plus button to create the container. Once a container is created, you can start, stop, and delete it using the buttons in the extension tab. Connect to the container directly in the extension with the embedded sqlcmd tool or by using your preferred SQL client. For convenience the connection string is displayed in the extension tab and a button for launching Azure Data Studio is provided." \
41+
com.docker.extension.publisher-url="https://github.com/dzsquared/docker-sql-extension" \
42+
com.docker.extension.additional-urls="[{\"title\":\"Source code and notices\",\"url\":\"https://github.com/dzsquared/docker-sql-extension/blob/main/README.md\"},\
43+
{\"title\":\"License\",\"url\":\"https://github.com/dzsquared/docker-sql-extension/blob/main/LICENSE\"}]" \
44+
com.docker.extension.categories="database" \
45+
com.docker.extension.changelog="<h3>1.0, Initial release</h3><ul><li>SQL container creation</li><li>Connection strings</li><li>Add and list databases</li><li>Embedded sqlcmd CLI</li></ul>"
46+
47+
COPY --from=builder /backend/bin/service /
48+
COPY --from=client-builder /ui/build ui
49+
COPY --from=cli-stage /usr/bin/ttyd /usr/bin/ttyd
50+
COPY --from=cli-stage /usr/bin/sqlcmd /usr/bin/sqlcmd
51+
COPY docker-compose.yaml .
52+
COPY metadata.json .
53+
COPY database.svg .
54+
COPY host /host
55+
56+
COPY sql.sh /cli/sql.sh
57+
RUN chmod +x /cli/sql.sh
58+
59+
CMD /service -socket /run/guest-services/backend.sock

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 Drew Skwiers-Koballa
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Local SQL
2+
3+
This repository contains the code for the Docker [SQL extension](), which enables you to create and manage SQL containers in Docker Desktop.
4+
5+
## Get started
6+
7+
After installing the extension, you can create a new SQL container by clicking on the "SQL containers" extension tab in Docker Desktop. Select the version of SQL Server you want to use, enter a container name, SQL port, and generate a password before clicking the plus button to create the container.
8+
9+
Once a container is created, you can start, stop, and delete it using the buttons in the extension tab. You can connect to the container directly in the extension with the embedded sqlcmd tool or by using your preferred SQL client. For convenience the connection string is displayed in the extension tab and a button for launching Azure Data Studio is provided.
10+
11+
_When launching Azure Data Studio from the extension the sa password is automatically copied into the clipboard, paste it in the connection dialog when Azure Data Studio opens._
12+
13+
![Docker SQL extension](./images/screenshot2.png)
14+
15+
A full help guide is available in the extension tab under the question mark icon.
16+
17+
## Support
18+
19+
This extension is a hobby project and is not officially supported by Microsoft or Docker. If you encounter any issues, please open an issue in this repository.
20+
21+
## Contributing
22+
23+
The extension is licensed under the [MIT license](./LICENSE). Feel free to open issues and pull requests to improve the extension. I'm interested in investment in:
24+
25+
- cross compatibility as a Podman desktop extension
26+
- selected options for container creation (eg Express vs Developer SKU)
27+
- deploying dacpac files to the container
28+
- your good ideas
29+
30+
This extension code is composed of:
31+
32+
- A [frontend](./ui) app in React that dictates the display in Docker Desktop.
33+
- A [backend](./backend) container that runs an API in Go. It exposes the endpoints which interact with the docker daemon and with SQL endpoints.
34+
- A [host](./host) folder that contains executables the extension needs to create and delete SQL containers.
35+
- A [Dockerfile](./Dockerfile) that builds the extension.
36+
37+
## Local development
38+
39+
To build the extension, use:
40+
41+
```shell
42+
docker build -t drewsk/docker-sql-extension:latest --no-cache .
43+
```
44+
45+
To install the extension, use :
46+
47+
```shell
48+
docker extension install drewsk/docker-sql-extension:latest
49+
```
50+
51+
> If you want to automate this command, use the `-f` or `--force` flag to accept the warning message.
52+
53+
To preview the extension in Docker Desktop, open Docker Dashboard once the installation is complete. The left-hand menu displays a new tab with the name of your extension. You can also use `docker extension ls` to see that the extension has been installed successfully.
54+
55+
To update the extension after making changes, use:
56+
57+
```shell
58+
docker extension update drewsk/docker-sql-extension:latest
59+
```
60+
61+
### Frontend development
62+
63+
During the development of the frontend part, it's helpful to use hot reloading to test your changes without rebuilding the entire extension. To do this, you can configure Docker Desktop to load your UI from a development server.
64+
65+
To start the local development server, run:
66+
67+
```shell
68+
cd ui
69+
npm install
70+
npm run dev
71+
```
72+
73+
You can now tell Docker Desktop to use this as the frontend source. In another terminal run:
74+
75+
```shell
76+
docker extension dev ui-source drewsk/docker-sql-extension:latest http://localhost:5173
77+
```
78+
79+
In order to open the Chrome Dev Tools for the extension when you click on the extension tab, run:
80+
81+
```shell
82+
docker extension dev debug drewsk/docker-sql-extension:latest
83+
```
84+
85+
Each subsequent click on the extension tab will also open Chrome Dev Tools. To stop this behaviour, run:
86+
87+
```shell
88+
docker extension dev reset drewsk/docker-sql-extension:latest
89+
```
90+
91+
### Backend development
92+
93+
This extension includes an API in Go that is deployed as a backend container when the extension is installed. This backend container is responsible for handling requests from the frontend and hosts go-sqlcmd for on-demand CLI access to SQL containers.
94+
95+
Whenever you make changes in the [backend](./backend) source code, you will need to compile them and re-deploy a new version of your backend container.
96+
Use the `docker extension update` command to remove and re-install the extension automatically:
97+
98+
```shell
99+
docker extension update drewsk/docker-sql-extension:latest
100+
```
101+
102+
> [!TIP]
103+
> Extension containers are hidden from the Docker Dashboard by default. You can change this in Settings > Extensions > Show Docker Extensions system containers.
104+
105+
## Notices
106+
107+
The extension is licensed under the [MIT license](./LICENSE).
108+
109+
The SQL containers extension is designed for local development and testing purposes. The extension does not support production workloads or high availability scenarios. SQL Server instances created by this extension are configured with the default settings and the SQL Server Express license.
110+
111+
This extension collects anonymous usage data to help improve the extension. The data collected includes the number of containers created and instances of other actions taken with the extension. The data is used for improving the extension. To disable data collection, obtain the extension source from GitHub and build the extension locally with the Application Insights connection string removed from App.tsx.

0 commit comments

Comments
 (0)