Skip to content

Root from devcontainer dir #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"build": {
"dockerfile": "../Dockerfile",
"args": {
"USER_NAME": "my-app",
"GROUP_NAME": "my-app",
"USER_ID": 1001,
"GROUP_ID": 1001
"USER_ID": 1000,
"GROUP_ID": 1000
}
},
"mounts": [
"source=/home/pontsoul/.config/github-copilot,target=/home/my-app/.config/github-copilot,type=bind",
"source=/home/pontsoul/.gitconfig,target=/home/my-app/.gitconfig,type=bind"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/home/my-app/.local/share/nvim/lazy/nvim-devcontainer-cli/,type=bind",
"workspaceFolder": "/home/my-app/.local/share/nvim/lazy/nvim-devcontainer-cli/",
"remoteUser": "my-app"
"remoteUser": "my-app",
"mounts": [],
"features": {
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": "neovim,stow,zsh,fzf"
}
}
}
77 changes: 38 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
FROM ubuntu:20.04 as builder
FROM ubuntu:22.04 as builder

ARG USER_NAME
ARG GROUP_NAME
ARG USER_ID
ARG GROUP_ID
ENV USER_NAME=my-app
ARG GROUP_NAME=$USER_NAME
ARG USER_ID=1000
ARG GROUP_ID=$USER_ID

# Create user called my-app in ubuntu
RUN groupadd --gid ${GROUP_ID} ${GROUP_NAME} \
&& useradd --create-home --no-log-init --uid ${USER_ID} --gid ${GROUP_ID} ${USER_NAME}

# This part of the code is needed for installing nodejs>=14
RUN apt-get update && apt-get install -y \
build-essential \
curl \
wget

RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
# Dependencies needed for bulding devcontainers/cli
nodejs \
# Dependencies needed for developing in neovim
lua5.1 \
luajit \
luarocks \
git \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd --gid $GROUP_ID $GROUP_NAME && \
useradd --uid $USER_ID --gid $GROUP_ID -m $USER_NAME \
&& apt-get update \
&& apt-get install -y --no-install-recommends sudo \
&& echo $USER_NAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_NAME \
&& chmod 0440 /etc/sudoers.d/$USER_NAME

# Switch to user
USER $USER_NAME

