如何将 Visual Studio 代码扩展重新打包到具有自己的一组依赖项的 Che-Theia 插件中

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

我正在尝试将 Visual Studio 代码扩展作为 Che-Theia 插件重新打包到 Eclipse Che 中。 plug-in 从 Ansible 文件中提取源代码指标,如下所示:

它通过执行用 Python 编写的工具的命令行来实现,即 ansiblemetrics,必须安装在用户环境中。 因此,我无法将该依赖项添加到 VSC 扩展的 package.json。相反,用户必须将它安装在 Eclipse Che 工作区中。不过,我希望 Eclipse Che 用户在使用扩展时不需要安装依赖项。容器看起来不错。

我有以下 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

Eclipse docs 说“要将 VS Code 扩展重新打包为 Che-Theia 插件,并带有其自己的一组依赖项,请将依赖项打包到一个容器中。” 可以在 spec keyword:

下的 chePlugin 参考元数据中添加容器
spec:
  containers:                                                   
    - image:                                                    
      memoryLimit:                                              
      memoryRequest:                                            
      cpuLimit:                                                 
      cpuRequest:

因此,我的插件元数据(meta.yaml)如下:

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

图像 stefadp/radon-dpt-plugin 是基于以下 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

但是,当我在 Eclipse Che 中 运行 工作区时,我观察到以下错误:

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'"

你有什么提示吗?

您必须自定义 docker 图像才能在 sidecar 容器中工作。作为示例,您可以查看已在 Che in sidecars 中使用的图像:https://github.com/eclipse/che-plugin-registry/blob/master/CONTRIBUTE.md#sidecars

尝试创建下一个结构:

radon
  etc
    entrypoint.sh
  Dockerfile

entrypoint.sh的内容是:

#!/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 "$@"

Dockerfile 是:

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}

然后构建这个 Dockerfile 并在您的插件中使用它 meta.yaml