Skip to content

Devcontainer customizations.vscode.settings are not honored #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nwrkbiz opened this issue Feb 11, 2024 · 2 comments
Open

Devcontainer customizations.vscode.settings are not honored #89

nwrkbiz opened this issue Feb 11, 2024 · 2 comments

Comments

@nwrkbiz
Copy link
Contributor

nwrkbiz commented Feb 11, 2024

Settings placed within devcontainer.json: customizations.vscode.settings are ignored.

Example: https://gitlab.com/nwrkbiz/cpp-design-patterns/-/tree/b81d6fdd2fcac393b491e8725387c99cf822b291/.devcontainer

@barrettMCW
Copy link

barrettMCW commented Apr 3, 2024

Ran into this as well but while I was trying to add extensions through customizations.vscode.extensions
Would be great to get this functionality native but in the meantime I whipped up a startup script that applies the customizations using python.

  startup_script = <<-EOT
    curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server 
    
    code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
    # for whatever reason the /tmp code-server doesn't install plugins where we want, find the correct code-server
    export PATH="$${HOME}/.vscode-server/bin/${"$"}( ls $${HOME}/.vscode-server/bin*)/bin/:$${PATH}"

    # we typically only work on one repo per workspace, use the git folder to find repo
    cd /workspaces/*/.git/..

    # Parse devcontainer.json and apply settings and extensions using Python
    python3 -c "
    import json, os, sys

    # Define the possible paths for the devcontainer.json file
    POSSIBLE_PATHS = ['.devcontainer.json', '.devcontainer/devcontainer.json']

    # Find the actual path of the devcontainer.json file
    DEVCONTAINER_FILE = None
    for path in POSSIBLE_PATHS:
        if os.path.isfile(path):
            DEVCONTAINER_FILE = path
            break

    if not DEVCONTAINER_FILE:
        print('devcontainer.json file not found in the expected locations.')
        sys.exit(1)

    # Load the devcontainer.json file
    with open(DEVCONTAINER_FILE) as f:
        data = json.load(f).get('customizations',{}).get('vscode',{})

    # Apply VS Code extensions
    extensions = data.get('extensions', [])
    if extensions:
        for extension in extensions:
            print(f'Installing extension: {extension}')
            os.system(f'code-server --install-extension {extension}')
    else:
        print(f'No extensions found in {DEVCONTAINER_FILE}')

    # Apply VS Code settings
    settings = data.get('settings', {})
    if settings:
        CONFIG_DIR = '$${HOME}/.vscode-server/data/Machine'
        os.makedirs(CONFIG_DIR, exist_ok=True)
        with open(f'{CONFIG_DIR}/settings.json', 'w') as f:
            json.dump(settings, f, indent=4)
        print('VS Code settings applied.')
    else:
        print(f'No settings found in {DEVCONTAINER_FILE}')
    "
    code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT

I had a version of this working in bash locally with grep and sed, but couldn't get it through terraform without it getting mangled. If someone doesn't work in python I imagine you could get around it by putting the bash script in a configmap, mounting it to all workspaces and adding it as a part of the startup script, but I mostly work in python so this does the job for me.

@nwrkbiz
Copy link
Contributor Author

nwrkbiz commented Apr 3, 2024

I hacked together a solution which works within coder using bash and jq that extracts the stuff and puts it into a settings.json file. I will share it as soon as I am at home.

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

No branches or pull requests

3 participants