From ed738843455c7d93e6fe56b75e972b1332a2dc2b Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Thu, 16 Dec 2021 20:50:37 -0800 Subject: [PATCH] Update Dockerfile and related Docker scripts Now working nvim in Docker! --- .dockerignore | 7 ++- Dockerfile | 105 ++++++++++++++++++++------------------------- docker-entry.sh | 34 ++++++++++----- nvim-container.sh | 9 ++-- vim-sync-append.sh | 4 +- 5 files changed, 82 insertions(+), 77 deletions(-) diff --git a/.dockerignore b/.dockerignore index c161bca..d82dea1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,11 @@ .DS_Store .pre_commit_env/ tags +neovim/backup/ +neovim/plugged/ +neovim/plugin/packer_compiled.lua +neovim/spell/ +neovim/tmp/ vim/.netrwhist vim/UltiSnips vim/autoload/plug.vim @@ -14,5 +19,3 @@ vim/spell/ vim/tmp/ vim/tmp/viminfo.* vim/view/ -Dockerfile -Makefile diff --git a/Dockerfile b/Dockerfile index 7746ca3..bf55e2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,81 +1,68 @@ -FROM ubuntu:hirsute +FROM alpine:3.15 -ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y --no-install-recommends \ +RUN apk add \ bash \ + cargo \ + ctags \ curl \ git \ - golang \ - gopls \ + go \ make \ neovim \ npm \ - python3-autopep8 \ - python3-flake8 \ - python3-mypy \ - python3-neovim \ - python3-pip \ - python3-proselint \ - python3-pyls-black \ - python3-venv \ - universal-ctags \ - yamllint \ - && apt-get clean && rm -rf /var/lib/apt/lists/* + py3-pip \ + python3 \ + rustup \ + shellcheck \ + ; -RUN useradd -ms /bin/bash vividboarder +# Install dependencies for python-language-server +RUN apk add gcc g++ python3-dev -RUN mkdir -p /go/bin -ENV PATH $PATH:/go/bin -RUN GOPATH=/go go get -u github.com/davidrjenni/reftools/cmd/fillstruct@master \ - && GOPATH=/go go get -u github.com/fatih/gomodifytags@latest \ - && GOPATH=/go go get -u github.com/fatih/motion@latest \ - # && GOPATH=/go go get -u github.com/go-delve/delve/cmd/dlv@latest \ - && GOPATH=/go go get -u github.com/josharian/impl@master \ - && GOPATH=/go go get -u github.com/jstemmer/gotags@master \ - && GOPATH=/go go get -u github.com/kisielk/errcheck@latest \ - && GOPATH=/go go get -u github.com/klauspost/asmfmt/cmd/asmfmt@latest \ - && GOPATH=/go go get -u github.com/koron/iferr@master \ - && GOPATH=/go go get -u github.com/rogpeppe/godef@latest \ - && GOPATH=/go go get -u golang.org/x/lint/golint@master \ - && GOPATH=/go go get -u golang.org/x/tools/cmd/goimports@master \ - && GOPATH=/go go get -u golang.org/x/tools/cmd/gorename@master \ - && GOPATH=/go go get -u golang.org/x/tools/cmd/guru@master \ - && GOPATH=/go go get -u honnef.co/go/tools/cmd/keyify@master \ - && GOPATH=/go go get -u honnef.co/go/tools/cmd/staticcheck@latest \ - && GOPATH=/go go get -u github.com/mrtazz/checkmake \ - && rm -fr /go/src /go/pkg - -RUN pip install --no-cache-dir \ - reorder-python-imports \ - vim-vint - -RUN npm install -g \ - alex \ - bash-language-server \ - csslint \ - pyright - -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /go/bin v1.35.2 -# RUN GOPATH=/go go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@latest +# Install neovim python client +RUN pip3 install pynvim +# Create user +RUN adduser -D -h /home/vividboarder -s /bin/bash vividboarder USER vividboarder -VOLUME /home/vividboarder + WORKDIR /home/vividboarder ENV HOME /home/vividboarder ENV XDG_CONFIG_HOME $HOME/.config RUN mkdir -p $XDG_CONFIG_HOME -COPY --chown=vividboarder:vividboarder . /vim-settings +# Create persistent data dir +RUN mkdir -p /home/vividboarder/.data +VOLUME /home/vividboarder/.data -# RUN ln -s $HOME/settings/vim "$XDG_CONFIG_HOME/nvim" -# RUN ln -s $HOME/settings/vim "$HOME/.vim" -# RUN ln -s $HOME/settings/vim/init.vim "$HOME/.vimrc" +# Configure go path +ENV GOPATH $HOME/go +RUN mkdir -p $GOPATH/bin +ENV PATH $PATH:$GOPATH/bin +# Configure npm path ENV NPM_PACKAGES $HOME/.npm-packages -# RUN mkdir $NPM_PACKAGES RUN npm config set prefix $NPM_PACKAGES -ENV PATH $PATH:$NPM_PACKAGES +ENV PATH $PATH:$NPM_PACKAGES/bin ENV PATH $HOME/.local/bin:$PATH -# RUN ./settings/install-language-servers.sh -RUN mkdir data +# Install Language servers +COPY --chown=vividboarder:vividboarder ./install-language-servers.sh ./ +RUN ./install-language-servers.sh +# Install golangci-lint +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOPATH/bin v1.43.0 + +# Add config +COPY --chown=vividboarder:vividboarder ./neovim $HOME/.config/nvim + +# Sync packer plugins +RUN nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerBootstrap" +# This may not actually do anyting. Haven't figured out how to get compiled ts files into the image +RUN nvim --headless -c "TSUpdateSync" -c "quitall" + +# Generate workdir +RUN mkdir /home/vividboarder/data +WORKDIR /home/vividboarder/data + +COPY docker-entry.sh /docker-entry.sh +ENTRYPOINT /docker-entry.sh diff --git a/docker-entry.sh b/docker-entry.sh index 089073e..ab3baf0 100755 --- a/docker-entry.sh +++ b/docker-entry.sh @@ -1,16 +1,28 @@ #! /bin/bash -set -e +set -ex -VIM_SYNC_DIR=$HOME/vim-settings -# copy settings to volume -[ -d "$VIM_SYNC_DIR" ] || cp -r /vim-settings "$VIM_SYNC_DIR" +# VIM_SYNC_DIR=$HOME/vim-settings +# # copy settings to volume +# [ -d "$VIM_SYNC_DIR" ] || cp -r /vim-settings "$VIM_SYNC_DIR" +# +# # Link config files +# [ -d "$XDG_CONFIG_HOME" ] || mkdir -p "$XDG_CONFIG_HOME" +# [ -d "$XDG_CONFIG_HOME/nvim" ] || ln -s "$VIM_SYNC_DIR/vim" "$XDG_CONFIG_HOME/nvim" +# [ -d "$XDG_CONFIG_HOME/nvim/backup" ] || mkdir -p "$XDG_CONFIG_HOME/nvim/backup" +# [ -d "$HOME/.vim" ] || ln -s "$VIM_SYNC_DIR/vim" "$HOME/.vim" +# [ -f "$HOME/.vimrc" ] || ln -s "$VIM_SYNC_DIR/vim/init.vim" "$HOME/.vimrc" -# Link config files -[ -d "$XDG_CONFIG_HOME" ] || mkdir -p "$XDG_CONFIG_HOME" -[ -d "$XDG_CONFIG_HOME/nvim" ] || ln -s "$VIM_SYNC_DIR/vim" "$XDG_CONFIG_HOME/nvim" -[ -d "$XDG_CONFIG_HOME/nvim/backup" ] || mkdir -p "$XDG_CONFIG_HOME/nvim/backup" -[ -d "$HOME/.vim" ] || ln -s "$VIM_SYNC_DIR/vim" "$HOME/.vim" -[ -f "$HOME/.vimrc" ] || ln -s "$VIM_SYNC_DIR/vim/init.vim" "$HOME/.vimrc" +VOLUME_DATA=/home/vividboarder/.data +[ -d "$VOLUME_DATA/nvim/backup" ] || mkdir -p "$VOLUME_DATA/nvim/backup" +[ -d "$XDG_CONFIG_HOME/nvim/backup" ] || ln -s "$VOLUME_DATA/nvim/backup" "$XDG_CONFIG_HOME/nvim/backup" -exec "$@" +TS_PARSERS="share/nvim/site/pack/packer/start/nvim-treesitter/parser" +[ -d "$VOLUME_DATA/ts-parsers" ] || mkdir -p "$VOLUME_DATA/ts-parsers" +rm -fr "$HOME/.local/$TS_PARSERS" || ln -s "$VOLUME_DATA/ts-parsers" "$HOME/.local/$TS_PARSERS" + +if [ "$1" == "bash" ]; then + exec "$@" +else + exec nvim "$@" +fi diff --git a/nvim-container.sh b/nvim-container.sh index 343ccb6..44b9a33 100755 --- a/nvim-container.sh +++ b/nvim-container.sh @@ -14,9 +14,10 @@ fi docker run --interactive --rm --tty \ --name "$container_name" \ --env "VIM_COLOR=$VIM_COLOR" \ - --volume "${container_name}-home:/home/vividboarder" \ + --volume "${container_name}-home:/home/vividboarder/.data" \ --volume "$(pwd):/home/vividboarder/data" \ --workdir /home/vividboarder/data \ - --entrypoint /vim-settings/docker-entry.sh \ - vividboarder/my-neovim nvim "$@" - # --user "$(id -u):$(id -g)" \ + --entrypoint /docker-entry.sh \ + --user "$(id -u):$(id -g)" \ + nvim "$@" + # vividboarder/my-neovim nvim "$@" diff --git a/vim-sync-append.sh b/vim-sync-append.sh index 5ecc103..13f2e66 100755 --- a/vim-sync-append.sh +++ b/vim-sync-append.sh @@ -29,7 +29,9 @@ if hash nvim 2>/dev/null; then echo "If using Neovim, install the python modules in your environment" nvim +PlugInstall +qall fi -vim +PlugInstall +qall +if hash vim 2>/dev/null; then + vim +PlugInstall +qall +fi echo "All done!"