dockerfiles
dockerfiles copied to clipboard
Speed up gopls startup
gopls image startup is really slow. This is mainly due to the usermod and chmod performed by the entrypoint script. I tried to implement another dockerfile which uses the official golang images. They are installing go in a world writable directory, so there is no need for a dedicated user any more (hence no usermod and the image spins in milliseconds).
I had to define a GOCACHE dir, but apart from that the image it quite simple and seems to be working fine.
I am testing it on my env with this conf
capabilities = capabilities,
cmd = require'lspcontainers'.command('ftassigopls', {
image = 'lspcontainers/gopls',
network="bridge",
cmd_builder = function (runtime, workdir, image, network)
local volume = workdir..":"..workdir..":z"
local env = vim.api.nvim_eval('environ()')
local gopath = env.GOPATH or env.HOME.."/go"
local gopath_volume = gopath..":"..gopath..":z"
local group_handle = io.popen("id -g")
local user_handle = io.popen("id -u")
local group_id = string.gsub(group_handle:read("*a"), "%s+", "")
local user_id = string.gsub(user_handle:read("*a"), "%s+", "")
group_handle:close()
user_handle:close()
local user = user_id..":"..group_id
return {
runtime,
"container",
"run",
"--interactive",
"--network="..network,
"--rm",
"--workdir="..workdir,
"--volume="..volume,
"--user="..user,
image
}
end,
}),
-- cmd = require'lspcontainers'.command('gopls'),
}
This could also solve https://github.com/lspcontainers/lspcontainers.nvim/issues/68 (not sure though)
I will test it later today or in the next few days, thanks!
Okay I can confirm, this solves the --user
related problems of lspcontainers/lspcontainers.nvim#68.
I just ran into a problem with this and I am not sure whether this is again podman related or not. While using your image with the --userid
flag I get a permission denied error when trying to download a go package (via code action) into the volume. When I remove the --userid
flag it works fine again. Is this the case for you? Do you have any ideas what causes this?
I believe I may have improved this in a separate PR if you don't mind testing this LSP and seeing if it's running faster. Thank you!