Skip to content

Parameter extra_volumes for mounting additional volumes on the container#69

Open
B3RR10 wants to merge 6 commits intolspcontainers:mainfrom
B3RR10:main
Open

Parameter extra_volumes for mounting additional volumes on the container#69
B3RR10 wants to merge 6 commits intolspcontainers:mainfrom
B3RR10:main

Conversation

@B3RR10
Copy link

@B3RR10 B3RR10 commented May 15, 2022

As proposed by @WhyNotHugo in the issue lspcontainers/dockerfiles#55, it could be useful to be able to mount additional directories to the containers.

This could be a start on solving the "customization" on the go-lsp case, and support global caches, which is very common in several languages such as rust, C# (omnisharp/nuget), ruby (solargraph/bundle), etc.

Copy link
Contributor

@WhyNotHugo WhyNotHugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't had a chance to test this, but the changes LGTM.

@erikreinert
Copy link
Contributor

This looks good - can you possibly resolve the conflicts on this and I'll merge it? Thank you!

B3RR10 added 4 commits July 8, 2022 22:50
* lspcontainers-main:
  docs: Add info for extra_volumes in README
  feat: add param extra_volumes for mounting multiple directories
  fix(gopls): networking mode depending on runtime (lspcontainers#76)
  fix(api): add runtime parameter to images_remove (lspcontainers#83)
  feat(server): Add tailwindcss language server (lspcontainers#81)
  Use lua to define custom commands (lspcontainers#66)
  fix(sysname): work with uname instead vim.fn.has (lspcontainers#71)
  feat(*): add prismals (lspcontainers#79)
  feat(selinux): add selinux labels to volumes for shared access (lspcontainers#72)
@B3RR10
Copy link
Author

B3RR10 commented Jul 8, 2022

@erikreinert Sorry that it took so long... But the conflicts were resolved

@jgero
Copy link
Contributor

jgero commented Jul 20, 2022

Would it be a good idea to maybe add named volumes as default values for this? I am doing this with my own setup at the moment. This enables persisting those directories between containers and even between projects even. I think this makes sense because these files are of no use mounted on the host anyways because the compilers and language servers that would use those are not installed on the host anyways when you run these tools in a container.

@WhyNotHugo
Copy link
Contributor

An attribute for each LSP with the volume mappings as strings makes sense.

@WhyNotHugo
Copy link
Contributor

WhyNotHugo commented Jul 21, 2022

I've been using bubblewrap to sandbox some locally-installed containers, and I'm defining per-LSP config with this format:

      network = true,
      volumes = {
        {
          host = "/home/hugo/.local/state/rustup",
          lsp = "/home/hugo/.local/state/rustup",
          readonly = false
        },
      },

This works well because it's easy to convert this into either docker or bubblewrap arguments.

@WhyNotHugo
Copy link
Contributor

I should caution that mounting things like go's cache or rust's cache has some risks tho. In particular, a compromised LSP could pollute the shared cache, and this would be picked up by the compiler when building some other project on the host.

@jgero
Copy link
Contributor

jgero commented Jul 22, 2022

I've been using bubblewrap to sandbox some locally-installed containers, and I'm defining per-LSP config with this format:

      network = true,
      volumes = {
        {
          host = "/home/hugo/.local/state/rustup",
          lsp = "/home/hugo/.local/state/rustup",
          readonly = false
        },
      },

This works well because it's easy to convert this into either docker or bubblewrap arguments.

Are you using bubblewrap as a runtime substitution for docker or podman? How does this work, are the CLIs compatible? Otherwise I think this is out of scope for this plugin. If you really want to use that configuration style you could just include the logic to convert from this style to a volume string in your config. For the configuration value I strongly prefer a string type instead of a table. With the table style the user would be unable to add SE Linux labels (the :z at the end) or use named volumes, which I think is a big limitation for no real benefit imo.

@WhyNotHugo
Copy link
Contributor

Are you using bubblewrap as a runtime substitution for docker or podman?

Essentially yes.

How does this work, are the CLIs compatible?

Not at all. But a lot of definitions are. Like volume mappings (+readonly), network (enabled/disabled), etc. Just looking to avoid duplicating all that TBH.

If you really want to use that configuration style you could just include the logic to convert from this style to a volume string in your config.

The configuration style I'm suggesting is rather backend-agnostic, and that's the whole point...

With the table style the user would be unable to add SE Linux labels (the :z at the end)

Appending this to the string is part of generating the cli, and not something that users need to provide IMHO.

This is already the case now too, btw.

@jgero
Copy link
Contributor

jgero commented Jul 22, 2022

Okay I'm sorry I was wrong then. How would a named volume setup look with the table style configuration?

lua

network = true,
      volumes = {
        {
          host = "named_volume",
          lsp = "/home/hugo/.local/state/rustup",
          readonly = false
        },
      },

Something like this?

@jgero
Copy link
Contributor

jgero commented Jul 31, 2022

Would allowing functions as parameters for the extra volumes make sense? I just thought of that because functions would then enable something like this:

image = "docker.io/lspcontainers/gopls",
extra_volumes = {
  function ()
    local env = vim.api.nvim_eval('environ()')
    local gopath = env.GOPATH or env.HOME.."/go"
    return gopath..":"..gopath..":z"
  end
}

It is definitely not necessary but I think some people would like and use this. It would also be useful for setting default values in the plugin itself.

@WhyNotHugo
Copy link
Contributor

@jgero Your function returns the same value each time it's run -- you could just execute that code once and pass its output to extra_volumes. There's no need to regenerate the volumes each time. I guess a function could help if there are scenarios where the volumes vary depending on some runtime condition that can change... but I can't think of any real examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants