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

时间:2017-12-21 07:23:33

标签: eclipse-che

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

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

我想要达到什么目的:

  • [完成] 在我的工作站上安装了Eclipse Che
  • [完成] 使用Dockerfile语法或本地Docker镜像创建自己的自定义堆栈的能力(我的工作站上的图像不在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. 中建议的sudo docker build -f custom.dockerfile -t my-custom-image .图片
  3. 然后我使用从食谱构建堆栈创建了Che堆栈。

  4. 之后我创建了一个基于此堆栈的工作区,它正常运行。

  5. 这种方法有一个明显的缺点:重新启动工作站后从Dockerfile重建工作区!只要Dockerfile包含安装命令,该过程需要相当长的时间,显然需要互联网连接。

    2。基于本地Docker镜像的堆栈

    1. 我使用自定义Dockerfile在本地构建docker镜像:

      { "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" }

    2. 然后我使用以下配置创建了两个Che堆栈:

      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.
    3. 基于这些堆栈的工作空间无法创建错误:

      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

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

    4. 看起来Che在我的工作站上没有看到Docker图像。

      所以问题是:有没有办法用Che实现我的目标?或者Che对我来说不是正确的工具?

      更新1

      第3。设置本地docker注册表(docs

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

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

        sudo docker tag my-custom-image localhost:5000/my-custom-image sudo docker push localhost:5000/my-custom-image

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

        localhost:5000/my-custom-image
      4. 使用图片 public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("bill").password("abc123").roles("ADMIN").and() .withUser("bob").password("abc123").roles("USER"); }

      5. 创建自定义堆栈

        这种方法有效,但有一个明显的缺点:维护docker注册表的必要性

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

1 个答案:

答案 0 :(得分:4)

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