Skip to content

Commit 5023160

Browse files
committed
Reuse virtual env of prev deployment
1 parent c9a004d commit 5023160

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/BuildScriptGenerator/Python/PythonBashBuildSnippet.sh.tpl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,46 @@ fi
6565
# Execute the resolved CreateVenvCommand
6666
echo "Executing: $CreateVenvCommand"
6767
$CreateVenvCommand
68+
69+
CACHE_EXTRACTION_DIR=""/tmp/oryx_cache_$(date +%s)""
70+
OLD_VENV_RESTORED=false
71+
72+
if [ -f "/home/site/wwwroot/output.tar.gz" ]; then
73+
echo "Found previous deployment, checking for virtual environment reuse..."
74+
75+
# Create temporary extraction directory
76+
mkdir -p "$CACHE_EXTRACTION_DIR"
77+
78+
# Extract previous deployment to temp location
79+
echo "Extracting previous deployment..."
80+
tar -xzf /home/site/wwwroot/output.tar.gz -C "$CACHE_EXTRACTION_DIR"
81+
82+
# Compare requirements.txt files
83+
OLD_REQUIREMENTS="$CACHE_EXTRACTION_DIR/$REQUIREMENTS_TXT_FILE"
84+
CURRENT_REQUIREMENTS="$REQUIREMENTS_TXT_FILE"
85+
86+
if [ -f "$OLD_REQUIREMENTS" ] && [ -f "$CURRENT_REQUIREMENTS" ]; then
87+
if cmp -s "$OLD_REQUIREMENTS" "$CURRENT_REQUIREMENTS"; then
88+
echo "Requirements.txt unchanged - reusing existing virtual environment"
89+
90+
# Check if old virtual environment exists
91+
if [ -d "$CACHE_EXTRACTION_DIR/$VIRTUALENVIRONMENTNAME" ]; then
92+
echo "Copying cached virtual environment..."
93+
# Remove current empty venv and replace with old one
94+
cp -r "$CACHE_EXTRACTION_DIR/$VIRTUALENVIRONMENTNAME" ./
95+
96+
# Reactivate the copied environment
97+
source $VIRTUALENVIRONMENTNAME/bin/activate
98+
99+
OLD_VENV_RESTORED=true
100+
echo "Successfully restored virtual environment from cache"
101+
echo "Skipping pip install - using cached packages"
102+
fi
103+
else
104+
echo "Requirements.txt changed - performing incremental update"
105+
fi
106+
fi
107+
fi
68108

69109
echo Activating virtual environment...
70110
printf %s " , $ActivateVenvCommand" >> "$COMMAND_MANIFEST_FILE"

0 commit comments

Comments
 (0)