Skip to content
67 changes: 33 additions & 34 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
{
"name": "Workbench template",
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm",
"hostRequirements": {
"storage": "32gb",
"memory": "8gb",
"cpus": 4
},
// Runs automatically after Prebuild Template environment is created.
"onCreateCommand": ".devcontainer/onCreate.sh",
// Runs automatically every time the dev container has been (re-)started
"postStartCommand": {
"app": "USE_DESIGNER=true USE_SPARK_AGENT=true npm run dev",
"ports": "gh cs ports visibility 5000:public -c $CODESPACE_NAME",
"spark-proxy": "proxy.js",
"server": "spark-server",
"spark-agent": "spark-agent",
"spark-designer": "spark-designer",
"spark-file-syncer": "spark-file-syncer 13000 >> /tmp/.spark-file-syncer.log 2>&1"
},
"forwardPorts": [4000, 5000, 9000, 13000],
"features": {
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},
"customizations": {
"codespaces": {
"repositories": {
"github/gh-runtime-cli": {
"permissions": {
"contents": "read",
"packages": "read"
}
"name": "Workbench template",
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm",
"hostRequirements": {
"storage": "32gb",
"memory": "8gb",
"cpus": 4
},
// Runs automatically after Prebuild Template environment is created.
"onCreateCommand": ".devcontainer/onCreate.sh",
// Runs automatically every time the dev container has been (re-)started
"postStartCommand": {
"ports": "gh cs ports visibility 5000:public -c $CODESPACE_NAME",
"tools": ".devcontainer/postStartCommand.sh"
Comment thread
cmbrose marked this conversation as resolved.
Outdated
},
"forwardPorts": [
4000,
5000,
9000,
13000
],
"features": {
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},
"customizations": {
Comment thread
cmbrose marked this conversation as resolved.
Outdated
"codespaces": {
"repositories": {
"github/gh-runtime-cli": {
"permissions": {
"contents": "read",
"packages": "read"
}
}
}
}
}
}
41 changes: 0 additions & 41 deletions .devcontainer/onCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,6 @@ fi
echo "Adding an alias for the GitHub CLI Runtime extension"
gh alias set runtime runtime-cli

echo "Downloading the latest release of workbench-template from GitHub"

GITHUB_PAT="$RELEASE_PAT"
REPO="github/workbench-template"

# Fetch the latest release information
LATEST_RELEASE=$(curl -s -H "Authorization: token $GITHUB_PAT" https://api.github.com/repos/$REPO/releases/latest)

# Extract the first browser_download_url from the assets
DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | jq -r '.assets[0].url')
echo "Download URL: $DOWNLOAD_URL"


# Fetch the latest release information
curl -L -o dist.zip -H "Authorization: token $GITHUB_PAT" -H "Accept: application/octet-stream" "$DOWNLOAD_URL"

unzip -o dist.zip
rm dist.zip

sudo mv ./spark-sdk-dist/server.js /usr/local/bin/spark-server
sudo mv ./spark-sdk-dist/designer.js /usr/local/bin/spark-designer
sudo mv ./spark-sdk-dist/upload-to-remote.sh /usr/local/bin/upload-to-remote.sh
sudo mv ./spark-sdk-dist/file-syncer.js /usr/local/bin/spark-file-syncer
sudo mv ./spark-sdk-dist/spark-agent.js /usr/local/bin/spark-agent
sudo cp ./spark-sdk-dist/proxy.js /workspaces/proxy.js
sudo mv ./spark-sdk-dist/proxy.js /usr/local/bin/proxy.js

tar -xzf ./spark-sdk-dist/spark-tools.tgz

mkdir -p /workspaces/spark-tools
sudo mv ./package/* /workspaces/spark-tools
sudo rmdir ./package
rm -rf ./spark-sdk-dist

cd /workspaces/spark-tools
npm i
cd /workspaces/spark-template
npm i -f /workspaces/spark-tools



echo "Installing azcopy"

sudo wget -O /usr/local/bin/azcopytar https://aka.ms/downloadazcopy-v10-linux
Expand Down
17 changes: 17 additions & 0 deletions .devcontainer/postStartCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
"$SCRIPT_DIR/refreshTools.sh"

USE_DESIGNER=true USE_SPARK_AGENT=true npm run dev &
proxy.js &
Comment thread
cmbrose marked this conversation as resolved.
spark-server &
spark-agent &
spark-designer &
spark-file-syncer 13000 >> /tmp/.spark-file-syncer.log 2>&1 &
Comment thread
cmbrose marked this conversation as resolved.

echo "Spark tools started successfully"

wait
74 changes: 74 additions & 0 deletions .devcontainer/refreshTools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

set -e

echo "Upgrading the Runtime CLI extension"
gh extension upgrade runtime-cli

echo "Checking for updates to workbench-template from GitHub"

GITHUB_PAT="$RELEASE_PAT"
REPO="github/workbench-template"

MARKER_DIR="/var/lib/spark/.versions"
RELEASE_MARKER_FILE="$MARKER_DIR/release"
TOOLS_MARKER_FILE="$MARKER_DIR/tools"

sudo mkdir -p "$MARKER_DIR"

# Fetch the latest release information
LATEST_RELEASE=$(curl -s -H "Authorization: token $GITHUB_PAT" https://api.github.com/repos/$REPO/releases/latest)

# Extract the release ID to use as marker
RELEASE_ID=$(echo "$LATEST_RELEASE" | jq -r '.id')

# Check if marker file exists and has the same release ID
if [ -f "$RELEASE_MARKER_FILE" ] && [ "$(cat "$RELEASE_MARKER_FILE")" == "$RELEASE_ID" ]; then
echo "Already at the latest release. Skipping download."
exit 0
fi

echo "New version found. Downloading latest release."

# Extract the first browser_download_url from the assets
DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | jq -r '.assets[0].url')
Comment thread
cmbrose marked this conversation as resolved.
Outdated
echo "Download URL: $DOWNLOAD_URL"

# Fetch the latest release information
curl -L -o dist.zip -H "Authorization: token $GITHUB_PAT" -H "Accept: application/octet-stream" "$DOWNLOAD_URL"

unzip -o dist.zip
rm dist.zip

sudo mv ./spark-sdk-dist/server.js /usr/local/bin/spark-server
sudo mv ./spark-sdk-dist/designer.js /usr/local/bin/spark-designer
sudo mv ./spark-sdk-dist/upload-to-remote.sh /usr/local/bin/upload-to-remote.sh
sudo mv ./spark-sdk-dist/file-syncer.js /usr/local/bin/spark-file-syncer
sudo mv ./spark-sdk-dist/spark-agent.js /usr/local/bin/spark-agent
sudo cp ./spark-sdk-dist/proxy.js /workspaces/proxy.js
sudo mv ./spark-sdk-dist/proxy.js /usr/local/bin/proxy.js

if [ -f "$TOOLS_MARKER_FILE" ] && [ "$(cat "$TOOLS_MARKER_FILE")" == "$(cat ./spark-sdk-dist/spark-tools-version)" ]; then
echo "Already at the latest tools version. Skipping extraction."
else
tar -xzf ./spark-sdk-dist/spark-tools.tgz

rm -rf /workspaces/spark-tools
mkdir -p /workspaces/spark-tools
sudo mv ./package/* /workspaces/spark-tools
sudo rmdir ./package

cd /workspaces/spark-tools
npm i
cd /workspaces/spark-template
npm i -f /workspaces/spark-tools

sudo cp ./spark-sdk-dist/spark-tools-version "$TOOLS_MARKER_FILE"
fi

rm -rf ./spark-sdk-dist

# Update marker file with latest release ID
echo "$RELEASE_ID" | sudo tee "$RELEASE_MARKER_FILE" > /dev/null

echo "Tools installed successfully."