Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Add VSCode extension broker #19

Merged
merged 21 commits into from
Jan 10, 2019
Merged
9 changes: 5 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore binaries with these names but not folders with the same names
*/che-plugin-broker/che-plugin-broker
*/theia-plugin-broker/theia-plugin-broker
*/init/init-plugin-broker
*/init/init
*/che-plugin-broker/cmd/che-plugin-broker
*/theia/cmd/theia-plugin-broker
*/init/cmd/init-plugin-broker
*/vscode/cmd/vscode-extension-broker
*/cmd/cmd
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)

# Ignore binaries with these names but not folders with the same names
**/cmd/che-plugin-broker
che-plugin-broker
!che-plugin-broker/
garagatyi marked this conversation as resolved.
Show resolved Hide resolved
theia-plugin-broker
init-plugin-broker
*/init/init
!che-plugin-broker/
!theia-plugin-broker/
vscode-extension-broker
**/cmd/cmd

*.o
*.a
Expand All @@ -31,4 +32,4 @@ _testmain.go
*.exe
*.test
*.prof
.idea/
.idea/
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ script:
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo ./...
- golangci-lint run -v # run a bunch of code checkers/linters in parallel
- go test -v -race ./... # Run all the tests with the race detector enabled
- cd brokers/che-plugin-broker; CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -installsuffix cgo -o che-plugin-broker main.go
- cd brokers/theia-plugin-broker; CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -installsuffix cgo -o theia-plugin-broker main.go
- cd brokers/che-plugin-broker/cmd
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -installsuffix cgo -o che-plugin-broker main.go
- cd ../../theia/cmd
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -installsuffix cgo -o theia-plugin-broker main.go
- cd ../../vscode/cmd
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -installsuffix cgo -o vscode-extension-broker main.go
notifications:
email: false
112 changes: 84 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,139 @@
# This repo contains implmentations of several Che plugin brokers
# This repo contains implementations of several Che plugin brokers

## che-plugin-broker

### che-plugin-broker
Downloads tar.gz archive and:
- Evaluates Che workspace sidecars config from che-plugin.yaml located in a plugin archive and data
from config.json that is placed in workdir or different path if a corresponding broker argument is used.
It contains data about Che plugin or editor from meta.yaml

- Evaluates Che workspace sidecars config from che-plugin.yaml located in a plugin archive and data from config.json that is placed in workdir or different path if a corresponding broker argument is used. It contains data about Che plugin or editor from meta.yaml
- Copies dependency file/folder specified in dependencies.yaml inside of a plugin archive

### theia-plugin-broker
## theia-plugin-broker

Downloads .theia archive and:

- Unzip it to a temp folder
- Check content of package.json file in it. If it contains {"engines.cheRuntimeContainer"}
then this value is taken as container image for sidecar of a remote plugin. If it is missing or empty
plugin is considered non-remote
- Check content of package.json file in it. If it contains {"engines.cheRuntimeContainer"} then this value is taken as container image for sidecar of a remote plugin. If it is missing or empty plugin is considered non-remote
- Copies .theia file to /plugins/ for a non-remote plugin case
- Copies unzipped .theia to /plugins/ for a remote plugin case
- Sends following sidecar config to Che workspace master:
- with projects volume
- with plugin volume
- adds an endpoint with random port between 4000 and 6000 and name `port<port>`
- adds env var to workspace-wide env vars with name
`THEIA_PLUGIN_REMOTE_ENDPOINT_<plugin_publisher_and_name from package.json>` and value
- Evaluates Che workspace sidecar config for running Theia plugin as Che remote plugin in a sidecar:
- adds an endpoint with random port between 4000 and 6000 and name `port<port>`
- adds env var to workspace-wide env vars with name `THEIA_PLUGIN_REMOTE_ENDPOINT_<plugin_publisher_and_name from package.json>` and value
`ws://port<port>:<port>`
- adds env var to sidecar env vars with name
- adds env var to sidecar env vars with name
`THEIA_PLUGIN_ENDPOINT_PORT` and value `port`
- Evaluates Che workspace sidecar config for running Theia plugin as Che remote plugin in a sidecar
- adds projects volume
- adds plugin volume
- Sends sidecar config to Che workspace master

## init-plugin-broker

### init-plugin-broker
Cleanups content of /plugins/ folder.
Should be started before other brokers not to remove files they are adding to plugins folder.

### Development
## Build
## vscode-extension-broker

Downloads VS Code extension from marketplace and:

- Unzip it to a temp folder
- Check content of package.json file in it.
- Copies unzipped extension to /plugins/
- Evaluates Che workspace sidecar config for running VS Code extension as Che Theia remote plugin in a sidecar:
- adds an endpoint with random port between 4000 and 6000 and name `port<port>`
- adds env var to workspace-wide env vars with name
`THEIA_PLUGIN_REMOTE_ENDPOINT_<plugin_publisher_and_name from package.json>` and value
`ws://port<port>:<port>`
- adds env var to sidecar env vars with name
`THEIA_PLUGIN_ENDPOINT_PORT` and value `port`
- with projects volume
- with plugin volume
- Sends sidecar config to Che workspace master

