Skip to content

Commit

Permalink
fix: server cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmerrell committed Sep 28, 2023
1 parent 7c81b62 commit 3f52568
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
16 changes: 12 additions & 4 deletions official-templates/vscode-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04
# Set working directory
WORKDIR /

ENV DEBIAN_FRONTEND=noninteractive \
VSCODE_SERVE_MODE=remote
ENV DEBIAN_FRONTEND=noninteractive

# VS Code Server Environment Variables
ENV VSCODE_SERVE_MODE=remote


# Install System Packages
Expand All @@ -16,6 +18,7 @@ RUN apt-get update -y && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
git \
nano \
nginx \
tzdata \
expect \
Expand All @@ -37,8 +40,13 @@ RUN ln -s /usr/bin/python3.10 /usr/bin/python && \
RUN pip install --upgrade pip && pip install jupyterlab

# Install vscode-server
RUN wget -q -O- https://aka.ms/install-vscode-server/setup.sh | sh && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY src/vscode-server-setup.sh /tmp/vscode-server-setup.sh
RUN chmod +x /tmp/vscode-server-setup.sh && \
/tmp/vscode-server-setup.sh && \
rm /tmp/vscode-server-setup.sh

# RUN wget -q -O- https://aka.ms/install-vscode-server/setup.sh | sh && \
# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# copy scripts
COPY src/* /usr/local/bin/
Expand Down
15 changes: 13 additions & 2 deletions official-templates/vscode-server/src/serve-remote
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#!/usr/bin/expect -f
#!/usr/bin/env expect

# Set infinite timeout for expect
set timeout -1

# Check for presence of the RUNPOD_POD_ID environment variable
if { ![info exists env(RUNPOD_POD_ID)] } {
puts "Error: RUNPOD_POD_ID environment variable is not set."
exit 1
}
set runpod_pod_id $env(RUNPOD_POD_ID)

# Spawn the code-server process
spawn code-server \
--accept-server-license-terms \
--disable-telemetry \
serve

# Automate responses to code-server prompts
expect {
"What would you like to call this machine?" {
send -- "$runpod_pod_id\r"
exp_continue
}
eof
eof {
puts "Finished interacting with code-server."
}
}
75 changes: 75 additions & 0 deletions official-templates/vscode-server/src/vscode-server-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

INSTALL_LOCATION=/usr/local/bin/code-server
INSTALL_ARCH=x86_64
INSTALL_TARGET=unknown-linux-gnu

MIN_GLIBC_VERSION=2.18
LDD=$(ldd --version 2>&1)

if [ "$(uname)" = "Darwin" ]; then
INSTALL_TARGET=apple-darwin-signed
elif echo "$LDD" | grep -q 'musl'; then
INSTALL_TARGET=unknown-linux-musl
echo "is musl"
else
GLIBC_VERSION=$(echo "$LDD" | grep -o 'GLIBC [0-9]\+\.[0-9]\+' | head -n 1 | tr -d 'GLIBC ')
echo "glibc version is $GLIBC_VERSION"
IS_MIN_GLIBC_VERSION=$(awk 'BEGIN{ print "'$MIN_GLIBC_VERSION'"<="'$GLIBC_VERSION'" }')
echo "is min? $IS_MIN_GLIBC_VERSION"
if [ "$IS_MIN_GLIBC_VERSION" = "0" ]; then
INSTALL_TARGET=unknown-linux-musl
fi
fi

ARCH=$(uname -m)
if [ $ARCH = "aarch64" ] || [ $ARCH = "arm64" ]; then
INSTALL_ARCH=aarch64
fi

INSTALL_URL=https://aka.ms/vscode-server-launcher/$INSTALL_ARCH-$INSTALL_TARGET
echo "Installing from $INSTALL_URL"


command_exists() {
command -v "$1" > /dev/null 2>&1
}

download_into() {
if command_exists curl; then
curl -sSL "$1" -o "$2"
elif command_exists wget; then
wget -qO "$2" "$1"
else
echo "Please install curl or wget"
exit 1
fi
}

if command_exists curl; then
DOWNLOAD_WITH=curl
elif command_exists wget; then
DOWNLOAD_WITH=wget
else
echo "Please install curl or wget"
exit 1
fi

if command_exists sudo;
then
if [ "$DOWNLOAD_WITH" = curl ]; then
sudo curl -sSL "$INSTALL_URL" -o "$INSTALL_LOCATION"
else
sudo wget -qO "$INSTALL_LOCATION" "$INSTALL_URL"
fi

sudo chown $USER $INSTALL_LOCATION
else
if [ "$DOWNLOAD_WITH" = curl ]; then
curl -sSL "$INSTALL_URL" -o "$INSTALL_LOCATION"
else
wget -qO "$INSTALL_LOCATION" "$INSTALL_URL"
fi
fi

chmod +x $INSTALL_LOCATION

0 comments on commit 3f52568

Please sign in to comment.