# Install dependencies needed for building devcontainers/cli and developing in neovim
RUN sudo apt-get update && \
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
curl \
wget \
nodejs \
npm \
lua5.1 \
luajit \
luarocks \
git \
# apt clean-up
&& sudo apt-get autoremove -y \
&& sudo rm -rf /var/lib/apt/lists/*

ENV NPM_CONFIG_PREFIX=/home/$USER_NAME/.npm-global

WORKDIR /app

# Installing the devcontainers CLI
RUN npm install -g @devcontainers/[email protected]

# Installing Lua Dependencies for testing LUA projects
RUN luarocks install busted

# Setting Up Environment
WORKDIR /home/${USER_NAME}
RUN git clone https://github.com/arnaupv/setup-environment.git \
&& cd setup-environment \
&& ./install.sh -p 'nvim stow zsh'

# Switch to user
USER ${USER_NAME}
RUN sudo luarocks install busted

# Installing vim-plug
COPY ./ /home/${USER}/.local/share/nvim/lazy/nvim-devcontainer-cli/
RUN mkdir -p /home/${USER}/.local/share/nvim/lazy/nvim-devcontainer-cli/
# this will prevent the .local directory from being owned by root on bind mount
RUN mkdir -p /home/$USER_NAME/.local/share/nvim/lazy
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ This plugin has been inspired by the work previously done by [esensar](https://g
{
"arnaupv/nvim-devcontainer-cli",
opts = {
-- whather to verify that the final devcontainer should be run
interactive = false,
-- search for the devcontainer directory closest to the root in the directory tree
toplevel = true,
-- Remove existing container each time DevcontainerUp is executed
-- If set to True [default_value] it can take extra time as you force to start from scratch
remove_existing_container = true,
-- By default, if no extra config is added, following nvim_dotfiles are
-- installed: "https://github.com/LazyVim/starter"
-- This is an example for configuring other nvim_dotfiles inside the docker container
nvim_dotfiles_repo = "https://github.com/arnaupv/dotfiles.git",
nvim_dotfiles_branch = "main", -- branch to clone from nvim_dotfiles_repo
nvim_dotfiles_install_command = "cd ~/nvim_dotfiles/ && ./install.sh",
-- In case you want to change the way the devenvironment is setup, you can also provide your own setup
setup_environment_repo = "https://github.com/arnaupv/setup-environment",
Expand Down
115 changes: 0 additions & 115 deletions bin/spawn_devcontainer.sh

This file was deleted.

12 changes: 7 additions & 5 deletions lua/devcontainer_cli/config/init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local ConfigModule = {}
local file_path = debug.getinfo(1).source:sub(2)
local default_config = {
-- Folder where devcontainer tool looks for the devcontainer.json file
devcontainer_folder = ".devcontainer/",
-- whather to verify that the final devcontainer should be run
interactive = false,
-- use the .devcontainer directory closest to root in the directory tree
toplevel = true,
-- Folder where the nvim-devcontainer-cli is installed

nvim_plugin_folder = file_path:gsub("init.lua", "") .. "../../../",
-- Remove existing container each time DevcontainerUp is executed
-- If set to True [default_value] it can take extra time as you force to start from scratch
Expand All @@ -14,15 +15,16 @@ local default_config = {
-- directory for the setup environment
setup_environment_directory = "setup_dotfiles",
-- command that's executed for installed the dependencies from the setup_environment_repo
setup_environment_install_command = "./install.sh -p nvim zsh stow --dotfiles",
setup_environment_install_command = "install.sh",

-- nvim_dotfiles that will be installed inside the docker devcontainer through the devcontainer cli.
nvim_dotfiles_repo = "https://github.com/LazyVim/starter",
-- branch to use for the nvim_dotfiles
nvim_dotfiles_branch = "main",
-- directory where to put the nvim_dotfiles
nvim_dotfiles_directory = "nvim_dotfiles",
-- nvim_dotfiles_install is the command that needs to be executed to install the dotfiles (it can be any bash command)
nvim_dotfiles_install_command = "mv ~/dotfiles ~/.config/nvim",
nvim_dotfiles_install_command = "mkdir -p ~/.config && mv ~/nvim_dotfiles ~/.config/nvim",
}

local options
Expand Down
41 changes: 9 additions & 32 deletions lua/devcontainer_cli/devcontainer_cli.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local config = require("devcontainer_cli.config")
local windows_utils = require("devcontainer_cli.windows_utils")
local folder_utils = require("devcontainer_cli.folder_utils")
local devcontainer_utils = require("devcontainer_cli.devcontainer_utils")

local M = {}

Expand All @@ -21,41 +21,18 @@ local function define_autocommands()
end

function M.up()
if not folder_utils.folder_exists(config.devcontainer_folder) then
print(
"Devcontainer folder not available: "
.. config.devcontainer_folder
.. ". devconatiner_cli_plugin plugin cannot be used"
-- bringup the devcontainer
devcontainer_parent = folder_utils.get_root(config.toplevel)
if devcontainer_parent == nil then
prev_win = vim.api.nvim_get_current_win()
vim.notify(
"Devcontainer folder not available. devconatiner_cli_plugin plugin cannot be used",
vim.log.levels.ERROR
)
return
else
print("Devcontainer folder detected. Path: " .. config.devcontainer_folder)
end

local command = config.nvim_plugin_folder .. "/bin/spawn_devcontainer.sh"

if config.remove_existing_container then
command = command .. " --remove-existing-container"
end
command = command .. " --root_directory " .. folder_utils.get_root_folder()
command = command .. " --setup-environment-repo " .. config.setup_environment_repo
command = command .. " --setup-environment-dir " .. '"' .. config.setup_environment_directory .. '"'
command = command .. " --setup-environment-install-command " .. '"' .. config.setup_environment_install_command .. '"'
command = command .. " --nvim-dotfiles-repo " .. '"' .. config.nvim_dotfiles_repo .. '"'
command = command .. " --nvim-dotfiles-branch " .. '"' .. config.nvim_dotfiles_branch .. '"'
command = command .. " --nvim-dotfiles-directory " .. '"' .. config.nvim_dotfiles_directory .. '"'
command = command .. " --nvim-dotfiles-install-command " .. '"' .. config.nvim_dotfiles_install_command .. '"'

print("Spawning devcontainer with command: " .. command)
windows_utils.create_floating_terminal(command, {
on_success = function(win_id)
vim.notify("A devcontainer has been successfully spawned by the nvim-devcontainer-cli!", vim.log.levels.INFO)
vim.api.nvim_win_close(win_id, true)
end,
on_fail = function(exit_code)
vim.notify("A devcontainer has failed to spawn! exit_code: " .. exit_code, vim.log.levels.ERROR)
end,
})
devcontainer_utils.bringup(devcontainer_parent)
end

function M.connect()
Expand Down
Loading