## Development

### Build

- build all the code:

```shell
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo ./...
```

- build Che plugin broker binary:

```shell
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o che-plugin-broker brokers/che-plugin-broker/main.go
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o che-plugin-broker brokers/che-plugin-broker/cmd/main.go
```

- build Che Theia plugin broker binary:

```shell
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o theia-plugin-broker brokers/theia-plugin-broker/main.go
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o theia-plugin-broker brokers/theia/cmd/main.go
```

- build Init plugin broker binary:

```shell
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o init-plugin-broker brokers/init/main.go
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o init-plugin-broker brokers/init/cmd/main.go
```

- build VS Code extension broker binary:

```shell
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o vscode-extension-broker brokers/vscode/cmd/main.go
```

- run tests:

```shell
go test -v -race ./...
```

- run linters:

```shell
golangci-lint run -v
```

- run CI checks locally in Docker (includes build/test/linters):

```shell
docker build -f Dockerfile.CI .
docker build -f build/CI/Dockerfile .
```
## Dependencies

### Dependencies

Dependencies in the project are managed by Go Dep.
After you added a dependency you need to run the following command to download dependencies to vendor repo and lock file and then commit changes:

```shell
dep ensure
```

`dep ensure` doesn't automatically change Gopkg.toml which contains dependencies constrants.
So, when a dependency is introduced or changed it should be reflected in Gopkg.toml.
## Build of Docker images

### Build of Docker images

- build Che plugin broker

```shell
docker build -t eclipse/che-plugin-broker:latest -f Dockerfile.cpb .
```

- build Theia plugin broker

```shell
docker build -t eclipse/theia-plugin-broker:latest -f Dockerfile.tpb .
docker build -t eclipse/che-theia-plugin-broker:latest -f build/theia/Dockerfile .
```

- build Init plugin broker

```shell
docker build -t eclipse/init-plugin-broker:latest -f build/init/Dockerfile .
```

- build VS Code extension broker

```shell
docker build -t eclipse/init-plugin-broker:latest -f Dockerfile.ipb .
docker build -t eclipse/che-vscode-extension-broker:latest -f build/vscode/Dockerfile .
```
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func (cheBroker *ChePluginBroker) Start(metas []model.PluginMeta) {
cheBroker.PrintFatal(m)
}
cheBroker.PubStarted()
cheBroker.PrintInfo("Started Plugin Broker")
cheBroker.PrintInfo("Started Che Plugin Broker")

cheBroker.PrintPlan(metas)

cheBroker.PrintInfo("Starting plugins processing")
cheBroker.PrintInfo("Starting common Che plugins processing")
for _, meta := range metas {
err := cheBroker.processPlugin(meta)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"log"
"os"

"github.com/eclipse/che-plugin-broker/brokers/che-plugin-broker/broker"
broker "github.com/eclipse/che-plugin-broker/brokers/che-plugin-broker"
"github.com/eclipse/che-plugin-broker/cfg"
"github.com/eclipse/che-plugin-broker/common"
)
Expand Down
3 changes: 2 additions & 1 deletion brokers/init/main.go → brokers/init/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func main() {
defer broker.CloseConsumers()
broker.PushEvents(statusTun, model.BrokerLogEventType)

broker.PrintInfo("Starting Init Plugin Broker")
// Clear any existing plugins from /plugins/
log.Println("Cleaning /plugins dir")
broker.PrintInfo("Cleaning /plugins dir")
files, err := filepath.Glob(filepath.Join("/plugins", "*"))
if err != nil {
// Send log about clearing failure but proceed.
Expand Down
25 changes: 25 additions & 0 deletions brokers/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -42,6 +43,14 @@ func CreateDirByPath(path string) string {
return path
}

func CreateDirs(path string) string {
err := os.MkdirAll(path, 0755)
if err != nil {
log.Fatal(err)
}
return path
}

func CreateDir(parent string, name string) string {
d := filepath.Join(parent, name)
return CreateDirByPath(d)
Expand Down Expand Up @@ -116,3 +125,19 @@ func ToJSONQuiet(obj interface{}) string {
}
return string(fileContent)
}

// RoundTripFunc is a function that responses to requests from the argument.
// It is useful for testing purposes to check request or produce certain response
type RoundTripFunc func(req *http.Request) *http.Response

// Do no use it directly!
// This is needed to make RoundTripF implement http.RoundTripper
func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req), nil
}

func NewTestHTTPClient(fn RoundTripFunc) *http.Client {
return &http.Client{
Transport: RoundTripFunc(fn),
}
}
Loading