Skip to content

Commit f0a57eb

Browse files
Ajeet Singh RainaAjeet Singh Raina
Ajeet Singh Raina
authored and
Ajeet Singh Raina
committed
Added
1 parent 199a8ea commit f0a57eb

File tree

10,507 files changed

+2403349
-2
lines changed

Some content is hidden

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

10,507 files changed

+2403349
-2
lines changed

Dockerfile

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM golang:1.19-alpine 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:18.12-alpine3.16 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+
FROM alpine
26+
LABEL org.opencontainers.image.title="Mindsdb" \
27+
org.opencontainers.image.description="Mindsdb Docker Extension" \
28+
org.opencontainers.image.vendor="Ajeet Singh Raina" \
29+
com.docker.desktop.extension.api.version="0.3.0" \
30+
com.docker.extension.screenshots="" \
31+
com.docker.extension.categories="Databases" \
32+
com.docker.desktop.extension.icon="https://uploads-ssl.webflow.com/62a8755be8bcc86e6307def8/63b75a4a90fefbed813c6549_Mindsdb-V%20logo.svg" \
33+
com.docker.extension.detailed-description="Mindsdb is an open-source machine learning framework that allows users to create predictive models using natural language queries. Mindsdb uses a combination of automated machine learning (AutoML) techniques and a knowledge graph to analyze data and generate predictions." \
34+
com.docker.extension.publisher-url="https://github.com/collabnix/mindsdb-docker-extension" \
35+
com.docker.extension.additional-urls='[{"title":"Documentation","url":"https://docs.mindsdb.com/what-is-mindsdb/"}, {"title":"Support","url":"https://github.com/mindsdb/mindsdb/discussions"}, {"title":"Terms of Service","url":"https://mindsdb.com/terms"}, {"title":"Privacy policy","url":"https://mindsdb.com/privacy-policy/"}]' \
36+
com.docker.extension.changelog="https://raw.githubusercontent.com/collabnix/mindsdb-docker-extension/main/CHANGELOG.md"
37+
38+
COPY --from=builder /backend/bin/service /
39+
COPY docker-compose.yaml .
40+
COPY metadata.json .
41+
COPY mindsdb.svg .
42+
COPY --from=client-builder /ui/build ui
43+
CMD /service -socket /run/guest-services/backend.sock

Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
IMAGE?=ajeetraina/mindsdb-docker-extension
2+
TAG?=1.0.0
3+
4+
BUILDER=buildx-multi-arch
5+
6+
INFO_COLOR = \033[0;36m
7+
NO_COLOR = \033[m
8+
9+
build-extension: ## Build service image to be deployed as a desktop extension
10+
docker build --tag=$(IMAGE):$(TAG) .
11+
12+
install-extension: build-extension ## Install the extension
13+
docker extension install $(IMAGE):$(TAG)
14+
15+
update-extension: build-extension ## Update the extension
16+
docker extension update $(IMAGE):$(TAG)
17+
18+
prepare-buildx: ## Create buildx builder for multi-arch build, if not exists
19+
docker buildx inspect $(BUILDER) || docker buildx create --name=$(BUILDER) --driver=docker-container --driver-opt=network=host
20+
21+
push-extension: prepare-buildx ## Build & Upload extension image to hub. Do not push if tag already exists: make push-extension tag=0.1
22+
docker pull $(IMAGE):$(TAG) && echo "Failure: Tag already exists" || docker buildx build --push --builder=$(BUILDER) --platform=linux/amd64,linux/arm64 --build-arg TAG=$(TAG) --tag=$(IMAGE):$(TAG) .
23+
24+
help: ## Show this help
25+
@echo Please specify a build target. The choices are:
26+
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}'
27+
28+
.PHONY: help

README.md

+107-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,107 @@
1-
# mindsdb-docker-extension
2-
MIndsDB Extension for Docker Desktop
1+
# Mindsdb
2+
3+
This repository defines an example of a Docker extension. The files in this repository have been automatically generated as a result of running `docker extension init`.
4+
5+
This extension is composed of:
6+
7+
- A [frontend](./ui) app in React that makes a request to the `/hello` endpoint and displays the payload in Docker Desktop.
8+
- A [backend](./backend) container that runs an API in Go. It exposes the `/hello` endpoint which returns a JSON payload.
9+
10+
> You can build your Docker Extension using your fav tech stack:
11+
>
12+
> - Frontend: React, Angular, Vue, Svelte, etc.
13+
> Basically, any frontend framework you can bundle in an `index.html` file with CSS, and JS assets.
14+
> - Backend (optional): anything that can run in a container.
15+
16+
<details>
17+
<summary>Looking for more templates?</summary>
18+
19+
1. [React + NodeJS](https://github.com/benja-M-1/node-backend-extension).
20+
2. [React + .NET 6 WebAPI](https://github.com/felipecruz91/dotnet-api-docker-extension).
21+
22+
Request one or submit yours [here](https://github.com/docker/extensions-sdk/issues).
23+
24+
</details>
25+
26+
## Local development
27+
28+
You can use `docker` to build, install and push your extension. Also, we provide an opinionated [Makefile](Makefile) that could be convenient for you. There isn't a strong preference of using one over the other, so just use the one you're most comfortable with.
29+
30+
To build the extension, use `make build-extension` **or**:
31+
32+
```shell
33+
docker buildx build -t ajeetraina/mindsdb-docker-extension:latest . --load
34+
```
35+
36+
To install the extension, use `make install-extension` **or**:
37+
38+
```shell
39+
docker extension install ajeetraina/mindsdb-docker-extension:latest
40+
```
41+
42+
> If you want to automate this command, use the `-f` or `--force` flag to accept the warning message.
43+
44+
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.
45+
46+
### Frontend development
47+
48+
During the development of the frontend part, it's helpful to use hot reloading to test your changes without rebuilding your entire extension. To do this, you can configure Docker Desktop to load your UI from a development server.
49+
Assuming your app runs on the default port, start your UI app and then run:
50+
51+
```shell
52+
cd ui
53+
npm install
54+
npm run dev
55+
```
56+
57+
This starts a development server that listens on port `3000`.
58+
59+
You can now tell Docker Desktop to use this as the frontend source. In another terminal run:
60+
61+
```shell
62+
docker extension dev ui-source ajeetraina/mindsdb-docker-extension:latest http://localhost:3000
63+
```
64+
65+
In order to open the Chrome Dev Tools for your extension when you click on the extension tab, run:
66+
67+
```shell
68+
docker extension dev debug ajeetraina/mindsdb-docker-extension:latest
69+
```
70+
71+
Each subsequent click on the extension tab will also open Chrome Dev Tools. To stop this behaviour, run:
72+
73+
```shell
74+
docker extension dev reset ajeetraina/mindsdb-docker-extension:latest
75+
```
76+
77+
### Backend development (optional)
78+
79+
This example defines an API in Go that is deployed as a backend container when the extension is installed. This backend could be implemented in any language, as it runs inside a container. The extension frameworks provides connectivity from the extension UI to a socket that the backend has to connect to on the server side.
80+
81+
Note that an extension doesn't necessarily need a backend container, but in this example we include one for teaching purposes.
82+
83+
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.
84+
Use the `docker extension update` command to remove and re-install the extension automatically:
85+
86+
```shell
87+
docker extension update ajeetraina/mindsdb-docker-extension:latest
88+
```
89+
90+
> If you want to automate this command, use the `-f` or `--force` flag to accept the warning message.
91+
92+
> Extension containers are hidden from the Docker Dashboard by default. You can change this in Settings > Extensions > Show Docker Extensions system containers.
93+
94+
### Clean up
95+
96+
To remove the extension:
97+
98+
```shell
99+
docker extension rm ajeetraina/mindsdb-docker-extension:latest
100+
```
101+
102+
## What's next?
103+
104+
- To learn more about how to build your extension refer to the Extension SDK docs at https://docs.docker.com/desktop/extensions-sdk/.
105+
- To publish your extension in the Marketplace visit https://www.docker.com/products/extensions/submissions/.
106+
- To report issues and feedback visit https://github.com/docker/extensions-sdk/issues.
107+
- To look for other ideas of new extensions, or propose new ideas of extensions you would like to see, visit https://github.com/docker/extension-ideas/discussions.

backend/go.mod

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module mindsdb
2+
3+
go 1.19
4+
5+
require (
6+
github.com/labstack/echo v3.3.10+incompatible
7+
github.com/sirupsen/logrus v1.9.0
8+
)
9+
10+
require (
11+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
12+
github.com/labstack/gommon v0.4.0 // indirect
13+
github.com/mattn/go-colorable v0.1.11 // indirect
14+
github.com/mattn/go-isatty v0.0.14 // indirect
15+
github.com/valyala/bytebufferpool v1.0.0 // indirect
16+
github.com/valyala/fasttemplate v1.2.2 // indirect
17+
golang.org/x/crypto v0.7.0 // indirect
18+
golang.org/x/net v0.8.0 // indirect
19+
golang.org/x/sys v0.6.0 // indirect
20+
golang.org/x/text v0.8.0 // indirect
21+
)

backend/go.sum

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
5+
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
6+
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
7+
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
8+
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
9+
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
10+
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
11+
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
12+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
13+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
14+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
15+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
16+
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
17+
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
18+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
19+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
20+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
21+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
22+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
23+
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
24+
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
25+
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
26+
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
27+
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
28+
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
29+
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
30+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
31+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
32+
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
34+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
35+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
36+
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
37+
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
38+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
39+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
40+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
41+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

backend/main.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"github.com/labstack/echo/middleware"
6+
"net"
7+
"net/http"
8+
"os"
9+
10+
"github.com/labstack/echo"
11+
"github.com/sirupsen/logrus"
12+
)
13+
14+
var logger = logrus.New()
15+
16+
func main() {
17+
var socketPath string
18+
flag.StringVar(&socketPath, "socket", "/run/guest-services/backend.sock", "Unix domain socket to listen on")
19+
flag.Parse()
20+
21+
_ = os.RemoveAll(socketPath)
22+
23+
logger.SetOutput(os.Stdout)
24+
25+
logMiddleware := middleware.LoggerWithConfig(middleware.LoggerConfig{
26+
Skipper: middleware.DefaultSkipper,
27+
Format: `{"time":"${time_rfc3339_nano}","id":"${id}",` +
28+
`"method":"${method}","uri":"${uri}",` +
29+
`"status":${status},"error":"${error}"` +
30+
`}` + "\n",
31+
CustomTimeFormat: "2006-01-02 15:04:05.00000",
32+
Output: logger.Writer(),
33+
})
34+
35+
logger.Infof("Starting listening on %s\n", socketPath)
36+
router := echo.New()
37+
router.HideBanner = true
38+
router.Use(logMiddleware)
39+
startURL := ""
40+
41+
ln, err := listen(socketPath)
42+
if err != nil {
43+
logger.Fatal(err)
44+
}
45+
router.Listener = ln
46+
47+
router.GET("/hello", hello)
48+
49+
logger.Fatal(router.Start(startURL))
50+
}
51+
52+
func listen(path string) (net.Listener, error) {
53+
return net.Listen("unix", path)
54+
}
55+
56+
func hello(ctx echo.Context) error {
57+
return ctx.JSON(http.StatusOK, HTTPMessageBody{Message: "hello"})
58+
}
59+
60+
type HTTPMessageBody struct {
61+
Message string
62+
}

docker-compose.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
mindsdb:
3+
image: ajeetraina/mindsdb
4+
ports:
5+
- "47334:47334"
6+
- "8080:8080"
7+
volumes:
8+
- data:/opt/mindsdb/data
9+
- config:/opt/mindsdb/config
10+
11+
volumes:
12+
data:
13+
config:

docker.svg

+22
Loading

metadata.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"icon": "mindsdb.svg",
3+
"vm": {
4+
"composefile": "docker-compose.yaml",
5+
"exposes": {
6+
"socket": "backend.sock"
7+
}
8+
},
9+
"ui": {
10+
"dashboard-tab": {
11+
"title": "Mindsdb",
12+
"src": "index.html",
13+
"root": "ui"
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)