How to use custom Eclipse Che stacks on workstation host?

感情迁移 提交于 2019-12-06 05:22:22

问题


I wonder what is a convenient way to use custom Eclipse Che stacks when running Che on a workstation.

I really like the concept of Eclipse Che: to have separate Che workspaces (Docker containers) for different development environments with corresponding tools installed. Workspaces are initialized from Che stacks. Stacks can be defined as Docker images or dynamically created using Dockerfiles or Docker composer files.

What do I want to achieve:

  • [done] have Eclipse Che installed on my workstation
  • [done] ability to create my own custom stacks using Dockerfile syntax or local Docker images (images on my workstation not in Docker repository)
  • [done] ability to painlessly reboot/shutdown my workstation
  • [done] have a reasonable workspace startup time

I have already tried:

1. Define stack by recipe (Dockerfile)

  1. I wrote my custom Dockerfile for test purposes:

    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/*
    

    It's based on eclipse/stack-base:ubuntu image as it is suggested in the docs

  2. Then I created Che stack using Build Stack From Recipe.

  3. After that I created a workspace based on this stack, it functions correctly.

This method has a significant drawback: after a reboot of my workstation Che rebuilds workspace from Dockerfile! As long as Dockerfile contains installation commands, the process takes considerable amount of time and obviously requires internet connection.

2. Stack based on local Docker image

  1. I used my custom Dockerfile to build docker image locally:

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

  2. Then I created two Che stacks with the following configurations:

    {
      "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"
    }
    
  3. Workspaces based on these stacks fail to create with errors:

    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

It looks like Che does not see Docker images on my workstation.

So the question is: Is there any way to achieve my goals with Che? Or Che is not the right tool for me?

Update 1

3. Setup local docker registry (https://docs.docker.com/registry/)

  1. Setup local docker registry: https://docs.docker.com/registry/deploying/

  2. Use Dockerfile to build a custom image

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

  3. Tag it and push it to local registry

    sudo docker tag my-custom-image localhost:5000/my-custom-image
    sudo docker push localhost:5000/my-custom-image
    
  4. Create custom stack using image localhost:5000/my-custom-image

This approach works but has a definite drawback: necessity to maintain docker registry.

Anyway it works and I can tick two check-boxes in my whish-list.


回答1:


If you want to use a local image, set CHE_DOCKER_ALWAYS__PULL__IMAGE=false in your che.env and restart Che.



来源:https://stackoverflow.com/questions/47919884/how-to-use-custom-eclipse-che-stacks-on-workstation-host

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!