Investigate a possibility of using a Docker flow in Che
- Developers are being "programmed" to appreciate that for a project, the Dockerfile or docker-compose.yml will be in the root of the repository.
- Developers expect as part of their workflow to "git clone
; docker-compose up -d" So, in our world, the developer will still need a workspace, but they will expect to keep using the development workflow that is familiar to them. This means that:
- They believe that (most) everything they need is in the repository already.
- The repository will have the files necessary to bootstrap the workspace's runtime as a combination of an already existing Dockerfile, docker-compose.yml ... optionally combined with additional info from within a Chefile.
- The workspace (after bootstrapped), would have 1..n projects which have the source code from the repository in it, and that source code would have Dockerfile, docker-compose.yml.
- Developers inside of the workspace will optionally be able to use their expected workflow "docker run
" ... or "docker-compose up". These commands will know how to volume mount the source code that is in the workspace.
- If a repo that is to be used to bootstrap a workspace has a Dockerfile, docker-compose.yml, and / or Chefile, then a "workspace created from repo" should have a bootstrapping algorithm around:
- verify SSH / oAuth
- check repo for necessary Dockerfile, docker-compose.yml, Chefile
- define workspace runtime through some precedent sequence
- start workspace
- create initial project from source repo.
We just need to embrace this workflow INSIDE of che - so that it's honored in the UD and other places where you create new workspaces.
I think one comment that is important is that the precedence of how we investigate files within an existing repository during the workspace runtime boot sequence. The precedence should be (Chefile), .codenvy.json (which should really be replaced by Chefile), docker-compose.yml, Dockerfile, (nothing). If (nothing), then the user would be forced to choose a stack from within the stack selector in the UD.
What kind of repository we should work with? Is it github, possible other git-based repositories or even svn?
We discussed possible ways of usage of docker-compose up or docker run in workspaces. There are 2 solutions we see right now.
- Use privileged containers in Che or Codenvy enterprise. This option is not secure for Codenvy Saas.
- Implement another type of machine based on some virtualization technology. In that case we will be able to use it in non-trusted environments like Codenvy Saas.
As for the creation of workspace from some repo here is what we considered: 3. We already have something like that in Codenvy Factories. Implemented by Florent. We can move that functionality in Che and adapt it if needed. It would be the best choice in terms of time, efforts to implement that and functionality. It is the only option we all considered as good one. Others probably require significant efforts and changes in our model/vision/infrastructure. 4. Quite often docker build and docker-compose up relies on other files in the repo. If we need to support that then we will have to clone whole repo to create WS and it is not easy to implement reliable solution for this. 5. Quite often docker build and docker-compose up relies on built binaries of application. Since there is no precompiled binaries in repo and we don't have needed runtime to built it such cases are hard to implement and support. So if binaries are needed they should be built in docker file build phase. Dockerfiles that relies on existing binaries we probably won't support.
I think there is a third possibility for usage of docker-compose up or docker run in workspaces - volume mounting /var/run/docker.sock:/var/run/docker.sock into a workspace's containers AND then have a "docker agent" which installs docker CLI utilities into the workspace. This would then allow the end user to create containers that are peers on the host. This woudl create certain challenges about how we constrain RAM and CPU for a workspace. However, I would see this feature as potentially only available in Che or Codenvy On-Prem, but not necessarily codenvy.io as the sprawl issue could be unmanageable for a shared infrastructure.
On your point #4 and #5:
In the bootstrapping use case, the repo's Dockerfile or docker-compose.yml would need to follow the guidelines that we have for building images in a distributed system. I don't think we would change those. If you need something more sophisticated, I think we would try to encourage users to create a Chefile which then has recipes that reference already-built images to be used. So I think we could say that auto-using Dockerfile and docker-compose.yml is a good thing but with a lot of limitations. And when using them, we should probably display in the workspace startup logs all of the things we are ignoring in those files with a message that a repository Chefile may offer more functionality.
Your point about needing all files from a repo to build the Dockerfile is a good one. We could consider respecting the .dockerignore file in the repo to simplify cloning the code?
If we have determeined that your Dockerfile is the source of our workspace definition and we initiate a local build, we would want to add some sort of logic to see if the build was successful or not. A failed build in this case would be a special case error where we would then want to provide a friendly message to the end user that shows a few things.
a) We tried to create a workspace from your repository's Dockerfile, but we could not build it.
b) This usually happens because there are other files that have to be pre-compiled first for the Dockerfile to be built.
c) Your repository should consider adding a Chefile which includes references to pre-built images we can use to more easily bootstrap a developer workspace.
d) You can now select from our of our built-in stacks with runtimes to start the workspace.
e) After the workspace is started, you can use docker build and docker-compose up to work with Docker and the source files at the same time.
Usage of docker socket is pretty the same as usage of privileged containers. Because it allows to run privileged containers. So it is non-secure solution that can not be used in untrusted environments like Codenvy Saas or Codenvy Enterprise for organizations with strict security requirements. And I really don't see how we can manage RAM and CPU for this case.
As for your comment on workspace creation from repo I agree that we should put limitations/rules on features list we support. And +1 to inform user on what was ignored. .gitignore can improve build image process but it doesn't eliminate threat of abusing system with repo that doesn't have .gitignore or it is not too restrictive and there are huge amount of files. To do builds of images with support of some context we would have to perform it on some sort of docker nodes with the same policy as docker machines have. This solution would require us to change our infrastructure by adding special build nodes or creation of new concept of containers on docker nodes that are not machines and should not be treated as machines by our tools and admins.
@garagatyi I personally like the Implement another type of machine based on some virtualization technology. In that case we will be able to use it in non-trusted environments like Codenvy Saas. option. This would give users "unrestricted" use of docker without any non-supported syntax. Would we use a privileged docker container to start virtualization software from inside then give user access only to the virtual machine and no access to privileged container? Also, not sure about the IP licensing restrictions this would impose https://en.wikipedia.org/wiki/Comparison_of_platform_virtualization_software. We should consider performance and resources if we use vitalization. Possibly make it a stack option/plugin to add docker to a workspace.
In that case user will be in his own VM, so it is not related to privileged mode.
@garagatyi We should have vm inside a privileged docker container. This may make things easier for us as we will not have to worry about native os environment. https://github.com/Ulexus/docker-qemu
I'm not sure this will work inside of other VMs like VM on amazon, digital ocean, azure, etc.
BTW my point was not in running VM inside of container, but running VM instead of container. Then it is safe to run container inside of this VM.
Could be safe to run container > VM > container . Think there will be more issues with VM > container but I really haven't investigated. The reason I think container > VM > container will be safer is that we already know docker will run. Putting VM directly on native OS COULD cause more issues. I would just like us to look into both.
@slemeur is it still relevant ?
Closing as we have handle most of the use cases with Chefile.