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

Fix Heroku Caching #2898

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "LIMIT_BLOG_PAGES=1 SKIP_DOCS=true gatsby develop",
"build": "gatsby build",
"start": "node ./src/server/index.js",
"heroku-postbuild": "./scripts/deploy-with-s3.js",
"heroku-postbuild": "./scripts/heroku-deploy.sh",
"test": "jest",
"format-staged": "pretty-quick --staged --no-restage --bail",
"format-check": "prettier --check '**/*.{js,jsx,md,tsx,ts,json}'",
Expand Down
36 changes: 21 additions & 15 deletions scripts/deploy-with-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const deployOptions = DEPLOY_OPTIONS
: {
download: true,
build: true,
retry: true,
upload: true,
clean: true,
clearCloudflareCache: true
Expand Down Expand Up @@ -69,9 +70,8 @@ const {
cleanEntry
} = require('./s3-utils')
const { move } = require('fs-extra')
const { downloadAllFromS3, uploadAllToS3, cleanAllLocal } = withEntries(
cacheDirs
)
const { downloadAllFromS3, uploadAllToS3, cleanAllLocal } =
withEntries(cacheDirs)

function run(command) {
execSync(command, {
Expand Down Expand Up @@ -100,18 +100,24 @@ async function main() {
try {
run('yarn build')
} catch (buildError) {
// Sometimes gatsby build fails because of bad cache.
// Clear it and try again.

console.error('------------------------\n\n')
console.error('The first Gatsby build attempt failed!\n')
console.error(buildError)
console.error('\nRetrying with a cleared cache:\n')

// Clear only .cache so we re-use images
await cleanEntry(cacheDirs[1])

run('yarn build')
if (deployOptions.retry) {
// Sometimes gatsby build fails because of bad cache.
// Clear it and try again.

console.error('------------------------\n\n')
console.error('The first Gatsby build attempt failed!\n')
console.error(buildError)
console.error('\nRetrying with a cleared cache:\n')

// Clear only .cache so we re-use images
await cleanEntry(cacheDirs[1])

run('yarn build')
} else {
throw new Error(
'The first Gatsby build attempt failed, and DEPLOY_OPTIONS does not include "retry"'
)
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions scripts/heroku-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
NEWPWD="/tmp/gatsby-build"
mv $OLDPWD $NEWPWD
ln -s $NEWPWD $OLDPWD
cd $NEWPWD
./scripts/deploy-with-s3.js