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

标签 eclipse-che

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

我真的很喜欢 Eclipse Che 的概念:为不同的开发环境提供单独的 Che 工作区(Docker 容器),并安装相应的工具。工作区从 Che 堆栈初始化。堆栈可以定义为 Docker 镜像,也可以使用 Dockerfiles 或 Docker composer 文件动态创建。

我想达到什么目标:

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

  • 我已经尝试过:

    1. 按配方定义堆栈(Dockerfile)
  • 我编写了我的自定义 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 docs 中建议的图像
  • 然后我使用 Build Stack From Recipe 创建了 Che 堆栈。
  • 之后,我基于此堆栈创建了一个工作区,它运行正常。

  • 这种方法有一个明显的缺点:在我的工作站重新启动后,Che 会从 Dockerfile 重建工作区!只要 Dockerfile 包含安装命令,该过程就会花费大量时间,并且显然需要互联网连接。

    2. 基于本地Docker镜像的堆栈
  • 我使用我的自定义 Dockerfile 在本地构建 docker 镜像:
    sudo docker build -f custom.dockerfile -t my-custom-image .
  • 然后我使用以下配置创建了两个 Che 堆栈:
    {
      "scope": "general",
      "description": "Custom1",
      "tags": [],
      "workspaceConfig": {
        "environments": {
          "default": {
            "recipe": {
              "contentType": "text/x-dockerfile",
              "type": "dockerfile",
              "content": "FROM my-custom-image\n"
            },
            "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-image\n"
            },
            "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"
    }
    
  • 基于这些堆栈的工作区无法创建并出现错误:
    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 不适合我?

    更新 1

    3. 设置本地 docker 注册表 ( https://docs.docker.com/registry/ )
  • 设置本地 docker 注册表:https://docs.docker.com/registry/deploying/
  • 使用 Dockerfile 构建自定义镜像
    sudo docker build -f custom.dockerfile -t my-custom-image .
  • 标记它并将其推送到本地注册表
    sudo docker tag my-custom-image localhost:5000/my-custom-image
    sudo docker push localhost:5000/my-custom-image
    
  • 使用图像创建自定义堆栈 localhost:5000/my-custom-image

  • 这种方法有效,但有明确的 缺点:必须维护 docker 注册表 .

    无论如何它都有效,我可以在我的愿望 list 中勾选两个复选框。

    最佳答案

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

    关于eclipse-che - 如何在工作站主机上使用自定义 Eclipse Che 堆栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47919884/

    相关文章:

    java - 如何在 Eclipse Che Java 项目中添加用户库?

    go - 无法在 eclipse che 中运行 delve - 无法启动进程,不允许操作

    python - 必须不断重新安装 python 模块 (Eclipse Che)?

    ubuntu - ubuntu下无法运行Eclipse Che

    java - 是否可以在 Eclipse Che 中使用/打开 GUI?

    java - 如何在 Eclipse Che 中运行 java 类

    eclipse - 如何在dockerfile中包含本地语言服务器并从中构建docker镜像?