Skip to content

Commit 8c66dcb

Browse files
authored
Merge pull request #532 from atheo89/install-extensions-on-folder
Allow code-server extensions to be installed while the build time
2 parents 97b3362 + a609ef0 commit 8c66dcb

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

codeserver/ubi9-python-3.9/Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ RUN yum install -y "https://github.com/coder/code-server/releases/download/${COD
3939
RUN chmod -R g+w /opt/app-root/lib/python3.9/site-packages && \
4040
fix-permissions /opt/app-root -P
4141

42+
COPY --chown=1001:0 utils utils/
43+
44+
# Create and intall the extensions though build-time on a temporary directory. Later this directory will copied on the `/opt/app-root/src/.local/share/code-server/extensions` via run-code-server.sh file when it starts up.
45+
RUN mkdir -p /opt/app-root/extensions-temp && \
46+
code-server --install-extension /opt/app-root/bin/utils/ms-python.python-2024.2.1.vsix --extensions-dir /opt/app-root/extensions-temp && \
47+
code-server --install-extension /opt/app-root/bin/utils/ms-toolsai.jupyter-2023.9.100.vsix --extensions-dir /opt/app-root/extensions-temp
48+
4249
# Install NGINX to proxy code-server and pass probes check
4350
ENV NGINX_VERSION=1.24 \
4451
NGINX_SHORT_VER=124 \
@@ -88,15 +95,20 @@ RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf.sed ${NGINX_CONF_PATH} && \
8895
chmod -R ug+rwX ${NGINX_APP_ROOT}/etc && \
8996
chmod -R ug+rwX ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
9097
chmod -R ug+rwX /var/lib/nginx /var/log/nginx /run && \
91-
rpm-file-permissions
98+
rpm-file-permissions && \
99+
# Ensure the temporary directory and target directory have the correct permissions
100+
mkdir -p /opt/app-root/src/.local/share/code-server/extensions && \
101+
mkdir -p /opt/app-root/src/.local/share/code-server/coder-logs && \
102+
chown -R 1001:0 /opt/app-root/src/.local/share/code-server && \
103+
chown -R 1001:0 /opt/app-root/extensions-temp && \
104+
chown -R 1001:0 /opt/app-root/src/.config/code-server
92105

93106
## Configure nginx
94107
COPY nginx/serverconf/ /opt/app-root/etc/nginx.default.d/
95108
COPY nginx/httpconf/ /opt/app-root/etc/nginx.d/
96109
COPY nginx/api/ /opt/app-root/api/
97110

98111
# Launcher
99-
COPY --chown=1001:0 utils utils/
100112
COPY --chown=1001:0 run-code-server.sh run-nginx.sh ./
101113

102114
ENV SHELL /bin/bash

codeserver/ubi9-python-3.9/run-code-server.sh

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,31 @@ else
4242
fi
4343
fi
4444

45-
# # Check if code-server folder exists
46-
if [ ! -f "/opt/app-root/src/.local/share/code-server" ]; then
45+
# Ensure the extensions directory exists
46+
extensions_dir="/opt/app-root/src/.local/share/code-server/extensions"
47+
mkdir -p "$extensions_dir"
4748

48-
# Check internet connection - this check is for disconected enviroments
49-
if curl -Is http://www.google.com | head -n 1 | grep -q "200 OK"; then
50-
# Internet connection is available
51-
echo "Internet connection available. Installing specific extensions."
52-
53-
# Install specific extensions
54-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-python.python-2024.2.1.vsix
55-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-toolsai.jupyter-2023.9.100.vsix
49+
# Copy installed extensions to the runtime extensions directory if they do not already exist
50+
if [ -d "/opt/app-root/extensions-temp" ]; then
51+
for extension in /opt/app-root/extensions-temp/*/;
52+
do
53+
extension_folder=$(basename "$extension")
54+
if [ ! -d "$extensions_dir/$extension_folder" ]; then
55+
cp -r "$extension" "$extensions_dir"
56+
echo "Debug: Extension '$extension_folder' copied to runtime directory."
5657
else
57-
# No internet connection
58-
echo "No internet connection. Installing all extensions."
59-
60-
# Install all extensions
61-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-python.python-2024.2.1.vsix
62-
code-server --install-extension ${SCRIPT_DIR}/utils/[email protected]
63-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-toolsai.jupyter-2023.9.100.vsix
64-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-toolsai.jupyter-keymap-1.1.2.vsix
65-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-toolsai.jupyter-renderers-1.0.17.vsix
66-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-toolsai.vscode-jupyter-cell-tags-0.1.8.vsix
67-
code-server --install-extension ${SCRIPT_DIR}/utils/ms-toolsai.vscode-jupyter-slideshow-0.1.5.vsix
58+
echo "Debug: Extension '$extension_folder' already exists in runtime directory, skipping."
6859
fi
60+
done
61+
else
62+
echo "Debug: Temporary extensions directory not found."
63+
fi
64+
65+
# Ensure log directory exists
66+
logs_dir="/opt/app-root/src/.local/share/code-server/coder-logs"
67+
if [ ! -d "$logs_dir" ]; then
68+
echo "Debug: Log directory not found, creating '$logs_dir'..."
69+
mkdir -p "$logs_dir"
6970
fi
7071

7172
# Start server

0 commit comments

Comments
 (0)