Skip to content

Commit

Permalink
feat(vscode): retry mechanism for extensions installation
Browse files Browse the repository at this point in the history
  • Loading branch information
avouacr committed Aug 7, 2024
1 parent 32ea1d6 commit 0bf54ca
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 33 deletions.
76 changes: 76 additions & 0 deletions scripts/install-vscode-extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

# Number of retries
retries=3
# Wait time between retries
wait_time=10

# Function to install an extension with retries
install_extension() {
local extension=$1
local attempt=1

while [ $attempt -le $retries ]; do
code-server --install-extension $extension && break
echo "Failed to install $extension. Attempt $attempt/$retries. Retrying in $wait_time seconds..."
attempt=$((attempt + 1))
sleep $wait_time
done

if [ $attempt -gt $retries ]; then
echo "Failed to install $extension after $retries attempts."
exit 1
fi
}

# Install base extensions
base_extensions=(
"ms-toolsai.jupyter"
"ms-kubernetes-tools.vscode-kubernetes-tools"
"mhutchie.git-graph"
"hediet.vscode-drawio"
"streetsidesoftware.code-spell-checker"
"streetsidesoftware.code-spell-checker-french"
)
for extension in "${base_extensions[@]}"; do
install_extension $extension
done

# Python-specific configuration
python_extensions=(
"ms-python.python"
"ms-python.flake8"
)
if command -v python &> /dev/null; then
for extension in "${python_extensions[@]}"; do
install_extension $extension
done
python_path=$(which python)
jq --arg pythonPath "$python_path" '.["python.defaultInterpreterPath"] = $pythonPath' ${REMOTE_CONFIG_DIR}/settings.json > tmp.json && mv tmp.json ${REMOTE_CONFIG_DIR}/settings.json
fi

# R-specific configuration
r_extensions=(
"reditorsupport.r"
"RDebugger.r-debugger"
)
if command -v R &> /dev/null; then
for extension in "${r_extensions[@]}"; do
install_extension $extension
done
R -e "install.packages(c('languageserver', 'rmarkdown', 'httpgd'))"
R -e "remotes::install_github('ManuelHentschel/vscDebugger')"
pip install radian
r_path=$(which radian)
jq --arg rPath "$r_path" '.["r.rterm.linux"] = $rPath' ${REMOTE_CONFIG_DIR}/settings.json > tmp.json && mv tmp.json ${REMOTE_CONFIG_DIR}/settings.json
fi

# Julia-specific configuration
if command -v julia &> /dev/null; then
install_extension "julialang.language-julia"
fi

# Quarto-specific configuration
if command -v quarto &> /dev/null; then
install_extension "quarto.quarto"
fi
35 changes: 2 additions & 33 deletions vscode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,8 @@ RUN curl -fsSL https://code-server.dev/install.sh | bash && \
COPY --chown=${USERNAME}:${GROUPNAME} settings/User.json ${USER_CONFIG_DIR}/settings.json
COPY --chown=${USERNAME}:${GROUPNAME} settings/Remote.json ${REMOTE_CONFIG_DIR}/settings.json

# VSCode extensions and configuration
RUN code-server --install-extension ms-toolsai.jupyter && \
code-server --install-extension ms-kubernetes-tools.vscode-kubernetes-tools && \
code-server --install-extension ms-azuretools.vscode-docker && \
code-server --install-extension njpwerner.autodocstring && \
code-server --install-extension mhutchie.git-graph && \
code-server --install-extension rangav.vscode-thunder-client && \
code-server --install-extension hediet.vscode-drawio && \
code-server --install-extension pomdtr.excalidraw-editor && \
code-server --install-extension streetsidesoftware.code-spell-checker && \
code-server --install-extension streetsidesoftware.code-spell-checker-french && \
# Language specific VSCode extensions and config
if command -v python; then \
code-server --install-extension ms-python.python && \
code-server --install-extension ms-python.flake8 && \
jq --arg pythonPath $(which python) '.["python.defaultInterpreterPath"] = $pythonPath' ${REMOTE_CONFIG_DIR}/settings.json > tmp.json && \
mv tmp.json ${REMOTE_CONFIG_DIR}/settings.json; \
fi && \
if command -v R; then \
code-server --install-extension reditorsupport.r && \
code-server --install-extension RDebugger.r-debugger && \
R -e "install.packages(c('languageserver', 'rmarkdown', 'httpgd'))" && \
R -e "remotes::install_github('ManuelHentschel/vscDebugger')" && \
pip install radian && \
jq --arg rPath $(which radian) '.["r.rterm.linux"] = $rPath' ${REMOTE_CONFIG_DIR}/settings.json > tmp.json && \
mv tmp.json ${REMOTE_CONFIG_DIR}/settings.json; \
fi && \
if command -v julia; then \
code-server --install-extension julialang.language-julia; \
fi && \
if command -v quarto; then \
code-server --install-extension quarto.quarto; \
fi && \
# VSCode extensions and language-specific configuration
RUN /opt/install-vscode-extensions.sh && \
# Fix permissions
chown -R ${USERNAME}:${GROUPNAME} ${HOME} && \
# Clean
Expand Down

0 comments on commit 0bf54ca

Please sign in to comment.