envbuilder
envbuilder copied to clipboard
Devcontainer customizations.vscode.settings are not honored
Settings placed within devcontainer.json: customizations.vscode.settings are ignored.
Example: https://gitlab.com/nwrkbiz/cpp-design-patterns/-/tree/b81d6fdd2fcac393b491e8725387c99cf822b291/.devcontainer
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.
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.