【问题标题】:How to repackage a Visual Studio Code extension into a Che-Theia plug-in with its own set of dependencies如何将 Visual Studio Code 扩展重新打包到具有自己的依赖项集的 Che-Theia 插件中
【发布时间】:2021-01-27 12:28:15
【问题描述】:

我正在尝试将 Visual Studio Code 扩展重新打包到 Eclipse Che 作为 Che-Theia 插件。 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'"

你有什么提示吗?

【问题讨论】:

    标签: plugins containers eclipse-che


    【解决方案1】:

    您必须自定义 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

    【讨论】:

    • 您好,感谢您的回答,但这并没有真正的帮助。该来源解释了如何在 Che 上发布插件(作为内置)。我只是想将我的插件添加为第三方。通过定义 meta.yml 文件很简单。但是,如果我避免使用依赖项,从而避免使用容器,它就可以正常工作。当我在元数据中添加“容器”部分时出现问题,这是允许的,但我可能遗漏了一些东西。
    • 我已经更新了我的评论,希望对你有所帮助。
    • 非常感谢,效果很好!您能否修改您的答案并在 entrypoint.sh 的第一行添加 #!/bin/sh ?这样使用此答案的用户就不必面对以下错误:standard_init_linux.go:211: exec user process cause "exec format error"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 2016-01-19
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2014-04-25
    相关资源
    最近更新 更多