Giter VIP home page Giter VIP logo

Comments (2)

nwrkbiz avatar nwrkbiz commented on August 11, 2024 1

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.

from envbuilder.

barrettMCW avatar barrettMCW commented on August 11, 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.

from envbuilder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.