Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache stack #58

Merged
merged 7 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function indent() {
esac
}

# Store which STACK we are running on in the cache to bust the cache if it changes
if [ -f $CACHE_DIR/.apt/STACK ]; then
CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK")
else
CACHED_STACK=$STACK
fi

# Ensure we store the STACK in the cache for next time.
mkdir -p "$CACHE_DIR/.apt"
echo "$STACK" > "$CACHE_DIR/.apt/STACK"

APT_CACHE_DIR="$CACHE_DIR/apt/cache"
APT_STATE_DIR="$CACHE_DIR/apt/state"
APT_SOURCELIST_DIR="$CACHE_DIR/apt/sources" # place custom sources.list here
Expand All @@ -42,12 +53,12 @@ case "$APT_VERSION" in
*) APT_FORCE_YES="--allow-downgrades --allow-remove-essential --allow-change-held-packages";;
esac

if [ -f $APT_CACHE_DIR/Aptfile ] && cmp -s $BUILD_DIR/Aptfile $APT_CACHE_DIR/Aptfile ; then
# Old Aptfile is the same as new
if [ -f $APT_CACHE_DIR/Aptfile ] && cmp -s $BUILD_DIR/Aptfile $APT_CACHE_DIR/Aptfile && [[ $CACHED_STACK == $STACK ]] ; then
# Old Aptfile is the same as new and STACK has not changed
topic "Reusing cache"
else
# Aptfile changed or does not exist
topic "Detected Aptfile changes, flushing cache"
# Aptfile changed or does not exist or STACK changed
topic "Detected Aptfile or Stack changes, flushing cache"
rm -rf $APT_CACHE_DIR
mkdir -p "$APT_CACHE_DIR/archives/partial"
mkdir -p "$APT_STATE_DIR/lists/partial"
Expand Down
49 changes: 44 additions & 5 deletions test/compile_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
. ${BUILDPACK_TEST_RUNNER_HOME}/lib/test_utils.sh

testCompile() {
cat > ${BUILD_DIR}/Aptfile <<EOF
# Test comment
s3cmd
wget
EOF
loadFixture "Aptfile"

compile

Expand All @@ -18,3 +14,46 @@ EOF
assertCaptured "Fetching .debs for wget"
assertCaptured "Installing wget_"
}

testStackChange() {
loadFixture "Aptfile"

#Set the cached STACK value to a non-existent stack, so it is guaranteed to change.
mkdir -p "$CACHE_DIR/.apt/"
echo "cedar-10" > "$CACHE_DIR/.apt/STACK"

#Load the Aptfile into the cache, to exclusively test the stack changes
mkdir -p "$CACHE_DIR/apt/cache"
cp $BUILD_DIR/Aptfile "$CACHE_DIR/apt/cache"

compile

assertCapturedSuccess

assertCaptured "Detected Aptfile or Stack changes, flushing cache"
}

testStackNoChange() {
loadFixture "Aptfile"

#Load the Aptfile into the cache, to exclusively test the stack changes
mkdir -p "$CACHE_DIR/apt/cache"
cp $BUILD_DIR/Aptfile "$CACHE_DIR/apt/cache"

compile

assertCaptured "Reusing cache"
}

testStackCached() {
loadFixture "Aptfile"

compile
assertCapturedSuccess

assertTrue 'STACK not cached' "[ -e $CACHE_DIR/.apt/STACK ]"
}

loadFixture() {
cp -a $BUILDPACK_HOME/test/fixtures/$1/. ${BUILD_DIR}
}
3 changes: 3 additions & 0 deletions test/fixtures/Aptfile/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test comment
s3cmd
wget