如何在工作站主机上使用自定义 Eclipse Che 堆栈?
How to use custom Eclipse Che stacks on workstation host?
我想知道在工作站上 运行 Che 时使用自定义 Eclipse Che 堆栈的方便方法是什么。
我非常喜欢 Eclipse Che 的概念:为不同的开发环境提供单独的 Che 工作区(Docker 容器)并安装相应的工具。工作区是从 Che 堆栈初始化的。堆栈可以定义为 Docker 图像或使用 Docker 文件或 Docker 作曲家文件动态创建。
我想达到什么目的:
- [完成] 在我的工作站上安装了 Eclipse Che
- [完成] 使用 Docker 文件语法或本地 Docker 图像(我工作站上的图像不在 Docker 存储库)
- [完成] 能够无痛地 reboot/shutdown 我的工作站
- [完成] 有一个合理的工作区启动时间
我已经试过了:
1.按配方定义堆栈(Docker文件)
我写了我的自定义 Docker 文件用于测试目的:
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 会从 Docker 文件重建工作区! 只要 Docker 文件包含安装命令,这个过程需要相当长的时间,显然需要互联网连接。
2。基于本地Docker图像的堆叠
我使用自定义 Docker 文件在本地构建 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实现我的目标?或者 Che 不是适合我的工具?
更新 1
3。设置本地 docker 注册表 (https://docs.docker.com/registry/)
设置本地 docker 注册表:https://docs.docker.com/registry/deploying/
使用Docker文件构建自定义图像
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 注册表。
不管怎样,我可以在我的愿望清单中勾选两个复选框。
如果您想使用本地图像,请在 che.env 中设置 CHE_DOCKER_ALWAYS__PULL__IMAGE=false
并重新启动 Che。
我想知道在工作站上 运行 Che 时使用自定义 Eclipse Che 堆栈的方便方法是什么。
我非常喜欢 Eclipse Che 的概念:为不同的开发环境提供单独的 Che 工作区(Docker 容器)并安装相应的工具。工作区是从 Che 堆栈初始化的。堆栈可以定义为 Docker 图像或使用 Docker 文件或 Docker 作曲家文件动态创建。
我想达到什么目的:
- [完成] 在我的工作站上安装了 Eclipse Che
- [完成] 使用 Docker 文件语法或本地 Docker 图像(我工作站上的图像不在 Docker 存储库)
- [完成] 能够无痛地 reboot/shutdown 我的工作站
- [完成] 有一个合理的工作区启动时间
我已经试过了:
1.按配方定义堆栈(Docker文件)
我写了我的自定义 Docker 文件用于测试目的:
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 会从 Docker 文件重建工作区! 只要 Docker 文件包含安装命令,这个过程需要相当长的时间,显然需要互联网连接。
2。基于本地Docker图像的堆叠
我使用自定义 Docker 文件在本地构建 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实现我的目标?或者 Che 不是适合我的工具?
更新 1
3。设置本地 docker 注册表 (https://docs.docker.com/registry/)
设置本地 docker 注册表:https://docs.docker.com/registry/deploying/
使用Docker文件构建自定义图像
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 注册表。
不管怎样,我可以在我的愿望清单中勾选两个复选框。
如果您想使用本地图像,请在 che.env 中设置 CHE_DOCKER_ALWAYS__PULL__IMAGE=false
并重新启动 Che。