Skip to content

Commit

Permalink
Merge pull request #20 from erichlf/update-setup
Browse files Browse the repository at this point in the history
Update setup
  • Loading branch information
erichlf authored Jun 4, 2024
2 parents c005518 + 47cccaa commit 55c5251
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 84 deletions.
10 changes: 8 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
"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",
"mounts": [],
"containerEnv": {
"DEV_WORKSPACE": "${containerWorkspaceFolder}",
},
"mounts": [
// unfortunately the runner for ci will fail with this mount so comment it out
// "type=bind,source=${localEnv:HOME}/.ssh,target=/home/my-app/.ssh,readonly",
],
"features": {
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": "neovim,stow,zsh,fzf"
"packages": "neovim,stow,zsh,fzf,python3-pip"
}
}
}
73 changes: 39 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

Develop your next Repo in a Devcontainer using *nvim* thanks to the
[Devconatiner CLI](https://github.com/devcontainers/cli) and this plugin
![devcontainer-cli in action](doc/gifs/nvim_devcontainer_cli-description.gif)

As you can see in the GIF above,
[alacritty](https://github.com/alacritty/alacritty) is being used as a Terminal
Emulator. Any of the ones recommended [here](https://www.lazyvim.org/) would
work. For dotfiles setup I would recommend looking at the `devcontainer` branch
of [my dotfiles](https://github.com/erichlf/dotfiles). The `install.sh` script is
quite simple, but should be very informative.
![devcontainer-cli in action](doc/gifs/devcontainer-cli-description.gif)

As you can see in the GIF above, guake with tmux is being used. Any of the ones
recommended [here](https://www.lazyvim.org/) would work. For dotfiles setup I created
a version of my dotfiles that doesn't have any private submodules. These dotfiles
are probably more than what anyone would want, but if feel free to use them. The
one gotcha with them is that it requires the environment variable DEV_WORKSPACE
to be set. I would recommend looking at the `devcontainer-cli` branch of
[my dotfiles](https://github.com/erichlf/dotfiles). The `install.sh` script ends
up calling `script/devcontainer-cli` which is quite simple, but should get you
some pretty good ideas of how things can be setup.

---

Expand Down Expand Up @@ -86,28 +89,6 @@ make assumptions about how you work.
{
"erichlf/devcontainer-cli.nvim",
dependencies = { 'akinsho/toggleterm.nvim' },
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/erichlf/dotfiles"
-- This is an example for configuring other dotfiles inside the docker container
dotfiles_repository = "https://github.com/erichlf/dotfiles.git",
dotfiles_branch = "main", -- branch to clone from dotfiles_repository`
dotfiles_targetPath = "~/dotfiles", -- location to install dotfiles
dotfiles_intallCommand = "install.sh", -- script to run after dotfiles are cloned
shell = "bash", -- shell to use when executing commands
-- The particular binary to use for connecting to in the devcontainer
-- Most likely this should remain nvim
nvim_binary = "nvim",
},
keys = {
-- stylua: ignore
{
Expand Down Expand Up @@ -140,8 +121,33 @@ make assumptions about how you work.
"<CMD>DevContainerToggle<CR>",
desc = "Toggle the current DevContainer Terminal"
},
}
},
},
init = function()
local 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/erichlf/dotfiles"
-- This is an example for configuring other dotfiles inside the docker container
dotfiles_repository = "https://github.com/erichlf/dotfiles.git",
dotfiles_branch = "devcontainer-cli", -- branch to clone from dotfiles_repository`
dotfiles_targetPath = "~/dotfiles", -- location to install dotfiles
dotfiles_intallCommand = "install.sh", -- script to run after dotfiles are cloned
shell = "bash", -- shell to use when executing commands
-- The particular binary to use for connecting to in the devcontainer
-- Most likely this should remain nvim
nvim_binary = "nvim",
}
require('devcontainer-cli').setup(opts)
end,
}
```

The default_config can be found [here](./lua/devcontainer_cli/config/init.lua).
Expand Down Expand Up @@ -204,6 +210,5 @@ make test
(`:DevcontainerUp<cr>`) is closed when the process finishes successfully.
4. [x] [Give the possibility of defining custom dotfiles when setting up the devcontainer](https://github.com/erichlf/devcontainer-cli.nvim/issues/1)
5. [x] Add unit tests using plenary.busted lua module.
6. [ ] The logs printed in the floating window when preparing the Devcontainer
are saved and easy to access.
6. [x] Create a logger.
7. [x] Convert bash scripts in lua code.
Binary file added doc/gifs/devcontainer-cli-description.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/gifs/nvim_devcontainer_cli-description.gif
Binary file not shown.
35 changes: 20 additions & 15 deletions lua/devcontainer-cli/config.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
-- Copyright (c) 2024 Erich L Foster
--
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
-- so, subject to the following conditions:
--
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
local log = require("devcontainer-cli.log")

local ConfigModule = {}
local file_path = debug.getinfo(1).source:sub(2)
Expand All @@ -28,41 +29,45 @@ local default_config = {
-- 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
-- If set to True [default_value] it can take extra time as you force to
-- start from scratch
remove_existing_container = true,
-- dotfiles to be downloaded
dotfiles_repository = "[email protected]:erichlf/dotfiles",
-- branch to checkout for repositories (this is a feature not supported by
-- branch to checkout for repositories (this is a feature not supported by
-- devcontainers in general, but we do)
dotfiles_branch = "main",
-- directory for the setup environment
dotfiles_targetPath = "~/dotfiles",
-- command that's executed for installed the dependencies from the
-- command that's executed for installed the dependencies from the
-- setup_environment_repo
dotfiles_installCommand = "install.sh",
-- The number of columns to wrap text at
terminal_columns = 80,
-- The particular binary to use for connecting to in the devcontainer
-- Most likely this should remain nvim
nvim_binary = "nvim",
-- The shell to use for executing command. Available sh, bash, zsh or any
-- The shell to use for executing command. Available sh, bash, zsh or any
-- other that uses '-c' to signify a command is to follow
shell = 'bash',
}

local options

function ConfigModule.setup(opts)
log.debug("Configuring devcontainer-cli")
opts = vim.tbl_deep_extend("force", default_config, opts or {})
options = opts
log.debug("Configuring devcontainer-cli complete")
end

return setmetatable(ConfigModule, {
__index = function(_, key)
if options == nil then
return vim.deepcopy(default_config)[key]
end
return options[key]
end,
})
return setmetatable(ConfigModule,
{
__index = function(_, key)
if options == nil then
return vim.deepcopy(default_config)[key]
end
return options[key]
end,
}
)
7 changes: 4 additions & 3 deletions lua/devcontainer-cli/devcontainer_cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
local utils = require("devcontainer-cli.devcontainer_utils")
local utils = require("devcontainer-cli.devcontainer_utils")
local terminal = require("devcontainer-cli.terminal")
local log = require("devcontainer-cli.log")

local M = {}
local M = {}

-- executes a given command in the devcontainer of the current project directory
---@param opts (table) options for executing the command
Expand Down Expand Up @@ -64,7 +65,7 @@ end
-- neovim window the devcontainer will be automatically open in a new terminal
function M.connect()
if not utils.create_connect_cmd() then
vim.notify("Failed to create autocommand", vim.log.levels.ERROR)
log.error("Failed to create autocommand")
return
end

Expand Down
7 changes: 3 additions & 4 deletions lua/devcontainer-cli/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

local M = {}

local start = vim.health.start or vim.health.report_start
local ok = vim.health.ok or vim.health.report_ok
local warn = vim.health.warn or vim.health.report_warn
local error = vim.health.error or vim.health.report_error
local start = vim.health.start or vim.health.start
local ok = vim.health.ok or vim.health.ok
local error = vim.health.error or vim.health.error

local function verify_binary(binary_name)
if vim.fn.executable(binary_name) ~= 1 then
Expand Down
14 changes: 6 additions & 8 deletions lua/devcontainer-cli/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ local M = {}

local devcontainer_cli = require("devcontainer-cli.devcontainer_cli")
local config = require("devcontainer-cli.config")
local configured = false
local log = require("devcontainer-cli.log")

-- setup the devcontainer-cli plugin
---@param opts (table) the options to set (see config/init.lua)
function M.setup(opts)
config.setup(opts)

if configured then
print("Already configured, skipping!")
return
end

configured = true
log.debug("Setting up devcontainer-cli")
config.setup(opts)

log.debug("Creating devcontainer-cli user commands")
-- Docker
vim.api.nvim_create_user_command(
"DevcontainerUp",
Expand Down Expand Up @@ -72,6 +68,8 @@ function M.setup(opts)
desc = "Connect to devcontainer.",
}
)

log.debug("Finished setting up devcontainer-cli")
end

return M
Loading

0 comments on commit 55c5251

Please sign in to comment.