spec icon indicating copy to clipboard operation
spec copied to clipboard

Allow cross-platform/per system initializeCommand definition

Open Destroy666x opened this issue 2 years ago • 10 comments

Not sure if it's the most proper repo to report this (if not, please redirect), but would be nice if there was a way to define initializeCommand per system in any way, so that the setup is truly cross-system. For example:

"initializeCommand": {
  "windows": "rd /s /q somedir",
  "linux": "rm -rf somedir",
  "macos": "..."
}

Use case example: https://stackoverflow.com/questions/77199011/how-to-create-a-cross-platform-initializecommand-for-visual-studio-codes-dev-co (copying proper .env file before container launch).

Destroy666x avatar Dec 04 '23 06:12 Destroy666x

Thanks for filing! I believe this would also be related to (and potentially covered by) https://github.com/devcontainers/spec/issues/58, https://github.com/devcontainers/spec/issues/405.

bamurtaugh avatar Jan 25 '24 00:01 bamurtaugh

Potentially indeed - assuming "features"/"things" include initiaizeCommand. If yes - looking forwards to that.

Destroy666x avatar Jan 25 '24 05:01 Destroy666x

This is indeed something required because depending on the host OS, different commands are needed to prepare the container to run.

In my case, I want to mount the .npmrc from the host system to avoid having to re-login every time I open a container. However, if a machine doesn't have the .npmrc file the mounts will fails.

	// It seems that if the .npmrc file is not present, then the container can't
    // be open. To not force, contributor to have an NPM account,
    // we create a dummy .npmrc file if it doesn't exist
    "initializeCommand": "if [ ! -f ~/.npmrc ]; then touch ~/.npmrc; fi",

    "mounts": [
        // Mount .npmrc from the host machine, to be able to use the host session
        // This allow the user to login on their own machine once and not each time
        // they build a new devcontainer
        "source=${localEnv:HOME}${localEnv:USERPROFILE}/.   ,target=/home/vscode/.npmrc,type=bind,consistency=cached"
    ],

I need to support both scenario to make my life easier as a maintainer but also not force contributor to have an NPM account.

MangelMaxime avatar Jun 17 '24 14:06 MangelMaxime

Being able to set up OS-specific InitializeCommand is definitely something I need as well.

Is there a way to choose the shell for executing InitializeCommand? It seems that on Mac, it runs with bash, while on Windows, it runs with PowerShell.

marystory avatar Jun 28 '24 18:06 marystory

Steve Bombardier

Le ven. 28 juin 2024, 14 h 37, Maryam.to @.***> a écrit :

Being able to set up OS-specific InitializeCommand is definitely something I need as well.

Is there a way to choose the shell for executing InitializeCommand? It seems that on Mac, it runs with bash, while on Windows, it runs with PowerShell.

— Reply to this email directly, view it on GitHub https://github.com/devcontainers/spec/issues/347#issuecomment-2197442843, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7XISKS6HUR7TWPT7PVN45DZJWUNNAVCNFSM6AAAAABAFPEFIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJXGQ2DEOBUGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Bombay268 avatar Jun 28 '24 22:06 Bombay268

https://github.com/microsoft/vscode-remote-release/issues/3007#issuecomment-1942968611

sdavids avatar May 04 '25 06:05 sdavids

That's a nice workaround that works with all types of commands. However, Mac and Linux separation could be needed at times and it'd be a lot more convoluted with those.

Destroy666x avatar May 14 '25 13:05 Destroy666x

For a true cross-system repository, consider a monorepo

Roboticsense00 avatar May 20 '25 23:05 Roboticsense00

For a true cross-system repository, consider a monorepo

How does that solve anything?? A monorepo is just a repo with multiple projects in it that share some base. Here we want to share a devcontainer configuration between platforms, which has nothing to do with a monorepo.

Blondee91 avatar May 24 '25 13:05 Blondee91