From 4a059408a4cc7e092956f7619ad83420a5f6fd48 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 29 May 2025 08:14:24 +0000 Subject: [PATCH 1/2] feat: optimize devcontainer build performance - Add build cacheFrom configuration for better layer caching - Enable postCreateCommand instead of postStartCommand for setup - Optimize npm install in common feature with caching and offline preference - Improve error handling and path resolution in install script - Add cache configuration file for future BuildKit optimizations Co-authored-by: keito4 --- .devcontainer/.devcontainer-cache | 8 ++++ .devcontainer/devcontainer.json | 5 ++- .devcontainer/features/common/install.sh | 52 ++++++++++++++++++------ 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 .devcontainer/.devcontainer-cache diff --git a/.devcontainer/.devcontainer-cache b/.devcontainer/.devcontainer-cache new file mode 100644 index 00000000..18d290c2 --- /dev/null +++ b/.devcontainer/.devcontainer-cache @@ -0,0 +1,8 @@ +# devcontainer build cache configuration +# This file is used to improve build performance by caching layers + +# Enable Docker BuildKit for better caching +DOCKER_BUILDKIT=1 + +# Set cache mount points for common directories +CACHE_DIRS="/tmp/.npm-cache:/home/linuxbrew/.linuxbrew/var/cache" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7ca61526..d66b6414 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,6 +15,9 @@ "ghcr.io/devcontainers-extra/features/zsh-plugins:0": {}, "ghcr.io/devcontainers-extra/features/kubectl-asdf:2": {} }, + "build": { + "cacheFrom": "mcr.microsoft.com/devcontainers/base:ubuntu" + }, "mounts": [ { "source": "${localEnv:HOME}/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock", @@ -25,7 +28,7 @@ "remoteEnv": { "SSH_AUTH_SOCK": "/home/vscode/.1password/agent.sock" }, - // "postStartCommand": "zsh -c 'eval \"$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)\" && source ~/.zshrc'", + "postCreateCommand": "zsh -c 'eval \"$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)\" && source ~/.zshrc'", "remoteUser": "vscode", "customizations": { "vscode": { diff --git a/.devcontainer/features/common/install.sh b/.devcontainer/features/common/install.sh index dd1b5689..ec28662d 100644 --- a/.devcontainer/features/common/install.sh +++ b/.devcontainer/features/common/install.sh @@ -10,34 +10,60 @@ echo "Current working directory: $(pwd)" echo "User: $(whoami)" echo "Home directory: $HOME" +# Check if npm packages are already installed +if ! command -v npm >/dev/null 2>&1; then + echo "npm not found, skipping npm package installation." + exit 0 +fi + +# Use cache directory for npm +NPM_CACHE_DIR="/tmp/.npm-cache" +mkdir -p "$NPM_CACHE_DIR" +npm config set cache "$NPM_CACHE_DIR" --global + +# Common expected paths for global.json GLOBAL_JSON_PATHS=( - "npm/global.json" - "/workspace/npm/global.json" "/workspaces/*/npm/global.json" + "/workspace/npm/global.json" "$HOME/npm/global.json" - "/tmp/build/npm/global.json" + "npm/global.json" ) GLOBAL_JSON_FILE="" -for path in ${GLOBAL_JSON_PATHS[@]}; do - for file in $path; do - if [ -f "$file" ]; then - GLOBAL_JSON_FILE="$file" +for path in "${GLOBAL_JSON_PATHS[@]}"; do + # Use find to avoid shell expansion issues with wildcards + if [[ "$path" == *"*"* ]]; then + found_file=$(find $(dirname "$path") -name "global.json" -type f 2>/dev/null | head -1) + if [ -n "$found_file" ] && [ -f "$found_file" ]; then + GLOBAL_JSON_FILE="$found_file" echo "Found npm/global.json at: $GLOBAL_JSON_FILE" - break 2 + break fi - done + elif [ -f "$path" ]; then + GLOBAL_JSON_FILE="$path" + echo "Found npm/global.json at: $GLOBAL_JSON_FILE" + break + fi done if [ -z "$GLOBAL_JSON_FILE" ]; then echo "Warning: npm/global.json not found in any of the expected locations:" - for path in ${GLOBAL_JSON_PATHS[@]}; do - echo " - $path" - done + printf ' - %s\n' "${GLOBAL_JSON_PATHS[@]}" echo "Skipping npm package installation." exit 0 fi -npm install -g $(jq -r '.dependencies | keys[]' "$GLOBAL_JSON_FILE") +# Install packages with better error handling +if jq -e '.dependencies' "$GLOBAL_JSON_FILE" >/dev/null 2>&1; then + packages=$(jq -r '.dependencies | keys[]' "$GLOBAL_JSON_FILE" 2>/dev/null || echo "") + if [ -n "$packages" ]; then + echo "Installing npm packages: $packages" + npm install -g $packages --prefer-offline --no-audit --no-fund + else + echo "No packages found in global.json dependencies" + fi +else + echo "No dependencies section found in global.json" +fi echo "Feature installation completed. Configuration will be applied by postCreateCommand." From 3f84d5cf93b06af31c806883c9b2ba36ccd241ad Mon Sep 17 00:00:00 2001 From: keito4 Date: Thu, 29 May 2025 17:42:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?devcontainer=E3=81=AE=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=97=E3=80=81=E3=82=AD=E3=83=A3?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=80=82install.sh=E5=86=85=E3=81=AEnpm=E3=83=91?= =?UTF-8?q?=E3=83=83=E3=82=B1=E3=83=BC=E3=82=B8=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=83=BC=E3=83=AB=E5=87=A6=E7=90=86=E3=82=92=E6=94=B9?= =?UTF-8?q?=E5=96=84=E3=81=97=E3=80=81=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=8F?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E3=82=92=E5=BC=B7?= =?UTF-8?q?=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/.devcontainer-cache | 2 +- .devcontainer/devcontainer.json | 3 --- .devcontainer/features/common/install.sh | 23 +++++++---------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/.devcontainer/.devcontainer-cache b/.devcontainer/.devcontainer-cache index 18d290c2..5d75bacc 100644 --- a/.devcontainer/.devcontainer-cache +++ b/.devcontainer/.devcontainer-cache @@ -5,4 +5,4 @@ DOCKER_BUILDKIT=1 # Set cache mount points for common directories -CACHE_DIRS="/tmp/.npm-cache:/home/linuxbrew/.linuxbrew/var/cache" \ No newline at end of file +CACHE_DIRS="/tmp/.npm-cache:/home/linuxbrew/.linuxbrew/var/cache" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d66b6414..366ea560 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,9 +15,6 @@ "ghcr.io/devcontainers-extra/features/zsh-plugins:0": {}, "ghcr.io/devcontainers-extra/features/kubectl-asdf:2": {} }, - "build": { - "cacheFrom": "mcr.microsoft.com/devcontainers/base:ubuntu" - }, "mounts": [ { "source": "${localEnv:HOME}/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock", diff --git a/.devcontainer/features/common/install.sh b/.devcontainer/features/common/install.sh index ec28662d..52500715 100644 --- a/.devcontainer/features/common/install.sh +++ b/.devcontainer/features/common/install.sh @@ -10,18 +10,15 @@ echo "Current working directory: $(pwd)" echo "User: $(whoami)" echo "Home directory: $HOME" -# Check if npm packages are already installed if ! command -v npm >/dev/null 2>&1; then echo "npm not found, skipping npm package installation." exit 0 fi -# Use cache directory for npm NPM_CACHE_DIR="/tmp/.npm-cache" mkdir -p "$NPM_CACHE_DIR" npm config set cache "$NPM_CACHE_DIR" --global -# Common expected paths for global.json GLOBAL_JSON_PATHS=( "/workspaces/*/npm/global.json" "/workspace/npm/global.json" @@ -31,10 +28,9 @@ GLOBAL_JSON_PATHS=( GLOBAL_JSON_FILE="" for path in "${GLOBAL_JSON_PATHS[@]}"; do - # Use find to avoid shell expansion issues with wildcards if [[ "$path" == *"*"* ]]; then - found_file=$(find $(dirname "$path") -name "global.json" -type f 2>/dev/null | head -1) - if [ -n "$found_file" ] && [ -f "$found_file" ]; then + found_file=$(find / -path "$path" -type f 2>/dev/null | head -n 1) + if [ -n "$found_file" ]; then GLOBAL_JSON_FILE="$found_file" echo "Found npm/global.json at: $GLOBAL_JSON_FILE" break @@ -53,17 +49,12 @@ if [ -z "$GLOBAL_JSON_FILE" ]; then exit 0 fi -# Install packages with better error handling -if jq -e '.dependencies' "$GLOBAL_JSON_FILE" >/dev/null 2>&1; then - packages=$(jq -r '.dependencies | keys[]' "$GLOBAL_JSON_FILE" 2>/dev/null || echo "") - if [ -n "$packages" ]; then - echo "Installing npm packages: $packages" - npm install -g $packages --prefer-offline --no-audit --no-fund - else - echo "No packages found in global.json dependencies" - fi +packages=$(jq -r '.dependencies | keys[]' "$GLOBAL_JSON_FILE" 2>/dev/null || echo "") +if [ -n "$packages" ]; then + echo "Installing npm packages: $packages" + npm install -g $packages --prefer-offline --no-audit --no-fund else - echo "No dependencies section found in global.json" + echo "No packages found in global.json dependencies" fi echo "Feature installation completed. Configuration will be applied by postCreateCommand."