簡體   English   中英

如何將 Visual Studio Code 擴展重新打包到具有自己的依賴項集的 Che-Theia 插件中

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

我正在嘗試將 Visual Studio Code 擴展重新打包到 Eclipse Che 作為 Che-Theia 插件。 插件從 Ansible 文件中提取源代碼指標,如下所示:

替代文字

它通過執行一個用 Python 編寫的工具(即ansiblemetrics )的命令行來實現,該工具必須安裝在用戶的環境中。 因此,我無法將該依賴項添加到 VSC 擴展的 package.json。 相反,用戶必須將其安裝在 Eclipse Che 工作區上。 盡管如此,我希望 Eclipse Che 用戶在使用擴展時不需要安裝依賴項。 一個容器看起來通往 go。

我有以下 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 文檔說“要將 VS Code 擴展重新打包為帶有自己的一組依賴項的 Che-Theia 插件,package 將依賴項打包到一個容器中。” 容器可以添加到 chePlugin 引用的元數據中的spec關鍵字下:

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

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

元.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 容器中工作。 作為示例,您可以查看已在 Sidecars 中的 Che 中使用的圖像: 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中使用它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM