-
Hi there, I've found some similar threads at #171 and #2658 , however they don't seem to be active anymore. My idea was to ship a custom Docker image with some extensions already pre-installed. So I tried this out: FROM codercom/code-server:4.0.1
RUN code-server --install-extension golang.go This built successfully, however, when I executed my Docker image, no extensions were there. I tried then to add this in the form of a CMD, first installing the extension and then starting the executable, something like: FROM codercom/code-server:4.0.1
ENTRYPOINT [ "bash" ]
CMD ["code-server", "--install-extension", "golang.Go", "&&", "code-server" ] But it always always saying that it couldn't find the binary. So, in the end, what I had to do to get this working, was to create a small entrypoint script, which looks like the following: #!/bin/bash
code-server --install-extension golang.Go
code-server --auth none --host=0.0.0.0 --port=8080 And the Dockerfile: FROM codercom/code-server:4.0.1
COPY "entrypoint.sh" /
ENTRYPOINT [ "/entrypoint.sh" ] Can anyone maybe help me understand what's going on here? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
I agree, we should have docs on this. @bpmct has helped me with this in the past personally. Let me ping him and see if he can help. @code-asher might have some suggestions. After we get that, I can add a guide to the docs to help with this. |
Beta Was this translation helpful? Give feedback.
-
Do you mount anything to the container? I wonder if the extensions are installed into that directory then a mount is made on top, maybe to |
Beta Was this translation helpful? Give feedback.
-
I'm running Singularity for my container application, but I think the solution may transfer; although, I have a feeling it's not a perfect solution due to the unpredictable naming extensions can have, but it should at least reduce the number of extensions that install whenever the container runs. For Singularity there is a In my container definition file I have: Bootstrap: docker
From: debian:buster
%post
# Install basic packages, like curl. Application specific so they're not listed here
# Install Code-Server
curl -fsSL https://code-server.dev/install.sh | sh
# Install Pip3 and the toml package. The toml package will be used in the Python script every time the container runs.
apt install -y python3-pip
pip3 install toml
%runscript
# Run the Python script for installing extensions
cd /path/to/dir/with/script
python3 configure-code-server.py
# Starts the code-server instance
code-server
This isn't strictly necessary, but I have a In my configure-code-server.py file I have: from pathlib import Path
import subprocess
import os
import signal
import toml
# Define paths
config_file = Path("config.toml")
code_server_dir = Path("/root/.local/share/code-server/")
code_server_extensions_dir = code_server_dir / "extensions" # My script does more than this example so that's why this extra step exists
default_extensions_dir = Path("/path/to/extensions/holding/directory") # This should contain the default .vsix extensions that will be included in code server
if code_server_dir.exists() is False:
# Run Code-Server instance to create necessary directories from its internal setup process
p = subprocess.Popen(["code-server"],shell=False,preexec_fn=os.setsid)
# Seems to be the onlyway to kill the signal without generating zombie instances of code-server
os.kill(p.pid,signal.SIGINT)
if config_file.exists():
print("Parsing config.toml...")
parsed_toml = toml.load(config_file)
if parsed_toml["install_extensions"] is True:
p = subprocess.Popen(["code-server","--list-extensions"],stdout=subprocess.PIPE,stderr=None)
# Generate a list of extension name strings for those that are already installed
installed_extensions = p.communicate()[0].decode("utf-8").split("\n")
extensions = list(default_extensions_dir.glob('*.vsix'))
print("Checking extensions...")
for installed_extension_path in installed_extensions:
for extension in extensions:
# Remove the extensions directory prefix and split on the '.' to split the publisher from the extension name
installed_extension = str(installed_extension_path).strip("extensions/").split(".")
# Use the extension name to make the comparision to the current extension
if len(installed_extension) >=2 and installed_extension[1] in str(extension):
# Extension is already installed. Remove it so that it isn't installed again
extensions.remove(extension)
break
if extensions:
print("\nMissing extensions found...")
for extension in extensions:
# Run Code-Server --install-extension <extension> to install all extensions remaining in the list
p = subprocess.Popen(["code-server","--install-extension",str(extension)],shell=False)
time.sleep(2)
else:
print("No extensions to install") It would be really convenient if this behavior could be included in code-server directly instead of needing this. Something like |
Beta Was this translation helpful? Give feedback.
-
Actually, after coming back to it after some time, I managed to get my use case going, even with Docker. I think the issue that I had previously was related to me using the Helm chart which would, as stated earlier, mount some folders on top of the path that I was installing my own extension. My current Dockerfile is something similar to this: FROM node:alpine AS builder
RUN npm install -g vsce
WORKDIR /usr/app
COPY ./ /usr/app
RUN yarn install && \
vsce package
FROM codercom/code-server:4.0.1 AS release
COPY --from=builder /usr/app/*.vsix /my-extension.vsix
RUN ["code-server", "--install-extension", "/my-extension.vsix"]
COPY "entrypoint.sh" /
ENTRYPOINT [ "/entrypoint.sh" ] And the entrypoint:
|
Beta Was this translation helpful? Give feedback.
Actually, after coming back to it after some time, I managed to get my use case going, even with Docker. I think the issue that I had previously was related to me using the Helm chart which would, as stated earlier, mount some folders on top of the path that I was installing my own extension.
My current Dockerfile is something similar to this:
A…