Saturday, February 11, 2017

CoVim as a service

Following are my notes for creating a CoVim service, in Docker, on Ubuntu 16.04.  It should be quite easy to port this to other Linux distros (probably even Windows with the proper libs):

Note: this assumes that each student also has a current Vim instance, as well as the CoVim plugin, installed on their system.  If they don't, the Docker file can also be used as a recipe for building and installing Vim and CoVim on each student's workstation.

Steps:

1) (as root) Create a working folder and cd into it.

  mkdir work && cd work

2) Inside of the work folder, create a Dockerfile containing the following:

  FROM        ubuntu:16.04
  MAINTAINER  Tim Kramer <joatblog@gmail.com>
  # Date: 04 Feb 2017

  # This Dockerfile will install build the current
  # version of Vim, and then install the covim plugin

  # make sure source image is up-to-date
  RUN touch /deleteme
  RUN apt-get update && apt-get upgrade -y

  # build and install the current version of Vim
  RUN apt-get install -y bash python-pip git libssl-dev libncurses5-dev supervisor
  RUN pip install twisted argparse service_identity
  RUN git clone git://github.com/vim/vim
  RUN cd /vim && ./configure --enable-pythoninterp=dynamic
  RUN cd /vim && make && make install

  # build and install the covim plugin
  RUN mkdir ~/.vim && mkdir ~/.vim/bundle
  RUN cd ~/.vim/bundle && git clone git://github.com/FredKSchott/CoVim.git
  RUN mv ~/.vim/bundle/CoVim/plugin ~/.vim/
  RUN cp ~/.vim/plugin/CoVimServer.py /bin/

  # add the supervisor config file
  COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

  EXPOSE 8555
  CMD ["/usr/bin/supervisord"]

3) Inside of the work folder, create a file called "supervisord.conf", containing the following:

  [supervisord]
  nodaemon=true

  [program:covim]
  command=/bin/bash -c "exec /bin/CoVimServer.py -p"
  autorestart=true

4) Create the Docker image by running the following (inside of the working folder):

  docker build -t pg/covim .

5) Create a container from the image by running:

  docker run --name covim -itd -p 8555:8555 pg/covim

6) (As a user) Connect to the service by running Vim and running the following command:

  :CoVim connect IPADDR 8555 USERNAME

In the above, edit "IPADDR" and "USERNAME" to fit.  Note: If vim is being run on the same machine as the CoVim service then IPADDR must be "localhost".  It's also assumed that each student has a different username.

IMPORTANT:  All editing is done in memory.  If each user wants a copy of the edited file, each must issue a save command (e.g., ":w myfilename") before exiting.  By default, the saved file will show up in whatever directory the user was in when they executed Vim.

Other ideas:

  • Install the client end on a machine reachable via ShellInABox (or similar SSH client).  This removes the need to install CoVim on each student's workstation.  All they'll need is a browser.  Possible drawback: when the student saves a file, it is stored on the machine running ShellInABox, not the student's machine.
  • In the student's .bashrc file, add the following line:
      alias covim="vim -c 'CoVim connect IPADDR 8555 $(whoami)'"

Oddities:

  • The user must exit twice when leaving the program.  The first ":q" or ":q!" disconnects from the service.  The second exits the Vim program.

No comments:

Post a Comment