diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 226b5e3..75f7591 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -24,6 +24,12 @@ "features": { "ghcr.io/devcontainers/features/sshd:1": { "version": "latest" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "latest" + }, + "ghcr.io/devcontainers/features/azure-cli:1": { + "version": "latest" } } } diff --git a/.devcontainer/onCreate.sh b/.devcontainer/onCreate.sh index 1cb26c6..e45485f 100755 --- a/.devcontainer/onCreate.sh +++ b/.devcontainer/onCreate.sh @@ -2,30 +2,20 @@ set -e -echo "Installing the GitHub CLI" -(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \ - && sudo mkdir -p -m 755 /etc/apt/keyrings \ - && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \ - && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ - && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ - && sudo apt update \ - && sudo apt install gh inotify-tools -y +echo "Setting up node user home directory and permissions" +sudo mkdir -p /home/node/.config/vscode-dev-containers +sudo chown -R node:node /home/node +sudo chmod 755 /home/node +sudo chmod -R 755 /home/node/.config -echo "Installing azcopy" - -sudo wget -O /usr/local/bin/azcopytar https://aka.ms/downloadazcopy-v10-linux -sudo tar -xvf /usr/local/bin/azcopytar -C /usr/local/bin/ -sudo rm /usr/local/bin/azcopytar -azcopy_dir=$(find /usr/local/bin/ -type d -name "azcopy*" | head -n 1) -sudo mv "$azcopy_dir/azcopy" /usr/local/bin/azcopy -sudo rm -rf "$azcopy_dir" +echo "Installing inotify-tools" +sudo apt update && sudo apt install -y inotify-tools SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" "$SCRIPT_DIR/refreshTools.sh" -echo "Pre-starting the server and generating the optimized assets" -npm run optimize --override +echo "Installing Node.js dependencies" +npm install echo "Installing supervisor" sudo apt-get update && sudo apt-get install -y supervisor \ No newline at end of file diff --git a/.devcontainer/refreshTools.sh b/.devcontainer/refreshTools.sh index aaaa428..c1e63b6 100755 --- a/.devcontainer/refreshTools.sh +++ b/.devcontainer/refreshTools.sh @@ -4,6 +4,12 @@ set -e echo "Checking for updates to workbench-template from GitHub" +# Ensure jq is installed for JSON parsing +if ! command -v jq &> /dev/null; then + echo "Installing jq for JSON parsing..." + sudo apt-get update && sudo apt-get install -y jq +fi + WORKSPACE_DIR="/workspaces/spark-template" MARKER_DIR="/var/lib/spark/.versions" @@ -12,11 +18,28 @@ TOOLS_MARKER_FILE="$MARKER_DIR/tools" sudo mkdir -p "$MARKER_DIR" +# Check if TEMPLATE_PAT is set +if [ -z "$TEMPLATE_PAT" ]; then + echo "TEMPLATE_PAT environment variable is not set. Skipping tools update." + exit 0 +fi + # Fetch the latest release information LATEST_RELEASE=$(curl -s -H "Authorization: token $TEMPLATE_PAT" https://api.github.com/repos/github/spark-template/releases/latest) +# Check if the API call succeeded +if [ $? -ne 0 ] || [ -z "$LATEST_RELEASE" ]; then + echo "Failed to fetch release information from GitHub. Skipping tools update." + exit 0 +fi + # Check if marker file exists and has the same release ID RELEASE_ID=$(echo "$LATEST_RELEASE" | jq -r '.id') +if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then + echo "Invalid release data received from GitHub. Skipping tools update." + exit 0 +fi + if [ -f "$RELEASE_MARKER_FILE" ] && [ "$(cat "$RELEASE_MARKER_FILE")" == "$RELEASE_ID" ]; then echo "Already at the latest release. Skipping download." exit 0 @@ -28,6 +51,13 @@ TEMP_DIR=$(mktemp -d) cd $TEMP_DIR DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | jq -r '.assets[0].url') +if [ "$DOWNLOAD_URL" == "null" ] || [ -z "$DOWNLOAD_URL" ]; then + echo "No download URL found in release data. Skipping tools update." + cd - >/dev/null + rm -rf $TEMP_DIR + exit 0 +fi + curl -L -o dist.zip -H "Authorization: token $TEMPLATE_PAT" -H "Accept: application/octet-stream" "$DOWNLOAD_URL" unzip -o dist.zip diff --git a/package.json b/package.json index ff5966a..bc80ee4 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "lint": "eslint .", "test": "vitest", "test:run": "vitest run", - "optimize": "vite optimize", "preview": "vite preview", "build:pages": "bash ./build-for-gh-pages.sh", "predeploy": "npm run build:pages",