diff --git a/Dockerfile b/Dockerfile index 68ca3520..5980eb9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ gnupg \ tzdata \ openssh-server \ + inotify-tools \ + vim \ + nano \ && rm -rf /var/lib/apt/lists/* # Add deadsnakes PPA for Python 3.12 and install Python @@ -117,45 +120,48 @@ RUN chown -R $USERNAME:devusergroup /pythagora USER $USERNAME +RUN npx @puppeteer/browsers install chrome@stable + # add this before vscode... better caching of layers -ADD pythagora-vs-code.vsix pythagora-vs-code.vsix +ADD pythagora-vs-code.vsix /var/init_data/pythagora-vs-code.vsix RUN mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys -ARG commitHash -# VS Code server installation with platform-specific handling -RUN case "$TARGETPLATFORM" in \ - "linux/amd64") \ - mkdir -p ~/.vscode-server/cli/servers/Stable-${commitHash} && \ - curl -fsSL https://update.code.visualstudio.com/commit:${commitHash}/server-linux-x64/stable -o server-linux-x64.tar.gz && \ - tar -xz -f server-linux-x64.tar.gz -C ~/.vscode-server/cli/servers/Stable-${commitHash} && \ - mv ~/.vscode-server/cli/servers/Stable-${commitHash}/vscode-server-linux-x64 ~/.vscode-server/cli/servers/Stable-${commitHash}/server \ - ;; \ - "linux/arm64"|"linux/arm64/v8") \ - mkdir -p ~/.vscode-server/cli/servers/Stable-${commitHash} && \ - curl -fsSL https://update.code.visualstudio.com/commit:${commitHash}/server-linux-arm64/stable -o server-linux-arm64.tar.gz && \ - tar -xz -f server-linux-arm64.tar.gz -C ~/.vscode-server/cli/servers/Stable-${commitHash} && \ - mv ~/.vscode-server/cli/servers/Stable-${commitHash}/vscode-server-linux-arm64 ~/.vscode-server/cli/servers/Stable-${commitHash}/server \ - ;; \ - *) \ - echo "Unsupported platform: $TARGETPLATFORM" && exit 1 \ - ;; \ - esac +# ARG commitHash +# # VS Code server installation with platform-specific handling +# RUN case "$TARGETPLATFORM" in \ +# "linux/amd64") \ +# mkdir -p ~/.vscode-server/cli/servers/Stable-${commitHash} && \ +# curl -fsSL https://update.code.visualstudio.com/commit:${commitHash}/server-linux-x64/stable -o server-linux-x64.tar.gz && \ +# tar -xz -f server-linux-x64.tar.gz -C ~/.vscode-server/cli/servers/Stable-${commitHash} && \ +# mv ~/.vscode-server/cli/servers/Stable-${commitHash}/vscode-server-linux-x64 ~/.vscode-server/cli/servers/Stable-${commitHash}/server \ +# ;; \ +# "linux/arm64"|"linux/arm64/v8") \ +# mkdir -p ~/.vscode-server/cli/servers/Stable-${commitHash} && \ +# curl -fsSL https://update.code.visualstudio.com/commit:${commitHash}/server-linux-arm64/stable -o server-linux-arm64.tar.gz && \ +# tar -xz -f server-linux-arm64.tar.gz -C ~/.vscode-server/cli/servers/Stable-${commitHash} && \ +# mv ~/.vscode-server/cli/servers/Stable-${commitHash}/vscode-server-linux-arm64 ~/.vscode-server/cli/servers/Stable-${commitHash}/server \ +# ;; \ +# *) \ +# echo "Unsupported platform: $TARGETPLATFORM" && exit 1 \ +# ;; \ +# esac -# Create default VS Code settings with dark theme -# RUN mkdir -p ~/.local/share/code-server/User \ -# && echo '{"workbench.colorTheme": "Dark", "workbench.startupEditor": "none"}' \ -# > ~/.local/share/code-server/User/settings.json - # Install VS Code extension (platform-agnostic) -RUN ~/.vscode-server/cli/servers/Stable-${commitHash}/server/bin/code-server --install-extension pythagora-vs-code.vsix -RUN rm pythagora-vs-code.vsix +# RUN ~/.vscode-server/cli/servers/Stable-${commitHash}/server/bin/code-server --install-extension pythagora-vs-code.vsix +ADD on-event-extension-install.sh /var/init_data/on-event-extension-install.sh # Create a workspace directory -WORKDIR /pythagora/gpt-pilot/workspace +RUN mkdir -p /pythagora/gpt-pilot/pythagora-core/workspace + +RUN mkdir -p /home/$USERNAME/.vscode-server/cli/servers USER root +RUN chmod +x /var/init_data/initialize-vscs-pythagora.sh +RUN chmod +x /var/init_data/on-event-extension-install.sh +RUN chown -R devuser: /var/init_data/ + # Set the entrypoint to the main application ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 1f722cfd..f012a664 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,7 +15,13 @@ mongod --dbpath "$MONGO_DB_DATA" --bind_ip_all >> $MONGO_DB_DATA/mongo_logs.txt export DB_DIR=$PYTHAGORA_DATA_DIR/database -mkdir -p $DB_DIR -chown -R devuser: $DB_DIR +chown -R devuser: $PYTHAGORA_DATA_DIR +su - devuser -c "mkdir -p $DB_DIR" + +set -e + +su - devuser -c "cd /var/init_data/ && ./on-event-extension-install.sh &" + +echo "Starting ssh server..." /usr/sbin/sshd -D diff --git a/on-event-extension-install.sh b/on-event-extension-install.sh new file mode 100644 index 00000000..80d75422 --- /dev/null +++ b/on-event-extension-install.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +# Directory to monitor +MONITOR_DIR="$HOME/.vscode-server/cli/servers" +PATTERN="Stable-*" +EXCLUDE_SUFFIX=".staging" + +# Command to execute when a new directory is detected +COMMAND="echo 'New Stable directory detected:'" + +# Ensure inotify-tools is installed +if ! command -v inotifywait >/dev/null 2>&1; then + echo "Error: inotifywait is not installed. Please install inotify-tools." >&2 + exit 1 +fi + +# Monitor for directory creation +echo "Monitoring $MONITOR_DIR for new directories matching $PATTERN..." + +inotifywait -m -e create -e moved_to --format '%f' "$MONITOR_DIR" | while read -r NEW_ITEM; do + # Check if the created item matches the pattern + if [[ "$NEW_ITEM" == $PATTERN && "$NEW_ITEM" != *$EXCLUDE_SUFFIX ]]; then + echo "Detected new directory: $NEW_ITEM" + # Run the specified command + # $COMMAND "$MONITOR_DIR/$NEW_ITEM" + while [ ! -f "$HOME/.vscode-server/cli/servers/$NEW_ITEM/server/bin/code-server" ]; do + sleep 1 + done + mkdir -p /pythagora/gpt-pilot/pythagora-core/workspace/.vscode && printf '{\n "gptPilot.isRemoteWs": true,\n "gptPilot.useRemoteWs": false\n}' > /pythagora/gpt-pilot/pythagora-core/workspace/.vscode/settings.json + $HOME/.vscode-server/cli/servers/$NEW_ITEM/server/bin/code-server --install-extension /var/init_data/pythagora-vs-code.vsix + # echo "ok" > /pythagora/gpt-pilot/pythagora-core/workspace/pythagora-installed.txt + fi +done diff --git a/pythagora-vs-code.vsix b/pythagora-vs-code.vsix index 168c128d..e04b225c 100644 Binary files a/pythagora-vs-code.vsix and b/pythagora-vs-code.vsix differ