Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

plugins - How to repackage a Visual Studio Code extension into a Che-Theia plug-in with its own set of dependencies

I am trying to repackage a Visual Studio Code extension into Eclipse Che as a Che-Theia plug-in. The plug-in extracts source code metrics from Ansible files, as shown below:

Alt Text

It does so by executing a command-line of a tool written in Python, namely ansiblemetrics, that must be installed on the user's environment. Therefore, I cannot add that dependency to the VSC extension's package.json. Rather, the user has to install it on the Eclipse Che workspace. Nevertheless, I want that Eclipse Che users do not need to install the dependencies when using the extension. A container looks the way to go.

I have the following Eclipse Che DevFile

Eclipse Che DevFile

apiVersion: 1.0.0
metadata:
  name: python-bd3zh
attributes:
  persistVolumes: 'false'
projects:
  - name: python-hello-world
    source:
      location: 'https://github.com/che-samples/python-hello-world.git'
      type: git
      branch: master
components:
  - type: chePlugin
    reference: 'https://raw.githubusercontent.com/radon-h2020/radon-plugin-registry/master/radon/radon-defect-predictor/latest/meta.yaml'
    alias: radon-dpt

The Eclipse docs says "To repackage a VS Code extension as a Che-Theia plug-in with its own set of dependencies, package the dependencies into a container." Containers can be added in the chePlugin reference's metadata under the spec keyword:

spec:
  containers:                                                   
    - image:                                                    
      memoryLimit:                                              
      memoryRequest:                                            
      cpuLimit:                                                 
      cpuRequest:

Therefore, my plugin's metadata (meta.yaml) is as follows:

meta.yaml

apiVersion: v2
publisher: radon
name: radon-defect-predictor
version: 0.0.5
type: VS Code extension
displayName: RADON-h2020 Defect Predictor
title: A Defect Predictor for Infrastructure-as-Code by RADON
description: A customized extension for analyzing the defectiveness of IaC blueprints
icon: https://www.eclipse.org/che/images/logo-eclipseche.svg
repository: https://github.com/radon-h2020/radon-defect-prediction-plugin
category: Other
spec:
  containers:                                                   
    - image: stefadp/radon-dpt-plugin
  extensions:
    - https://raw.githubusercontent.com/radon-h2020/radon-defect-prediction-plugin/master/radon-defect-predictor-0.0.5.vsix

where the image stefadp/radon-dpt-plugin was built upon the following Dockerfile:

Dockerfile

FROM ubuntu:latest

RUN apt-get update 
  && apt-get install -y python3-pip python3-dev 
  && cd /usr/local/bin 
  && ln -s /usr/bin/python3 python 
  && pip3 install --upgrade pip

RUN pip3 install ansiblemetrics

However, when I run the workspace in Eclipse Che, I observe the following error:

pulling image "quay.io/eclipse/che-plugin-metadata-broker:v3.4.0"
Successfully pulled image "quay.io/eclipse/che-plugin-metadata-broker:v3.4.0"
Created container
Started container
Starting plugin metadata broker
List of plugins and editors to install
- radon/radon-defect-predictor/0.0.6 - A customized extension for analyzing the defectiveness of IaC blueprints
- eclipse/che-workspace-telemetry-woopra-plugin/0.0.1 - Telemetry plugin to send information to Woopra
- eclipse/che-machine-exec-plugin/7.24.2 - Che Plug-in with che-machine-exec service to provide creation terminal or tasks for Eclipse Che workspace containers.
- eclipse/che-theia/7.24.2 - Eclipse Theia
All plugin metadata has been successfully processed
pulling image "quay.io/eclipse/che-theia-endpoint-runtime-binary:7.24.2"
Successfully pulled image "quay.io/eclipse/che-theia-endpoint-runtime-binary:7.24.2"
Created container
Started container
pulling image "quay.io/eclipse/che-plugin-artifacts-broker:v3.4.0"
Successfully pulled image "quay.io/eclipse/che-plugin-artifacts-broker:v3.4.0"
Created container
Started container
Starting plugin artifacts broker
Cleaning /plugins dir
Processing plugin radon/radon-defect-predictor/0.0.6
  Installing plugin extension 1/1
    Downloading plugin from https://raw.githubusercontent.com/radon-h2020/radon-plugin-registry/master/radon/radon-defect-predictor/0.0.6/radon-defect-predictor-0.0.6.vsix
Saving log of installed plugins
All plugin artifacts have been successfully downloaded
pulling image "quay.io/eclipse/che-jwtproxy:0.10.0"
Successfully pulled image "quay.io/eclipse/che-jwtproxy:0.10.0"
Created container
Started container
pulling image "stefadp/radon-dpt-plugin"
Successfully pulled image "stefadp/radon-dpt-plugin"
Created container
Started container
pulling image "quay.io/eclipse/che-workspace-telemetry-woopra-plugin:latest"
Successfully pulled image "quay.io/eclipse/che-workspace-telemetry-woopra-plugin:latest"
Created container
Started container
pulling image "quay.io/eclipse/che-machine-exec:7.24.2"
Successfully pulled image "quay.io/eclipse/che-machine-exec:7.24.2"
Created container
Started container
pulling image "quay.io/eclipse/che-theia:7.24.2"

Error: Failed to run the workspace: "The following containers have terminated:
nt0: reason = 'Completed', exit code = 0, message = 'null'"

Do you have any hint?

question from:https://stackoverflow.com/questions/65919180/how-to-repackage-a-visual-studio-code-extension-into-a-che-theia-plug-in-with-it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to customize your docker image to work in the sidecar container. As an example you can take a look at images which are already used in Che in sidecars: https://github.com/eclipse/che-plugin-registry/blob/master/CONTRIBUTE.md#sidecars

Try to create next structure:

radon
  etc
    entrypoint.sh
  Dockerfile

The content of entrypoint.sh is:

#!/bin/sh
set -e
set -x

USER_ID=$(id -u)
export USER_ID
GROUP_ID=$(id -g)
export GROUP_ID

if ! whoami >/dev/null 2>&1; then
    echo "${USER_NAME:-user}:x:${USER_ID}:0:${USER_NAME:-user} user:${HOME}:/bin/sh" >> /etc/passwd
fi

# Grant access to projects volume in case of non root user with sudo rights
if [ "${USER_ID}" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
    sudo chown "${USER_ID}:${GROUP_ID}" /projects
fi

exec "$@"

and the Dockerfile is:

FROM ubuntu:latest

ENV HOME=/home/theia

RUN mkdir /projects ${HOME} && 
    # Change permissions to let any arbitrary user
    for f in "${HOME}" "/etc/passwd" "/projects"; do 
      echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && 
      chmod -R g+rwX ${f}; 
    done

RUN apt-get update 
  && apt-get install -y python3-pip python3-dev 
  && cd /usr/local/bin 
  && ln -s /usr/bin/python3 python 
  && pip3 install --upgrade pip

RUN pip3 install ansiblemetrics

ADD etc/entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}

Then build this Dockerfile and use it in your plugin meta.yaml


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...