From 00c5192eacdb17bcd584f38c48081881062a3baa Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sat, 6 Oct 2018 12:51:37 +0800 Subject: [PATCH] Add docker spacevim (#2238) --- .SpaceVim.d/autoload/SpaceVim/dev/layers.vim | 33 +++ docker/Dockerfile.nvim-python3 | 4 + docker/README.md | 46 ++-- docker/init.toml | 232 +++++++++++++++++++ docs/cn/quick-start-guide.md | 16 ++ docs/quick-start-guide.md | 14 ++ wiki/en/Following-HEAD.md | 1 + 7 files changed, 325 insertions(+), 21 deletions(-) create mode 100644 docker/init.toml diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/layers.vim b/.SpaceVim.d/autoload/SpaceVim/dev/layers.vim index 842fbbce8..334308730 100644 --- a/.SpaceVim.d/autoload/SpaceVim/dev/layers.vim +++ b/.SpaceVim.d/autoload/SpaceVim/dev/layers.vim @@ -21,6 +21,16 @@ function! SpaceVim#dev#layers#update() abort endfunction +function! SpaceVim#dev#layers#updatedocker() abort + let [start, end] = s:find_docker_position() + if start != 0 && end != 0 + if end - start > 1 + exe (start + 1) . ',' . (end - 1) . 'delete' + endif + call append(start, s:generate_docker_content()) + endif +endfunction + function! SpaceVim#dev#layers#updateCn() abort let [start, end] = s:find_position_cn() @@ -40,6 +50,12 @@ function! s:find_position() abort return sort([start, end], 'n') endfunction +function! s:find_docker_position() abort + let start = search('^## -- SpaceVim layer list start$','bwnc') + let end = search('^## -- SpaceVim layer list end$','bnwc') + return sort([start, end], 'n') +endfunction + function! s:find_position_cn() abort let start = search('^$','bwnc') let end = search('^$','bnwc') @@ -58,6 +74,23 @@ function! s:generate_content_cn() abort return content endfunction +function! s:generate_docker_content() abort + let layers = SpaceVim#util#globpath('~/.SpaceVim/', 'docs/cn/layers/**/*.md') + let list = [ + \ ] + call remove(layers, index(layers, '/home/wsdjeg/.SpaceVim/docs/cn/layers/index.md')) + for layer in layers + let name = split(layer, '/docs/cn/layers/')[1][:-4] . '/' + if name ==# 'language-server-protocol/' + let name = 'lsp' + endif + let name = join(split(name, '/'), '#') + let snippet = ['[[layers]]', ' name = "' . name . '"', ''] + let list += snippet + endfor + return list +endfunction + function! s:layer_list() abort let layers = SpaceVim#util#globpath('~/.SpaceVim/', 'docs/layers/**/*.md') let list = [ diff --git a/docker/Dockerfile.nvim-python3 b/docker/Dockerfile.nvim-python3 index 8017c3784..350e3fdf6 100644 --- a/docker/Dockerfile.nvim-python3 +++ b/docker/Dockerfile.nvim-python3 @@ -47,8 +47,12 @@ RUN mkdir -p $HOME/.config $HOME/.SpaceVim.d RUN pip install --user neovim pipenv +RUN curl https://raw.githubusercontent.com/SpaceVim/SpaceVim/master/docker/init.toml > $HOME/.SpaceVim.d/init.toml + RUN curl -sLf https://spacevim.org/install.sh | bash RUN nvim --headless +'call dein#install()' +qall +RUN rm $HOME/.SpaceVim.d/init.toml + ENTRYPOINT /usr/local/bin/nvim diff --git a/docker/README.md b/docker/README.md index 10ba0e728..4ecb9c6fe 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,37 +1,41 @@ ## SpaceVim and Neovim in Docker + +![Docker Build Status](https://img.shields.io/docker/build/spacevim/spacevim.svg) + This Dockerfile builds neovim `HEAD` and installs the latest available version of SpaceVim. You might want to use this for several reasons: -* Have a consistent version of Neovim and SpaceVim as long as the machine supports Docker. -* Try SpaceVim without modifying your current Vim/Neovim configuration. -* Try the latest Neovim with SpaceVim. -* Try SpaceVim with a newer version of Python. -* Debug SpaceVim configurations. e.g. when posting a bug report if you can reproduce it in this container then there's a higher chance that it is a true bug and not just an issue with your machine. +- Have a consistent version of Neovim and SpaceVim as long as the machine supports Docker. +- Try SpaceVim without modifying your current Vim/Neovim configuration. +- Try the latest Neovim with SpaceVim. +- Try SpaceVim with a newer version of Python. +- Debug SpaceVim configurations. e.g. when posting a bug report if you can reproduce it in this container then there's a higher chance that it is a true bug and not just an issue with your machine. ### FAQ + Isn't Docker stateless? Won't I have to reinstall all plugins each time I launch the container? -* During the build we call `dein#install()` so all plugins are installed and frozen. Your custom configurations can be added as an additional build step using the Docker `COPY` command. + +- During the build we call `dein#install()` so all plugins are installed and frozen. Your custom configurations can be added as an additional build step using the Docker `COPY` command. ### Build + You can build using the supplied `Makefile`: -``` -make build -``` + + make build + or call the command manually using: -``` -docker build -t nvim -f Dockerfile.nvim-python3 . -``` + + docker build -t nvim -f Dockerfile.nvim-python3 . ### Run + You can run the container using: -``` -docker run -it nvim -``` + + docker run -it nvim + but that isn't terribly useful since changes made inside the container won't be visible outside. More useful is mounting the current working directory inside the container: -``` -docker run -it -v $(pwd):/home/spacevim/src nvim -``` + + docker run -it -v $(pwd):/home/spacevim/src nvim Even better is an alias `dnvim` which will do this automatically: -``` -alias dnvim="docker run -it -v $(pwd):/home/spacevim/src nvim" -``` + + alias dnvim="docker run -it -v $(pwd):/home/spacevim/src nvim" diff --git a/docker/init.toml b/docker/init.toml new file mode 100644 index 000000000..240679e7d --- /dev/null +++ b/docker/init.toml @@ -0,0 +1,232 @@ +#============================================================================= +# init.toml --- Docker config temp file +# Copyright (c) 2016-2017 Wang Shidong & Contributors +# Author: Wang Shidong < wsdjeg at 163.com > +# URL: https://spacevim.org +#============================================================================= + +# SpaceVim options {{{ +[options] + # vimcompatible = true + # enable_language_specific_leader = false +# }}} + +## -- SpaceVim layer list start +[[layers]] + name = "VersionControl" + +[[layers]] + name = "autocomplete" + +[[layers]] + name = "chat" + +[[layers]] + name = "checkers" + +[[layers]] + name = "chinese" + +[[layers]] + name = "colorscheme" + +[[layers]] + name = "core#banner" + +[[layers]] + name = "core#statusline" + +[[layers]] + name = "core#tabline" + +[[layers]] + name = "core" + +[[layers]] + name = "cscope" + +[[layers]] + name = "ctrlp" + +[[layers]] + name = "debug" + +[[layers]] + name = "default" + +[[layers]] + name = "denite" + +[[layers]] + name = "edit" + +[[layers]] + name = "floobits" + +[[layers]] + name = "format" + +[[layers]] + name = "fzf" + +[[layers]] + name = "git" + +[[layers]] + name = "github" + +[[layers]] + name = "japanese" + +[[layers]] + name = "lang#WebAssembly" + +[[layers]] + name = "lang#agda" + +[[layers]] + name = "lang#asciidoc" + +[[layers]] + name = "lang#autohotkey" + +[[layers]] + name = "lang#c" + +[[layers]] + name = "lang#clojure" + +[[layers]] + name = "lang#csharp" + +[[layers]] + name = "lang#dart" + +[[layers]] + name = "lang#dockerfile" + +[[layers]] + name = "lang#elixir" + +[[layers]] + name = "lang#elm" + +[[layers]] + name = "lang#erlang" + +[[layers]] + name = "lang#extra" + +[[layers]] + name = "lang#fsharp" + +[[layers]] + name = "lang#go" + +[[layers]] + name = "lang#haskell" + +[[layers]] + name = "lang#html" + +[[layers]] + name = "lang#java" + +[[layers]] + name = "lang#javascript" + +[[layers]] + name = "lang#julia" + +[[layers]] + name = "lang#kotlin" + +[[layers]] + name = "lang#latex" + +[[layers]] + name = "lang#lisp" + +[[layers]] + name = "lang#lua" + +[[layers]] + name = "lang#markdown" + +[[layers]] + name = "lang#nim" + +[[layers]] + name = "lang#ocaml" + +[[layers]] + name = "lang#perl" + +[[layers]] + name = "lang#php" + +[[layers]] + name = "lang#plantuml" + +[[layers]] + name = "lang#puppet" + +[[layers]] + name = "lang#purescript" + +[[layers]] + name = "lang#python" + +[[layers]] + name = "lang#ruby" + +[[layers]] + name = "lang#rust" + +[[layers]] + name = "lang#scala" + +[[layers]] + name = "lang#sh" + +[[layers]] + name = "lang#swift" + +[[layers]] + name = "lang#typescript" + +[[layers]] + name = "lang#vim" + +[[layers]] + name = "lang#vue" + +[[layers]] + name = "lsp" + +[[layers]] + name = "leaderf" + +[[layers]] + name = "shell" + +[[layers]] + name = "sudo" + +[[layers]] + name = "tags" + +[[layers]] + name = "tmux" + +[[layers]] + name = "tools#dash" + +[[layers]] + name = "tools" + +[[layers]] + name = "ui" + +## -- SpaceVim layer list end + diff --git a/docs/cn/quick-start-guide.md b/docs/cn/quick-start-guide.md index bd187f3d7..a3f07d1f4 100644 --- a/docs/cn/quick-start-guide.md +++ b/docs/cn/quick-start-guide.md @@ -15,6 +15,7 @@ lang: cn - [安装](#安装) - [Linux 或 macOS](#linux-或-macos) - [Windows](#windows) +- [在 Docker 中运行](#在-docker-中运行) - [配置](#配置) - [学习SpaceVim](#学习spacevim) - [在线指南](#在线指南) @@ -46,6 +47,21 @@ curl -sLf https://spacevim.org/cn/install.sh | bash -s -- -h windows 下最快捷的安装方法是下载安装脚本 [install.cmd](https://spacevim.org/cn/install.cmd) 并运行。 + +### 在 Docker 中运行 + +```sh +docker pull spacevim/spacevim +docker run -it --rm spacevim/spacevim nvim +``` + +也可以通过挂载的方式,载入本地配置: + +```sh +docker run -it -v ~/.SpaceVim.d:/home/spacevim/.SpaceVim.d --rm spacevim/spacevim nvim +``` + + ### 配置 SpaceVim 的默认配置文件为 `~/.SpaceVim.d/init.toml`。下面为一简单的配置示例。 diff --git a/docs/quick-start-guide.md b/docs/quick-start-guide.md index a3bfd44a0..17206ead4 100644 --- a/docs/quick-start-guide.md +++ b/docs/quick-start-guide.md @@ -14,6 +14,7 @@ show you how to install it, how to config it, and explain its features. - [Install](#install) - [Linux and macOS](#linux-and-macos) - [Windows](#windows) +- [Run in docker](#run-in-docker) - [Configuration](#configuration) - [Online tutor](#online-tutor) - [Learning SpaceVim](#learning-spacevim) @@ -45,6 +46,19 @@ curl -sLf https://spacevim.org/install.sh | bash -s -- -h The easiest way is to download [install.cmd](https://spacevim.org/install.cmd) and run it as administrator, or install SpaceVim manually. +## Run in docker + +```sh +docker pull spacevim/spacevim +docker run -it --rm spacevim/spacevim nvim +``` + +you can also load local config: + +```sh +docker run -it -v ~/.SpaceVim.d:/home/spacevim/.SpaceVim.d --rm spacevim/spacevim nvim +``` + ## Configuration The default configuration file of SpaceVim is `~/.SpaceVim.d/init.toml`. This is diff --git a/wiki/en/Following-HEAD.md b/wiki/en/Following-HEAD.md index 7f30b95df..4a01f56f0 100644 --- a/wiki/en/Following-HEAD.md +++ b/wiki/en/Following-HEAD.md @@ -12,6 +12,7 @@ The next release is v1.0.0. ### Improvement - Update runtime log for startup ([#2219](https://github.com/SpaceVim/SpaceVim/pull/2219)) +- Add doc for how run run spacevim in docker ([#2238](https://github.com/SpaceVim/SpaceVim/pull/2238)) ### Changed