fix docker build

This commit is contained in:
Shan Indrakumar
2025-03-19 18:07:18 -04:00
parent aee37628bd
commit 14c6110367
4 changed files with 110 additions and 7 deletions

View File

@@ -5,6 +5,9 @@ FROM ubuntu:22.04
ARG TARGETPLATFORM
ARG BUILDPLATFORM
# Set defaults for TARGETPLATFORM to ensure it's available in scripts
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
# Copy VSIX file first
COPY pythagora-vs-code.vsix /var/init_data/pythagora-vs-code.vsix
@@ -72,4 +75,4 @@ RUN mkdir -p ${PYTH_INSTALL_DIR}/pythagora-core/workspace && \
chown -R devuser:devusergroup ${PYTH_INSTALL_DIR}/pythagora-core/workspace
# Remove the USER directive to keep root as the running user
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -5,7 +5,21 @@ set -e
export DEBIAN_FRONTEND=noninteractive
export TZ=Etc/UTC
# IMPORTANT: Create a dummy update-ca-certificates script that does nothing
# This completely bypasses the problematic ca-certificates update process
echo "Creating dummy update-ca-certificates script"
if [ -f /usr/sbin/update-ca-certificates ]; then
mv /usr/sbin/update-ca-certificates /usr/sbin/update-ca-certificates.orig
fi
cat > /usr/sbin/update-ca-certificates << 'EOF'
#!/bin/sh
echo "Dummy update-ca-certificates called, doing nothing"
exit 0
EOF
chmod +x /usr/sbin/update-ca-certificates
# Update package list and install prerequisites
echo "Installing basic packages"
apt-get update && apt-get install -y --no-install-recommends \
software-properties-common \
build-essential \
@@ -17,29 +31,37 @@ apt-get update && apt-get install -y --no-install-recommends \
vim \
nano \
lsof \
procps
procps \
ca-certificates
echo "Basic packages installed successfully"
rm -rf /var/lib/apt/lists/*
# Install Python 3.12
echo "Adding Python 3.12 PPA"
add-apt-repository ppa:deadsnakes/ppa -y && apt-get update
echo "Installing Python 3.12"
apt-get install -y --no-install-recommends \
python3.12 \
python3.12-venv \
python3.12-dev \
python3-pip
echo "Python 3.12 installed successfully"
rm -rf /var/lib/apt/lists/*
# Set Python 3.12 as default
echo "Setting Python 3.12 as default"
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
python --version
# Install Node.js
echo "Installing Node.js"
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
node --version && npm --version
# Install MongoDB based on platform architecture
echo "Installing MongoDB"
case "$TARGETPLATFORM" in
"linux/amd64")
MONGO_ARCH="amd64"
@@ -48,17 +70,19 @@ case "$TARGETPLATFORM" in
MONGO_ARCH="arm64"
;;
*)
echo "Unsupported platform: $TARGETPLATFORM"
exit 1
echo "Using default architecture amd64 for MongoDB"
MONGO_ARCH="amd64"
;;
esac
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-archive-keyring.gpg
echo "deb [arch=$MONGO_ARCH signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
apt-get update && apt-get install -y mongodb-org
echo "MongoDB installed successfully"
rm -rf /var/lib/apt/lists/*
# Install code-server
echo "Installing code-server"
VERSION="4.97.2"
case "$TARGETPLATFORM" in
"linux/amd64")
@@ -68,8 +92,8 @@ case "$TARGETPLATFORM" in
PLATFORM="arm64"
;;
*)
echo "Unsupported platform: $TARGETPLATFORM"
exit 1
echo "Using default platform amd64 for code-server"
PLATFORM="amd64"
;;
esac
@@ -88,6 +112,7 @@ mkdir -p /etc/code-server
tar -xzf /tmp/code-server.tar.gz -C /usr/local/lib/code-server --strip-components=1
ln -s /usr/local/lib/code-server/bin/code-server /usr/local/bin/code-server
rm /tmp/code-server.tar.gz
echo "code-server installed successfully"
# Create default config
cat > /etc/code-server/config.yaml << EOF
@@ -98,4 +123,15 @@ user-data-dir: /usr/local/share/code-server/data
EOF
# Pre-install extension
code-server --config /etc/code-server/config.yaml --install-extension /var/init_data/pythagora-vs-code.vsix
echo "Installing VS Code extension..."
code-server --config /etc/code-server/config.yaml --install-extension /var/init_data/pythagora-vs-code.vsix || {
echo "Extension installation failed but continuing build process..."
}
# Restore original update-ca-certificates if it exists
if [ -f /usr/sbin/update-ca-certificates.orig ]; then
mv /usr/sbin/update-ca-certificates.orig /usr/sbin/update-ca-certificates
echo "Restored original update-ca-certificates"
fi
echo "Setup completed successfully"

30
entrypoint.sh.original Normal file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
if [ -z "$SSH_KEY_B64" ]; then
echo "Environment variable SSH_KEY_B64 is not set. Exiting."
exit 1
fi
echo "$SSH_KEY_B64" | base64 -d >> /home/devuser/.ssh/authorized_keys
chmod 600 /home/devuser/.ssh/authorized_keys
export MONGO_DB_DATA=$PYTHAGORA_DATA_DIR/mongodata
mkdir -p $MONGO_DB_DATA
mongod --dbpath "$MONGO_DB_DATA" --bind_ip_all >> $MONGO_DB_DATA/mongo_logs.txt 2>&1 &
export DB_DIR=$PYTHAGORA_DATA_DIR/database
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..."
su - devuser -c "git config --global user.email 'devuser@pythagora.ai'"
su - devuser -c "git config --global user.name 'pythagora'"
/usr/sbin/sshd -D

View File

@@ -0,0 +1,34 @@
#!/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/pythagora-core/workspace/.vscode && printf '{\n "gptPilot.isRemoteWs": true,\n "gptPilot.useRemoteWs": false\n}' > /pythagora/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
fi
done