coder / code-server

VS Code in the browser
https://coder.com
MIT License
67.65k stars 5.55k forks source link

[Bug]: Specified custom settings.json is ignored #6577

Closed distributev closed 6 months ago

distributev commented 9 months ago

Is there an existing issue for this?

OS/Web Information

I'm using docker/docker-compose

Steps to Reproduce

I tried without success

      - ../../..:/workspace
      - ../.vscode/settings.json:/home/coder/.local/share/code-server/User/settings.json

not working

      - ../../..:/workspace
      - FULL_PATH/.vscode/settings.json:/home/coder/.local/share/code-server/User/settings.json

not working

      - ../../..:/workspace
      - ../.vscode:/home/coder/.vscode

together with code-server --user-data-dir ~/.vscode

still not working

I also tried

      - ../../..:/workspace
      - ../.vscode:/home/coder/.local/share/code-server

again not working

Whatever I tried Code Server did not took my custom settings.json with my own colors.

The only thing which was working was to place my settings.json directly into the root folder opened into Code Server ../../../.vscode but I need to have my custom settings.json located here ../.vscode

Expected

Code Server should use the custom settings.json

Below is an except from the docs which I tried and this is not working.

Where is VS Code configuration stored?

VS Code configuration such as settings and keybindings are stored in ~/.local/share/code-server by default.

Alternatively, you can also pass --user-data-dir ~/.vscode or copy ~/.vscode into ~/.local/share/code-server to reuse your existing VS Code extensions and configuration.

I tried both and it is not working.

Actual

Code Server show use the specified settings.json

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

Are you accessing code-server over a secure context?

Notes

Code Server seems to load ROOT/.vscode/settings.json only from the root folder and nothing else.

code-asher commented 9 months ago

I just tested without Docker and this seems to be working (although it takes a few seconds for the theme to apply).

Could you post the output of code-server on the terminal? I think you can get it with docker logs.

If you post your Docker files and the command(s) you are running I will try them out to see if I get the same error.

distributev commented 9 months ago

image

image

I did not notice any errors in the logs.

version: "3.8"
services:
  code-server-test:
    container_name: code-server-test
    build:
      context: .
      dockerfile: Dockerfile.code-server
    command: bash -c "git config --global user.name $$GIT_USERNAME && git config --global user.email $$GIT_EMAIL && /usr/bin/code-server --auth none --bind-addr 0.0.0.0:8080"
    environment:
      - GIT_USERNAME=test_user
      - GIT_EMAIL=test_user@gmail.com
    volumes:
      - ../../..:/workspace
      - ../.vscode/settings.json:/home/coder/.local/share/code-server/User/settings.json
    restart: unless-stopped
    networks:
      - bridge_current_host_cross_containers_net

networks:
  bridge_current_host_cross_containers_net:
    driver: bridge
    external: true

settings.json colors are not used.

I did login to the container and checked the content of settings.json to be correct (it is) still the colors I use there have no effect.

I also tried with

- ../../..:/workspace
- ../.vscode:/home/coder/.vscode

without luck also.

Dockerfile.code-server is in the same folder as docker-compose.yml

# Start from a base image with Node.js
FROM node:14

# Install utilities
RUN apt-get update && apt-get install -y curl

# Install code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh

# Install VS Code extensions
# https://open-vsx.org (only extensions available here work)
RUN code-server --install-extension dbaeumer.vscode-eslint
RUN code-server --install-extension esbenp.prettier-vscode
RUN code-server --install-extension Gruntfuggly.todo-tree
RUN code-server --install-extension humao.rest-client

# Set the working directory
WORKDIR /workspace

# Expose port for code-server
EXPOSE 8080

# Start code-server
CMD ["code-server", "--bind-addr", "0.0.0.0:8080", "--auth", "none"]
code-asher commented 9 months ago

I did not notice any errors in the logs.

I was not looking for errors, I wanted to see where code-server thinks the user data directory is.

But, thank you for the files! It looks like you are running code-server as the root user. ~ for root is /root, not /home/coder, so you need:

../.vscode/settings.json:/root/.local/share/code-server/User/settings.json

You can confirm this by checking your code-server output. For example here is what mine said when I ran your setup (note the Using user-data-dir line):

