如何在工作站主机上使用自定义Eclipse Che堆栈



我想知道什么是在工作站上运行CHE时使用自定义Eclipse Che堆栈的方便方法。

我真的很喜欢Eclipse Che的概念:使用已安装相应工具的不同开发环境,拥有单独的CHE工作区(Docker容器)。工作区是从CHE堆栈初始化的。堆栈可以定义为Docker图像,也可以使用Dockerfiles或Docker Composer Files动态创建。

我想实现什么:

  • [完成] 在我的工作站上安装了Eclipse Che
  • [完成] 能够使用Dockerfile语法或本地Docker images创建自己的自定义堆栈(我的工作站上的图像不在Docker存储库中)
  • [完成] 能够无痛重新启动/关闭我的工作站
  • [完成] 有一个合理的工作空间启动时间

我已经尝试过:

1。通过食谱(Dockerfile)定义堆栈

  1. 我为测试目的写了我的自定义Dockerfile:

    FROM eclipse/stack-base:ubuntu
    RUN sudo apt-get update
    RUN sudo apt-get install -y apt-transport-https
    RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
    RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
    RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    RUN sudo apt-get install -y nodejs build-essential mongodb-org
    RUN sudo apt-get clean
    RUN sudo apt-get -y autoremove
    RUN sudo apt-get -y clean
    RUN sudo rm -rf /var/lib/apt/lists/*
    

    它基于 eclipse/stack-base:ubuntu图像,因为它在文档中建议

  2. 然后,我使用从食谱中构建堆栈

  3. 创建了CHE堆栈
  4. 之后,我创建了一个基于此堆栈的工作空间,它的功能正确。

此方法具有重要的缺点:在重新启动我的工作站Che Che Che Rebuilds Workspace之后,只要DockerFile包含安装命令,该过程就需要大量时间,并且显然需要Internet连接。

2。基于本地码头图像

堆栈
  1. 我使用我的自定义Dockerfile在本地构建Docker图像:

    sudo docker build -f custom.dockerfile -t my-custom-image .

  2. 然后,我创建了两个具有以下配置的CHE堆栈:

    {
      "scope": "general",
      "description": "Custom1",
      "tags": [],
      "workspaceConfig": {
        "environments": {
          "default": {
            "recipe": {
              "contentType": "text/x-dockerfile",
              "type": "dockerfile",
              "content": "FROM my-custom-imagen"
            },
            "machines": {
              "dev-machine": {
                "servers": {},
                "agents": [
                  "org.eclipse.che.ws-agent",
                  "org.eclipse.che.ssh",
                  "org.eclipse.che.terminal",
                  "org.eclipse.che.exec"
                ],
                "attributes": {
                  "memoryLimitBytes": "2147483648"
                }
              }
            }
          }
        },
        "defaultEnv": "default",
        "commands": [],
        "projects": [],
        "name": "default",
        "links": []
      },
      "components": [],
      "creator": "che",
      "name": "my-custom-1",
      "id": "stackx6hs410a9awhu299"
    }
    {
      "scope": "general",
      "description": "Custom2",
      "tags": [],
      "workspaceConfig": {
        "environments": {
          "default": {
            "recipe": {
              "contentType": "application/x-yaml",
              "type": "compose",
              "content": "services:n dev-machine:n  image: my-custom-imagen"
            },
            "machines": {
              "dev-machine": {
                "servers": {},
                "agents": [
                  "org.eclipse.che.exec",
                  "org.eclipse.che.terminal",
                  "org.eclipse.che.ws-agent",
                  "org.eclipse.che.ssh"
                ],
                "attributes": {
                  "memoryLimitBytes": "2147483648"
                }
              }
            }
          }
        },
        "defaultEnv": "default",
        "commands": [],
        "projects": [],
        "name": "custom",
        "links": []
      },
      "components": [],
      "creator": "che",
      "name": "my-custom-2",
      "id": "stack55s3tso56cljsf30"
    }
    
  3. 基于这些堆栈的工作空间无法使用错误创建:

    Could not start workspace my-custom-1. Reason: Start of environment 'default' failed. Error: Docker image build failed. Image id not found in build output.

    Could not start workspace my-custom-2. Reason: Start of environment 'default' failed. Error: Can't create machine from image. Cause: Error response from docker API, status: 404, message: repository my-node-mongo not found: does not exist or no pull access

看来CHE在我的工作站上看不到Docker的图像。

所以问题是:有什么办法可以用CHE实现我的目标?或CHE不是我的正确工具?

更新1

3。设置本地Docker注册表(https://docs.docker.com/registry/)

  1. 设置本地码头注册表:https://docs.docker.com/registry/registry/deploying/

  2. 使用Dockerfile构建自定义图像

    sudo docker build -f custom.dockerfile -t my-custom-image .

  3. 标记并将其推到本地注册表

    sudo docker tag my-custom-image localhost:5000/my-custom-image
    sudo docker push localhost:5000/my-custom-image
    
  4. 使用图像localhost:5000/my-custom-image

  5. 创建自定义堆栈

此方法有效,但具有确定的缺点:必须维护Docker注册表

无论如何它都可以工作,我可以在我的whish list中勾选两个复选框。

如果要使用本地图像,请在che.env中设置 CHE_DOCKER_ALWAYS__PULL__IMAGE=false并重新启动che。

最新更新