Skip to content

Commit 55c5251

Browse files
authored
Merge pull request #20 from erichlf/update-setup
Update setup
2 parents c005518 + 47cccaa commit 55c5251

File tree

10 files changed

+252
-84
lines changed

10 files changed

+252
-84
lines changed

.devcontainer/devcontainer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
"workspaceMount": "source=${localWorkspaceFolder},target=/home/my-app/.local/share/nvim/lazy/nvim-devcontainer-cli/,type=bind",
1111
"workspaceFolder": "/home/my-app/.local/share/nvim/lazy/nvim-devcontainer-cli/",
1212
"remoteUser": "my-app",
13-
"mounts": [],
13+
"containerEnv": {
14+
"DEV_WORKSPACE": "${containerWorkspaceFolder}",
15+
},
16+
"mounts": [
17+
// unfortunately the runner for ci will fail with this mount so comment it out
18+
// "type=bind,source=${localEnv:HOME}/.ssh,target=/home/my-app/.ssh,readonly",
19+
],
1420
"features": {
1521
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
16-
"packages": "neovim,stow,zsh,fzf"
22+
"packages": "neovim,stow,zsh,fzf,python3-pip"
1723
}
1824
}
1925
}

README.md

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
Develop your next Repo in a Devcontainer using *nvim* thanks to the
44
[Devconatiner CLI](https://github.com/devcontainers/cli) and this plugin
5-
![devcontainer-cli in action](doc/gifs/nvim_devcontainer_cli-description.gif)
6-
7-
As you can see in the GIF above,
8-
[alacritty](https://github.com/alacritty/alacritty) is being used as a Terminal
9-
Emulator. Any of the ones recommended [here](https://www.lazyvim.org/) would
10-
work. For dotfiles setup I would recommend looking at the `devcontainer` branch
11-
of [my dotfiles](https://github.com/erichlf/dotfiles). The `install.sh` script is
12-
quite simple, but should be very informative.
5+
![devcontainer-cli in action](doc/gifs/devcontainer-cli-description.gif)
6+
7+
As you can see in the GIF above, guake with tmux is being used. Any of the ones
8+
recommended [here](https://www.lazyvim.org/) would work. For dotfiles setup I created
9+
a version of my dotfiles that doesn't have any private submodules. These dotfiles
10+
are probably more than what anyone would want, but if feel free to use them. The
11+
one gotcha with them is that it requires the environment variable DEV_WORKSPACE
12+
to be set. I would recommend looking at the `devcontainer-cli` branch of
13+
[my dotfiles](https://github.com/erichlf/dotfiles). The `install.sh` script ends
14+
up calling `script/devcontainer-cli` which is quite simple, but should get you
15+
some pretty good ideas of how things can be setup.
1316

1417
---
1518

@@ -86,28 +89,6 @@ make assumptions about how you work.
8689
{
8790
"erichlf/devcontainer-cli.nvim",
8891
dependencies = { 'akinsho/toggleterm.nvim' },
89-
opts = {
90-
-- whather to verify that the final devcontainer should be run
91-
interactive = false,
92-
-- search for the devcontainer directory closest to the root in the
93-
-- directory tree
94-
toplevel = true,
95-
-- Remove existing container each time DevcontainerUp is executed
96-
-- If set to True [default_value] it can take extra time as you force to
97-
-- start from scratch
98-
remove_existing_container = true,
99-
-- By default, if no extra config is added, following nvim_dotfiles are
100-
-- installed: "https://github.com/erichlf/dotfiles"
101-
-- This is an example for configuring other dotfiles inside the docker container
102-
dotfiles_repository = "https://github.com/erichlf/dotfiles.git",
103-
dotfiles_branch = "main", -- branch to clone from dotfiles_repository`
104-
dotfiles_targetPath = "~/dotfiles", -- location to install dotfiles
105-
dotfiles_intallCommand = "install.sh", -- script to run after dotfiles are cloned
106-
shell = "bash", -- shell to use when executing commands
107-
-- The particular binary to use for connecting to in the devcontainer
108-
-- Most likely this should remain nvim
109-
nvim_binary = "nvim",
110-
},
11192
keys = {
11293
-- stylua: ignore
11394
{
@@ -140,8 +121,33 @@ make assumptions about how you work.
140121
"<CMD>DevContainerToggle<CR>",
141122
desc = "Toggle the current DevContainer Terminal"
142123
},
143-
}
144-
},
124+
},
125+
init = function()
126+
local opts = {
127+
-- whather to verify that the final devcontainer should be run
128+
interactive = false,
129+
-- search for the devcontainer directory closest to the root in the
130+
-- directory tree
131+
toplevel = true,
132+
-- Remove existing container each time DevcontainerUp is executed
133+
-- If set to True [default_value] it can take extra time as you force to
134+
-- start from scratch
135+
remove_existing_container = true,
136+
-- By default, if no extra config is added, following nvim_dotfiles are
137+
-- installed: "https://github.com/erichlf/dotfiles"
138+
-- This is an example for configuring other dotfiles inside the docker container
139+
dotfiles_repository = "https://github.com/erichlf/dotfiles.git",
140+
dotfiles_branch = "devcontainer-cli", -- branch to clone from dotfiles_repository`
141+
dotfiles_targetPath = "~/dotfiles", -- location to install dotfiles
142+
dotfiles_intallCommand = "install.sh", -- script to run after dotfiles are cloned
143+
shell = "bash", -- shell to use when executing commands
144+
-- The particular binary to use for connecting to in the devcontainer
145+
-- Most likely this should remain nvim
146+
nvim_binary = "nvim",
147+
}
148+
require('devcontainer-cli').setup(opts)
149+
end,
150+
}
145151
```
146152

147153
The default_config can be found [here](./lua/devcontainer_cli/config/init.lua).
@@ -204,6 +210,5 @@ make test
204210
(`:DevcontainerUp<cr>`) is closed when the process finishes successfully.
205211
4. [x] [Give the possibility of defining custom dotfiles when setting up the devcontainer](https://github.com/erichlf/devcontainer-cli.nvim/issues/1)
206212
5. [x] Add unit tests using plenary.busted lua module.
207-
6. [ ] The logs printed in the floating window when preparing the Devcontainer
208-
are saved and easy to access.
213+
6. [x] Create a logger.
209214
7. [x] Convert bash scripts in lua code.
10.6 MB
Loading
-1010 KB
Binary file not shown.

lua/devcontainer-cli/config.lua

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
-- Copyright (c) 2024 Erich L Foster
2-
--
2+
--
33
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
44
-- this software and associated documentation files (the "Software"), to deal in
55
-- the Software without restriction, including without limitation the rights to
66
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
77
-- of the Software, and to permit persons to whom the Software is furnished to do
88
-- so, subject to the following conditions:
9-
--
9+
--
1010
-- The above copyright notice and this permission notice shall be included in all
1111
-- copies or substantial portions of the Software.
12-
--
12+
--
1313
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1414
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1515
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
-- SOFTWARE.
20+
local log = require("devcontainer-cli.log")
2021

2122
local ConfigModule = {}
2223
local file_path = debug.getinfo(1).source:sub(2)
@@ -28,41 +29,45 @@ local default_config = {
2829
-- Folder where the nvim-devcontainer-cli is installed
2930
nvim_plugin_folder = file_path:gsub("init.lua", "") .. "../../../",
3031
-- Remove existing container each time DevcontainerUp is executed
31-
-- If set to True [default_value] it can take extra time as you force to
32+
-- If set to True [default_value] it can take extra time as you force to
3233
-- start from scratch
3334
remove_existing_container = true,
3435
-- dotfiles to be downloaded
3536
dotfiles_repository = "git@github.com:erichlf/dotfiles",
36-
-- branch to checkout for repositories (this is a feature not supported by
37+
-- branch to checkout for repositories (this is a feature not supported by
3738
-- devcontainers in general, but we do)
3839
dotfiles_branch = "main",
3940
-- directory for the setup environment
4041
dotfiles_targetPath = "~/dotfiles",
41-
-- command that's executed for installed the dependencies from the
42+
-- command that's executed for installed the dependencies from the
4243
-- setup_environment_repo
4344
dotfiles_installCommand = "install.sh",
4445
-- The number of columns to wrap text at
4546
terminal_columns = 80,
4647
-- The particular binary to use for connecting to in the devcontainer
4748
-- Most likely this should remain nvim
4849
nvim_binary = "nvim",
49-
-- The shell to use for executing command. Available sh, bash, zsh or any
50+
-- The shell to use for executing command. Available sh, bash, zsh or any
5051
-- other that uses '-c' to signify a command is to follow
5152
shell = 'bash',
5253
}
5354

5455
local options
5556

5657
function ConfigModule.setup(opts)
58+
log.debug("Configuring devcontainer-cli")
5759
opts = vim.tbl_deep_extend("force", default_config, opts or {})
5860
options = opts
61+
log.debug("Configuring devcontainer-cli complete")
5962
end
6063

61-
return setmetatable(ConfigModule, {
62-
__index = function(_, key)
63-
if options == nil then
64-
return vim.deepcopy(default_config)[key]
65-
end
66-
return options[key]
67-
end,
68-
})
64+
return setmetatable(ConfigModule,
65+
{
66+
__index = function(_, key)
67+
if options == nil then
68+
return vim.deepcopy(default_config)[key]
69+
end
70+
return options[key]
71+
end,
72+
}
73+
)

lua/devcontainer-cli/devcontainer_cli.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
-- SOFTWARE.
20-
local utils = require("devcontainer-cli.devcontainer_utils")
20+
local utils = require("devcontainer-cli.devcontainer_utils")
2121
local terminal = require("devcontainer-cli.terminal")
22+
local log = require("devcontainer-cli.log")
2223

23-
local M = {}
24+
local M = {}
2425

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

lua/devcontainer-cli/health.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
local M = {}
2222

23-
local start = vim.health.start or vim.health.report_start
24-
local ok = vim.health.ok or vim.health.report_ok
25-
local warn = vim.health.warn or vim.health.report_warn
26-
local error = vim.health.error or vim.health.report_error
23+
local start = vim.health.start or vim.health.start
24+
local ok = vim.health.ok or vim.health.ok
25+
local error = vim.health.error or vim.health.error
2726

2827
local function verify_binary(binary_name)
2928
if vim.fn.executable(binary_name) ~= 1 then

lua/devcontainer-cli/init.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,16 @@ local M = {}
2222

2323
local devcontainer_cli = require("devcontainer-cli.devcontainer_cli")
2424
local config = require("devcontainer-cli.config")
25-
local configured = false
25+
local log = require("devcontainer-cli.log")
2626

2727
-- setup the devcontainer-cli plugin
2828
---@param opts (table) the options to set (see config/init.lua)
2929
function M.setup(opts)
30-
config.setup(opts)
31-
32-
if configured then
33-
print("Already configured, skipping!")
34-
return
35-
end
3630

37-
configured = true
31+
log.debug("Setting up devcontainer-cli")
32+
config.setup(opts)
3833

34+
log.debug("Creating devcontainer-cli user commands")
3935
-- Docker
4036
vim.api.nvim_create_user_command(
4137
"DevcontainerUp",
@@ -72,6 +68,8 @@ function M.setup(opts)
7268
desc = "Connect to devcontainer.",
7369
}
7470
)
71+
72+
log.debug("Finished setting up devcontainer-cli")
7573
end
7674

7775
return M

0 commit comments

Comments
 (0)