[2023-12-15T19:16:31.133Z] info  code-server 4.19.1 0c98611e6b43803a9d5dba222d7023b569abfb49
[2023-12-15T19:16:31.134Z] info  Using user-data-dir /root/.local/share/code-server
[2023-12-15T19:16:31.145Z] info  Using config file /root/.config/code-server/config.yaml
[2023-12-15T19:16:31.146Z] info  HTTP server listening on http://0.0.0.0:8080/
[2023-12-15T19:16:31.146Z] info    - Authentication is disabled
[2023-12-15T19:16:31.146Z] info    - Not serving HTTPS
[2023-12-15T19:16:31.146Z] info  Session server listening on /root/.local/share/code-server/code-server-ipc.sock

Alternatively, you can set up a coder user in your Dockerfile. Check out our release image Dockerfile for how to do that, or you could extend our Docker image.

munjalpatel commented 8 months ago

@code-asher I also have same issues.

  1. The pre-installed extensions are not available when I open Code Server in browser. I also don't see them in the mounted volume ./.code-server
  2. My custom settings.json file goes missing once the container starts.

Dockerfile

FROM node:21.5.0

RUN apt-get update && apt-get install -y \
    elixir erlang-dev erlang-xmerl erlang-os-mon && \
    mix local.hex && \
    mix local.rebar

RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
    -p git \
    -p node \
    -p https://github.com/zsh-users/zsh-completions \
    -p https://github.com/zsh-users/zsh-autosuggestions

RUN npm install -g pnpm && \
    SHELL=bash pnpm setup && \
    pnpm config set store-dir /root/.local/share/pnpm/store

RUN npm install -g turbo commitizen

RUN curl -fsSL https://code-server.dev/install.sh | sh

RUN code-server --install-extension bradlc.vscode-tailwindcss
RUN code-server --install-extension vscode-icons-team.vscode-icons
RUN code-server --install-extension ms-azuretools.vscode-docker
RUN code-server --install-extension PROxZIMA.sweetdracula
RUN code-server --install-extension streetsidesoftware.code-spell-checker
RUN code-server --install-extension dbaeumer.vscode-eslint
RUN code-server --install-extension rvest.vs-code-prettier-eslint
RUN code-server --install-extension esbenp.prettier-vscode
RUN code-server --install-extension elixir-lsp.elixir-ls

COPY ./.vscode/code-server.settings.json /root/.local/share/code-server/User/settings.json

EXPOSE 8080

CMD code-server --auth none --proxy-domain localdev.local --bind-addr 0.0.0.0:8080 /workspace

docker-compose.yaml

services:
  code-server:
    image: local-code-server:dev-1.0
    build:
      context: .
      dockerfile: dev.dockerfile
    ports:
      - 80:8080
      - 8080:8080
    volumes:
      - .:/workspace
      - ./.code-server:/root/.local/share/code-server

Logs:

local-code-server-1  | [2023-12-28T23:05:48.034Z] info  code-server 4.20.0 d0215eca8804d0be5d3551c39404e336032c3141
local-code-server-1  | [2023-12-28T23:05:48.035Z] info  Using user-data-dir /root/.local/share/code-server
local-code-server-1  | [2023-12-28T23:05:48.053Z] info  Using config file /root/.config/code-server/config.yaml
local-code-server-1  | [2023-12-28T23:05:48.053Z] info  HTTP server listening on http://0.0.0.0:8080/
local-code-server-1  | [2023-12-28T23:05:48.053Z] info    - Authentication is disabled
local-code-server-1  | [2023-12-28T23:05:48.053Z] info    - Not serving HTTPS
local-code-server-1  | [2023-12-28T23:05:48.053Z] info    - Proxying the following domain:
local-code-server-1  | [2023-12-28T23:05:48.053Z] info      - {{port}}.localdev.local
local-code-server-1  | [2023-12-28T23:05:48.054Z] info  Using proxy URI in PORTS tab: //{{port}}.localdev.local
local-code-server-1  | [2023-12-28T23:05:48.054Z] info  Session server listening on /root/.local/share/code-server/code-server-ipc.sock
code-asher commented 8 months ago

Thank you for the reproduction steps and logs @munjalpatel!

When you mount, the local directory gets placed on top of the remote directory and anything inside the remote directory is essentially wiped. The extensions and settings are placed inside /root/.local/share/code-server, but then you mount a local directory (.code-server) on top of that, wiping out the remote directory that had the settings and extensions in it.

Here are some ideas:

  1. Instead of copying the settings file, mount it in (so place it in .code-server/User/settings.json and remove the COPY.
  2. Install the extensions after the mount (so as part of the entrypoint) OR put the extensions somewhere else (--extensions-dir /root/extensions for example)
code-asher commented 6 months ago

Closing since this does not appear to be a code-server bug, but please feel free to continue commenting if you need help.