Rudimentary devcontainer support for Emacs
This package lets you handle i.e. start, restart devcontainers of your projects
and forwards all your compile commands into the devcontainer by advising
compilation-start. So as long you use compile to build, test and run
(parts of your) software, all will be executed inside the devcontainer.
The the documentation on how to setup and use the package.
Devcontainers become increasingly popular in modern software development. The idea is to put everything the software you are developing needs in order to run into a docker container or a stack of docker containers. Then all your local builds and testing is performed inside that container. So your development basically takes place inside the docker container – hence the name "devcontainer".
The initiative came from the Visual Studio Code community. They actually run the complete tooling inside the container, even their IDE. The configuration of the IDE – i.e. which extensions are to be installed – is also defined by the definition of the devcontainer.
While you technically don't need to use devcontainers even though your team is
using them, it is convenient for you also to use devcontainers at least to some
degree. Of course, you won't install an Emacs instance inside the
devcontainer, but it is really helpful for you to manage devcontainers from
within Emacs and interact with the installation of your software inside of it.
That's where the devcontainer package comes in.
devcontainer provides a set Emacs commands to build, launch, stop, erase
and rebuild the devcontainer according to its definition in the project's repo.
In order for you to run and test your software inside the devcontainer,
devcontainer-mode advises Emacs' compilation-start function to prepend
devcontainer exec --workspace-folder . to your compilation command and thus
runs the compilation command inside the container.
Usually you would mount your local working directory into your devcontainer.
Then you edit files just like without using devcontainer. Then, launching any
kind of compile command, it is actually performed inside your devcontainer.
Development started about a year ago. Since then it has been of big help
to me in my day job programming. With my usual workflows, the packages just
does its job and otherwise stays out of my way. As I don't tend to experiment
that much with edge cases, I might not be aware of caveats, when different
workflows are used. This might especially the case if you are using podman
as container engine rather than docker.
If you experience any issues, please report them back in the issue tracker.
Important
Please consider this package experimental as long as there is no release yet. There might be breaking changes like changing function and variable names out of the blue. So please consider checking the git history when updating.
You need to have the devcontainers/cli
command line tool installed into your execution path. For that you need a
working node/npm setup. Then you can install the tool with
npm install -g @devcontainers/cli
Of course you also need a working docker installation and probably also docker compose. Alternatively you can also use podman.
Easiest way to install is from MELPA. If you have
configured the MELPA sources you can just install the devcontainer
package using the package-install command.
You can of course also use straight.el. Put the following lines into your startup file.
(use-package devcontainer
:straight (devcontainer :type git :host github :repo "johannes-mueller/devcontainer.el"))- See how it works in practice (it baisically works and is helpful)
- Fix things that don't work (see issues)
- Document things that work
- See if we find a way to reliably connect to a language server inside the
container. Maybe find inspiration from
eglot-booster-mode. - See if we can get dape to work with
devcontainer-mode. - See if anything more is needed that can be implemented with a reasonable effort.
- Announce it to melpa
- Enjoy the
devcontainerpackage in real life programming
At this stage of development it would be great if you share your thoughts on the discussion page. If you have something more concrete, you can for sure also file an issue.
This package uses unit tests defined by Emacs' built in ERT testing framework. An easy way to run the tests is ert-runner.el. To run the test suite from the command line simply
- Install Cask on your system
- Open a shell in the repo's root directory
- Install the rependencies using
$ cask install
- Run the test suite using
$ cask exec ert-runner
If you want to run the tests interactively from within emacs, you might want to take a look at test-cockpit.el.