From 19d082d26d9862eb5f8ed6e8ca71a51059068fb5 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 9 Jun 2021 10:23:48 -0700 Subject: [PATCH] Add support for running in a Docker image --- .dockerignore | 18 +++++++++++ Dockerfile | 80 +++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 25 +++++++++++++++ docker-entry.sh | 16 ++++++++++ nvim-container.sh | 22 +++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 docker-entry.sh create mode 100755 nvim-container.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c161bca --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +*.log +.DS_Store +.pre_commit_env/ +tags +vim/.netrwhist +vim/UltiSnips +vim/autoload/plug.vim +vim/autoload/plug.vim.old +vim/backup/ +vim/plugged/ +vim/rc/*.local.rc.vim +vim/rc/plugins/*.local.rc.vim +vim/spell/ +vim/tmp/ +vim/tmp/viminfo.* +vim/view/ +Dockerfile +Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da78eb7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,80 @@ +FROM ubuntu:hirsute + +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y --no-install-recommends \ + bash \ + curl \ + git \ + golang \ + gopls \ + 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/* + +RUN useradd -ms /bin/bash vividboarder + +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 \ + +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 + +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 + +# 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" + +ENV NPM_PACKAGES $HOME/.npm-packages +# RUN mkdir $NPM_PACKAGES +RUN npm config set prefix $NPM_PACKAGES +ENV PATH $PATH:$NPM_PACKAGES +ENV PATH $HOME/.local/bin:$PATH +# RUN ./settings/install-language-servers.sh + +RUN mkdir data diff --git a/Makefile b/Makefile index 9828ac4..fafa7fb 100644 --- a/Makefile +++ b/Makefile @@ -45,3 +45,28 @@ install-hooks: $(PRE_COMMIT_ENV_BIN)/pre-commit .PHONY: check check: $(PRE_COMMIT_ENV_BIN)/pre-commit $(PRE_COMMIT_ENV_BIN)/pre-commit run --all-files + +# Build Docker images +.PHONY: docker-build +docker-build: + docker build \ + --tag vividboarder/my-neovim . + +# Build Docker images +.PHONY: docker-build-all +docker-build-all: + docker buildx build \ + --platform linux/arm/v7,linux/arm64/v8,linux/amd64 \ + --tag vividboarder/my-neovim . + +# Build Docker images +.PHONY: docker-build-push +docker-build-push: + docker buildx build \ + --push \ + --platform linux/arm/v7,linux/arm64/v8,linux/amd64 \ + --tag vividboarder/my-neovim . + +.PHONY: docker-clean +docker-clean: + docker volume rm nvim-$(USER)-home diff --git a/docker-entry.sh b/docker-entry.sh new file mode 100755 index 0000000..089073e --- /dev/null +++ b/docker-entry.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +set -e + +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" + +exec "$@" diff --git a/nvim-container.sh b/nvim-container.sh new file mode 100755 index 0000000..343ccb6 --- /dev/null +++ b/nvim-container.sh @@ -0,0 +1,22 @@ +#! /bin/bash + +if ! docker image ls -q nvim > /dev/null ;then + echo "no nvim image found" + exit 1 +fi + +container_name=nvim-$USER + +if ! docker inspect "${container_name}-home" > /dev/null ; then + docker volume create "${container_name}-home" +fi + +docker run --interactive --rm --tty \ + --name "$container_name" \ + --env "VIM_COLOR=$VIM_COLOR" \ + --volume "${container_name}-home:/home/vividboarder" \ + --volume "$(pwd):/home/vividboarder/data" \ + --workdir /home/vividboarder/data \ + --entrypoint /vim-settings/docker-entry.sh \ + vividboarder/my-neovim nvim "$@" + # --user "$(id -u):$(id -g)" \