Reputation: 1149
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.
1. Define stack by recipe (Dockerfile)
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
Then I created Che stack using Build Stack From Recipe.
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
I used my custom Dockerfile to build docker image locally:
sudo docker build -f custom.dockerfile -t my-custom-image .
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"
}
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?
3. Setup local docker registry (https://docs.docker.com/registry/)
Setup local docker registry: https://docs.docker.com/registry/deploying/
Use Dockerfile to build a custom image
sudo docker build -f custom.dockerfile -t my-custom-image .
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
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.
Upvotes: 4
Views: 1256
Reputation: 500
If you want to use a local image, set CHE_DOCKER_ALWAYS__PULL__IMAGE=false
in your che.env and restart Che.
Upvotes: 5